简体   繁体   中英

Download/Upload Excel workbook created with openpyxl using dialog box

I'm using Django and Openpyxl to create an app that can write an Excel workbook using data from the app and then save the file locally.

When I used:

wb = Workbook()
wb.save('test.xlsx')

The file was saved in my Django project's root folder.

How can I have the file download to the browser's download folder as opposed to saving directly in the root directory of the app on its server?

Thanks.

openpyxl provides a function to save a file to a StringIO object:

from openpyxl.writer.excel import save_virtual_workbook
stream = save_virtual_workbook(wb)

However, for larger files it might be preferable to save to somewhere in the file system and let the http server handle the download.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM