1.使用 python-docx 模块提取导航标题
说明文档 https://python-docx.readthedocs.io/en/latest/index.html
from docx import Document document = Document(‘123.docx‘) paragraphs = document.paragraphs document_1 = Document() li = [] se = set() for i in paragraphs: # #拿到段落格式样式 # print(repr(i.style.name)) # se.add(i.style.name) if i.style.name in {‘Heading 1‘,‘Heading 2‘,‘Heading 3‘,‘Heading4‘,‘Heading 5‘, ‘Caption‘}:# ‘附录F表‘ # li.append([i.style.name,i.text,i]) p1 = document_1.add_paragraph() p1.style = document_1.styles[i.style.name] p1.add_run(text=i.text) document_1.save(‘qwe.docx‘)
原文:https://www.cnblogs.com/Bluemomo/p/14463190.html