我正在尝试在 Google App Engine 中使用 xlsxwriter,但我不断收到错误:“响应”对象没有属性“告诉”。我已经查看了以前的问题Using xlsxwriter in Google App Engine for Python & XlsxWriter object save as http response to create download in Django但我仍然收到此错误。我试图修改他们在文档中给出的示例https://github.com/jmcnamara/XlsxWriter/blob/master/examples/http_server_py2.py
我目前在 GAE 中使用 xlwt 没有任何问题。
output = StringIO.StringIO()
# Even though the final file will be in memory the module uses temp
# files during assembly for efficiency. To avoid this on servers that
# don't allow temp files, for example the Google APP Engine, set the
# 'in_memory' constructor option to True:
workbook = xlsxwriter.Workbook(self.response.out,{'in_memory': True})
worksheet = workbook.add_worksheet()
# Write some test data.
worksheet.write(0, 0, 'Hello, world!')
# Close the workbook before streaming the data.
workbook.close()
# Rewind the buffer.
output.seek(0)
# Construct a server response.
self.response.headers['Content-disposition'] = 'attachment; filename=test.xls'
self.response.headers['Content-Transfer-Encoding'] = 'Binary'
self.response.headers['Content-Type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'