Created
September 14, 2021 06:10
-
-
Save aydinemre/15e3334620e12bba892dc4732ced442a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install docxcompose | |
# Combines all word files under docs folder | |
import os | |
from pathlib import Path | |
from docxcompose.composer import Composer | |
from docx import Document as Document_compose | |
def combine_all_docx(filename_master, files_list, output_file='combined_files.docx'): | |
number_of_sections = len(files_list) | |
master = Document_compose(filename_master) | |
composer = Composer(master) | |
for i in range(0, number_of_sections): | |
doc_temp = Document_compose(files_list[i]) | |
composer.append(doc_temp) | |
composer.save(output_file) | |
filename_master = "master.docx" | |
files = [d.absolute() for d in Path('docs').glob('*.docx')] | |
combine_all_docx(filename_master, files) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment