栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Django输出word文件(.doc),仅在内容中显示原始html

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Django输出word文件(.doc),仅在内容中显示原始html

除非您有某种方法将响应(这里是HTML假定的)转换为.doc文件,否则您将获得的只是一个包含扩展名为.doc的响应的文本文件。如果您愿意使用.docx文件,那么有个很棒的python库叫做python-
docx,
您应该研究一下它,它允许您使用lxml库生成格式正确的docx文件。

或者,使用模板,例如:

<html><head><meta HTTP-EQUIV=""Content-Type"" ConTENT=""text/html; charset=UTF-8""><meta name=ProgId content=Word.document><meta name=Generator content=""Microsoft Word 9""><meta name=Originator content=""Microsoft Word 9""><style>@page Section1 {size:595.45pt 841.7pt; margin:1.0in 1.25in 1.0in 1.25in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}div.Section1 {page:Section1;}@page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.25in 1.0in 1.25in 1.0in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}div.Section2 {page:Section2;}</style></head><body><div class=Section2>'Section1: Portrait, Section2: Landscape[your text here]</div></body></html>

根据此asp.net论坛帖子,当

application/msword
使用
UTF-8
charset作为mime类型返回时,这应该创建一个有效的.doc文件(因此,请确保字符串均为unipre)。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/646851.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号