欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

python输出word内容_Django输出word文件(.doc),只在内容中显示原始html

发布时间:2025/3/19 python 46 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python输出word内容_Django输出word文件(.doc),只在内容中显示原始html 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

除非您有某种方法将您的响应(这里假设为HTML)转换为.doc文件,否则您将得到一个文本文件,其中包含扩展名为.doc的响应。如果您愿意使用.docx文件,那么有一个很棒的python库python-docx您应该看看,它允许您使用lxml库生成格式良好的docx文件。在

或者,使用模板,例如:

@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;}

'Section1: Portrait, Section2: Landscape

[your text here]

当使用UTF-8字符集作为mime类型application/msword返回时,according to this asp.net forum post应该是一个有效的.doc文件(因此请确保字符串都是unicode)。在

总结

以上是生活随笔为你收集整理的python输出word内容_Django输出word文件(.doc),只在内容中显示原始html的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。