18_python_练习题——写入文件到word文档中
2017-04-14 14:56
351 查看
想要使用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文档了
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文档了
相关文章推荐
- 用Python读取Word文档并写入Excel(一)
- 用Python读取Word文档并写入Excel(二)
- 使用Python通过win32 COM实现Word文档的写入与保存方法
- 使用Python通过win32 COM实现Word文档的写入与保存
- java读取文件写入到word文档中
- python实现word 2007文档转换为pdf文件
- Python学习笔记(29)-Python创建并写入word文档
- 利用Python将word 2007的文档转为pdf文件
- 用VB将WORD文档(或其他的二进制数据)生成xml文件并互相转换
- python学习笔记(四)-文件的读取、写入和复制、剪切
- python学习随笔(1):读取与写入csv文件
- Java程序员从笨鸟到菜鸟之(一百零三)java操作office和pdf文件(一)java读取word,excel和pdf文档内容
- python文件写入excel
- python-18-如何将文件映射到内存?
- 把word文档写入Sqlserver
- Java创建写入word文档图片和文字
- 使用python调用zabbix接口截取监控图并生成Word文档
- python对xml的处理和文件的写入操作1
- python读取 .txt 文本内容以及将程序执行结果写入txt文件
- python+adb获取当前activity的名字,并写入到文件中