问题描述
我正在将OpenPyXL构建到一个应用程序中,该应用程序需要一个包含excel文件内容的字符串,以便它可以通过文件流写入.
I'm building OpenPyXL into an application that expects a string containing the content of the excel file, for it to write via file stream.
从我对OpenPyXL源代码的调查来看,它似乎不支持这种输出.有没有人有修改openpyxl来支持它的经验?
From my investigation into the OpenPyXL source code, it doesn't look like it supports this kind of output. Does anyone have any experience with modifying openpyxl to support this?
或任何常规建议/解决方法?
Or any general advice/workarounds?
谢谢.
推荐答案
jcollado的答案实际上是有效的,但是openpyxl.writer.excel中还有一个名为"save_virtual_workbook"的函数(该文件尚未正式记录)将使用您的工作簿.并以字符串形式返回工作簿:
jcollado's answer is actually valid, but there is also a function (sadly not documented yet) called "save_virtual_workbook" in openpyxl.writer.excel that will take your workbook and return the workbook as a string:
from openpyxl.workbook import Workbook
from openpyxl.writer.excel import save_virtual_workbook
wb = Workbook()
print save_virtual_workbook(wb)
您要查找的是save_virtual_workbook()返回的字符串
What you're looking for is the string returned by save_virtual_workbook()
这篇关于通过文本和文件流保存openpyxl文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!