想要使用python 将数据存储在doc 、docx等 word文档中,首先需要安装一个模块
python-docx
安装指令如下:
pip install python-docx
测试使用如下:
>>> from docx import Document
>>> document=docx.document
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'docx' is not defined
>>> document=Document()
>>> document.add_heading('Head',0)
<docx.text.paragraph.Paragraph object at 0x00000000034A4A20>
>>> document.add_heading('Head,help',1)
<docx.text.paragraph.Paragraph object at 0x00000000034A49E8>
>>> document.add_paragraph('Helllo world!')
<docx.text.paragraph.Paragraph object at 0x00000000034A4A58>
>>> document.save('hello_world.doc')
然后就可以生成doc文档了
转载请注明原文地址: https://ju.6miu.com/read-674376.html