from docx import Document
from docx.enum.style import WD_STYLE_TYPE
from docx.shared import Pt
def main(filename):
try:
src_doc = Document(filename)
tgt_doc = Document()
styles = src_doc.styles
paragraph_styles = [ s for s in styles if s.type == WD_STYLE_TYPE.PARAGRAPH ]
# print(paragraph_styles)
styles = tgt_doc.styles['Normal']
font = styles.font
font.name = 'Times'
font.size = Pt(11)
for src_paragraph in src_doc.paragraphs:
tgt_paragraph = tgt_doc.add_paragraph()
for src_run in src_paragraph.runs:
print('Run: ', src_run.text)
tgt_run = tgt_paragraph.add_run(src_run.text)
if src_run.bold:
tgt_run.bold = True
if src_run.italic:
tgt_run.italic = True
if src_run.underline:
tgt_run.underline = True
tgt_doc.save('../Output/the_target.docx')
except IOError:
print('There was an error opening the file')
if __name__ == '__main__':
main("../Input/Current_File.docx")应该是这样的:
本程序的目的是确保所有反馈都被记录下来,记录在案,并根据21 CFR 820和ISO 13485接收、评估和审查任何由此产生的投诉。
2.0范围本程序适用于兰花收到的所有反馈。投诉是一种反馈形式。
3.0责任
3.1质量管理/监管合规领导:正式指定接受、审查和管理的个人
evaluate complaints that comprise the Complaint Handling Unit (CHU). Job Descriptions and/or Org Charts may be utilized to designate the CHU per site.不是这样的:
本程序的目的是确保所有反馈都被记录下来,记录在案,并根据21 CFR 820和ISO 13485接收、评估和审查任何由此产生的投诉。
本程序适用于兰花收到的所有反馈。投诉是一种反馈形式。
责任-质量管理/监管合规领导:
发布于 2020-02-26 13:51:32
代码显示您只保留段落样式:
paragraph_styles = [ s for s in styles if s.type == WD_STYLE_TYPE.PARAGRAPH ]我认为你也应该尽量保持列表样式,比如:
paragraph_styles = [ s for s in styles if s.type in (WD_STYLE_TYPE.PARAGRAPH, WD_STYLE_TYPE.LIST ]https://stackoverflow.com/questions/60415274
复制相似问题