1
manzhiyong 2020-09-16 17:32:55 +08:00
from openpyxl import Workbook
.... .... wb = Workbook() ..... ...... response = HttpResponse(content_type='application/msexcel') response['Content-Disposition'] = 'attachment; filename=xxx.xls' wb.save(response) return response |
2
dwadewyp OP @manzhiyong 我就是这么做的。。。 通过 postman 返回的是乱码的字节流
|
3
dwadewyp OP @manzhiyong response = HttpResponse(content_type='application/ms-excel')
response['Content-Disposition'] = 'attachment; filename="ThePythonDjango.xls"' ws.save(response) return response |
4
bolide2005 2020-09-16 17:36:19 +08:00
content type 改成 application/x-xls 试试?
|
5
manzhiyong 2020-09-16 17:38:00 +08:00
https://baijiahao.baidu.com/s?id=1666379708328635331&wfr=spider&for=pc
你点的是文章里的 send and download 吗 |
6
dwadewyp OP @manzhiyong 感谢
|
7
sunmlight 2020-09-16 20:47:29 +08:00
有可能是文件名的原因, 可以 urlquote 转一下文件名
|
8
Erroad 2020-09-16 20:51:05 +08:00
.xls Microsoft Excel application/vnd.ms-excel
.xlsx Microsoft Excel (OpenXML) application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
9
renmu123 2020-09-16 20:52:30 +08:00 via Android
你用 requests 請求處理一下文件試試看
|
10
Erroad 2020-09-16 20:52:42 +08:00
这是用 google 搜到的 mdn 对 xls,slsx mime 类型的描述,但是怀疑也可能不是这个原因?
|
11
hushao 2020-09-17 08:46:36 +08:00 via iPhone
你用 postman 看二进制文件当然是乱码...
|
12
vegetableChick 2020-09-22 16:10:12 +08:00
postman 不是可以直接 post_and_save 么?
|
13
dwadewyp OP @vegetableChick 已解决
|