作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
XLRD 已安装并测试:
>>> import xlrd
>>> workbook = xlrd.open_workbook('Sample.xls')
当我通过如下 html 表单读取文件时,我能够访问所有值。
xls_file = request.params['xls_file']
print xls_file.filename, xls_file.type
我正在使用 Pylons 模块,请求来自:from pylons import request, tmpl_context as c
我的问题:
requst.params
读取的xls_file
是一个对象吗? xls_file
并使其与 xlrd 一起工作?更新:
xls_file
已上传到 Web 服务器,但 xlrd 库需要一个文件名而不是打开的文件对象,如何使上传的文件与 xlrd 一起使用? (感谢 Martijn Pieters,我无法清楚地提出问题。)
最佳答案
xlrd 确实支持直接提供数据而无需文件路径,只需使用 file_contents
参数即可:
xlrd.open_workbook(file_contents=fileobj.read())
来自documentation :
file_contents – A string or an
mmap.mmap
object or some other behave-alike object. Iffile_contents
is supplied,filename
will not be used, except (possibly) in messages.
关于python - 如何从 Python 中的流(不是磁盘支持的文件)中读取 Excel 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11955300/
我是一名优秀的程序员,十分优秀!