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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sql is null优化_你不会还在用
- 下一篇: python 代理ip验证_Python