Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving openpyxl file via text and filestream

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.

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?

Thanks.

like image 280
Nelson Shaw Avatar asked Dec 12 '11 03:12

Nelson Shaw


People also ask

Can openpyxl write XLS files?

Introduction. openpyxl is a Python library to read/write Excel 2010 xlsx/xlsm/xltx/xltm files.

Is openpyxl faster than pandas?

Step 3: Load with Openpyxl Still slow but a tiny drop faster than Pandas. Openpyxl Documentation: Memory use is fairly high in comparison with other libraries and applications and is approximately 50 times the original file size.

Is openpyxl maintained?

Further analysis of the maintenance status of openpyxl based on released PyPI versions cadence, the repository activity, and other data points determined that its maintenance is Healthy. We found that openpyxl demonstrates a positive version release cadence with at least one new version released in the past 12 months.


1 Answers

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) 

What you're looking for is the string returned by save_virtual_workbook()

like image 199
Eric Gazoni Avatar answered Sep 28 '22 10:09

Eric Gazoni