python关于word文档操作--docx模块

安装模块  pip install python-docx -i https://pypi.tuna.tsinghua.edu.cn/simple

相关学习链接  https://blog.csdn.net/u011331731/article/details/94230989

 

导入 :  

from docx import Document

新建word对象
f = Document()

添加标题,此为2级标题
f.add_heading(str(title_num)+str(data), 2)


添加完内容后,保存文档 例子:
f.save('C:\\Users\h\Desktop\制度文件(2020.10.16)\制度文件(2020.10.16)\标题.docx')
posted @ 2020-10-20 11:43  诗诗萌萌  阅读(136)  评论(0编辑  收藏  举报