简体   繁体   English

使用对话框使用openpyxl下载/上传Excel工作簿

[英]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. 我正在使用Django和Openpyxl创建一个可以使用应用程序中的数据编写Excel工作簿的应用程序,然后将其保存在本地。

When I used: 当我使用时:

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

The file was saved in my Django project's root folder. 该文件保存在我的Django项目的根文件夹中。

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: openpyxl提供了将文件保存到StringIO对象的功能:

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. 但是,对于较大的文件,最好将其保存到文件系统中的某个位置,然后由http服务器处理下载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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