Wordテンプレートを適用します

#長いためのテンプレート、及び元の形式保持
DOCXインポート文書からの
docx.sharedインポートのPtから
QN docx.oxml.nsインポートから

ドキュメント=ドキュメント(R'C:/ユーザ/ 13375 /デスクトップ/パイソン/永遠の後悔2.docx ')
document.styles ['通常']微軟雅黒' = U font.name '
document.styles ['通常'] element.rPr.rFonts.set(Qnは(' W:eastAsia ')、U'マイクロソフト黒YA ')
。document.styles ['通常「] = Font.SizeのPt(22)と


DEF change_text(OLD_TEXT、NEW_TEXT):
    all_paragraphs = document.paragraphs
    段落all_paragraphs内用:
        RUNにするためparagraph.runs:
            run_text = RUN。 text.replace(OLD_TEXT、NEW_TEXT)
            Run.Text = run_text
        
    ALL_TABLES = document.tables
    表でALL_TABLES用:
        :table.rowsにおける行の
            row.cellsのセルのために:
                セル内の文字列= cell.text.replace(OLD_TEXT、NEW_TEXT)
                cell.text =セル内の文字列
                
change_text( '不'、 'OK')
change_text( '女'、 '男性' )

document.save(R'C:/ユーザー/ 13375 /デスクトップ/パイソン/长恨歌修改后の.docx ')

おすすめ

転載: www.cnblogs.com/tomhu/p/12342998.html