seq*_*oia 5 django internet-explorer-8 xlwt
我正在尝试使用xlwt从我的django站点上的数据库内容创建MS-Excel文件.
我在stackoverflow上看到了几个解决方案,特别是这个链接:django excel xlwt
和这个django片段:http://djangosnippets.org/snippets/2233/
这些示例适用于Firefox,但不适用于Internet Explorer.屏幕上出现了一堆蜿蜒的垃圾,而不是被提示打开或保存文件.似乎IE认为响应是html.
这是我的视图功能:
def exportexcel(request):
from xlwt import Workbook
wb = Workbook()
ws = wb.add_sheet('Sheetname')
ws.write(0, 0, 'Firstname')
ws.write(0, 1, 'Surname')
ws.write(1, 0, 'Hans')
ws.write(1, 1, 'Muster')
fname = 'testfile.xls'
response = HttpResponse(mimetype="application/ms-excel")
response['Content-Disposition'] = 'attachment; filename=%s' % fname
wb.save(response)
return response
Run Code Online (Sandbox Code Playgroud)
我在IE 8中看到了这种行为.
有关为什么这在Internet Explorer中不起作用的任何建议?
谢谢.
您使用的 mimetypeapplication/ms-excel对文件无效.xls。
标准的是application/vnd.ms-excel
请参阅此处为 Excel 文档设置 MIME 类型以获取更多信息。
| 归档时间: |
|
| 查看次数: |
3250 次 |
| 最近记录: |