我在cStringIO变量中创建了一个Excel文件。
我要打开看看。但是要用xlrd函数xlrd.open_workbook(excel_file_name)打开excel文件,我需要使用它的文件名来调用它。但在这种情况下,没有文件名,因为它是一个包含cStrinIO文件表示的变量。
如何将cStringIO变量转换为我可以打开的实际excel文件?
谢谢!
发布于 2014-04-16 12:11:15
看起来工作簿()也接受file_contents参数,所以可能如下所示?
xlrd.open_workbook(file_contents=cstringio_var.getvalue())发布于 2014-04-16 11:28:04
您可以使用tempfile.NamedTemporaryFile。
示例(未测试):
with tempfile.NamedTemporaryFile() as f:
f.write(your_cStringIO_variable.read())
f.flush()
something = xlrd.open_workbook(f.name)https://stackoverflow.com/questions/23107966
复制相似问题