I am writing a set of records in excel but I am not supposed to create a physical file. How do I write the records in excel in memory? If I do write it, how do I see the output of the records? I have tried:
import xlsxwriter
import io
filename= io.BytesIO()
workbook=xlsxwriter.Workbook(filename,{'in_memory': True})
worksheet=workbook.add_worksheet('sheet1')
worksheet.write(1,1,'Testing')
print(workbook.get_worksheet_by_name('sheet1'))
workbook.close()
From the XlsxWriter docs:
It is possible to write files to in-memory strings using BytesIO as follows:
from io import BytesIO
output = BytesIO()
workbook = xlsxwriter.Workbook(output)
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'Hello')
workbook.close()
xlsx_data = output.getvalue()
To avoid the use of any temporary files and keep the entire file in-memory use the in_memory constructor option shown above.
See also Example: Simple HTTP Server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With