我使用的是带有python2.7的googleappengine。需要在内存中生成xls文件并发送给用户下载。在
我在网上找到了很多话题,但都帮不了我。 我尝试过使用的相关主题:1)this is with Blobs, I tried at first,2)without Blob,3)with force-download MIME type,我也尝试过使用googlecloudstorage(找不到指向主题的链接)。在
这是我的代码:
import StringIO
class ExcelHandler(BaseHandler):
def post(self):
"""Save members to excel document and send to user"""
sheet = pyexcel.Sheet([[1, 2], [3, 4]])
filesheet = StringIO.StringIO()
sheet.save_to_memory('xls', filesheet)
filesheet.close()
self.response.write(sheet)
self.response.headers['Content-Type'] = 'application/force-download'
self.response.headers['Content-Transfer-Encoding'] = 'utf-8'
self.response.headers['Content-Disposition'] = 'attachment; filename=test.xlsx'
问题在于发送响应(而不是创建文件)。我尝试了不同的“内容类型”: '应用程序/越南盾-excel', “应用程序/下载”, “应用程序/强制下载”, '应用程序/八位字节流', '应用程序/vnd.openxml格式- officedocument.spreadsheetml.sheet'
但我得到的最好的回应是:
无法从我的服务器下载数据。我想我应该在那里找到我的想法,但是我想我应该在那里找到一些东西。谢谢你的帮助!在
这也是我的要求:
^{pr2}$和调试器上的响应:
HTTP/1.1 200 OK
content-disposition: attachment; filename=test.xlsx
content-transfer-encoding: utf-8
cache-control: no-cache
content-type: application/force-download
Content-Length: 64
Server: Development/2.0
Date: Sun, 02 Oct 2016 15:36:20 GMT
编辑1:(请尝试voscausa回答)
试试这个:
相关问题 更多 >
编程相关推荐