Python
2
Вклад в тег
from docx import Document
merged_doc = Document()
file_names = ["file1.docx", "file2.docx", "file3.docx"]
for file_name in file_names:
doc = Document(file_name)
for element in doc.element.body:
if isinstance(element, docx.oxml.table.CT_Tbl):
new_table = merged_doc.add_table(rows=0, cols=len(element[0]))
for row in element:
new_row = new_table.add_row().cells
for i, cell in enumerate(row):
new_row[i].text = cell.text
else:
merged_doc.element.body.append(element)
if file_name != file_names[-1]:
merged_doc.add_page_break()
merged_doc.save("merged.docx")