Пример #1
0
def combine_word_documents(path, files):
    """
    merge docx
    """
    merged_document = Document()
    merged_document.save(path + "\\" + 'merge.docx')
    try:
        for index, file in enumerate(files):
            doc = Document(path + "\\" + 'merge.docx')
            doc.add_paragraph('{{temp_name}}')
            doc.add_page_break()
            doc.save(path + "\\" + 'merge.docx')
            doc = DocxTemplate(path + "\\" + '合并文件.docx')
            sub = doc.new_subdoc()
            sub.subdocx = Document(path + "\\" + file)
            doc.render({'temp_name': sub})
            doc.save(path + "\\" + 'merge.docx')
    except Exception as e:
        pass