我已经尝试了一段时间,使tablib与web2py的工作没有运气。代码按预期传递了一个.xls文件,但该文件已损坏且为空。你知道吗
import tablib
data = []
headers = ('first_name', 'last_name')
data = tablib.Dataset(*data, headers=headers)
data.append(('John', 'Adams'))
data.append(('George', 'Washington'))
response.headers['Content-Type']= 'application/vnd.ms-excel;charset=utf-8'
response.headers['Content-disposition']='attachment; filename=test.xls'
response.write(data.xls, escape=False)
有什么想法吗?? 谢谢!你知道吗
根据http://en.wikipedia.org/wiki/Process_state,
response.write
被记录为服务(我的重点)。
data.xls
是不是文本它是二进制的东西!要验证这确实是问题的原因,请尝试改用data.csv
,并且应该有效,因为它是文本。你知道吗我相信您需要使用
response.stream
来发送“二进制内容”作为您的响应(或作为附件)。你知道吗相关问题 更多 >
编程相关推荐