Example #1
0
def _combine_docx(target_file, files):
    master = Document_compose(files[0])
    composer = Composer(master)
    for i in range(1, len(files)):
        doc_temp = Document_compose(files[i])
        composer.append(doc_temp)
    composer.save(target_file)
Example #2
0
def merge_word_documents(indir,
                         outfile=search_book_name(),
                         add_page_break=True,
                         delete_merged_files=True):
    """
    Merge word documents.
    :param indir: THe directory where the documents are stored.
    :param outfile: THe outfile name of the word documents.
    :param add_page_break: flag for adding page breaks between documents.
    :param delete_merged_files: flag determining if the files merged files should be deleted.
    """
    files = [f"{indir}/{f}" for f in os.listdir(indir) if f.endswith(".docx")]
    first, *rest = files
    master = Document_compose(first)
    if add_page_break:
        master.add_page_break()
    composer = Composer(master)
    for i, f in enumerate(rest):
        tmp = Document_compose(f)
        if add_page_break and i < len(rest) - 1:
            tmp.add_page_break()
        composer.append(tmp)
    composer.save(f"{indir}/{outfile}")

    if delete_merged_files:
        for f in files:
            os.remove(f)
Example #3
0
def combine_all_docx(filename_master, files_list):
    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("combined_file.docx")
Example #4
0
def mergeDoc(filename_master, files_list):
    number_of_sections = len(files_list)
    master = Document_compose()
    composer = Composer(master)
    for i in range(0, number_of_sections):
        doc_temp = Document_compose(files_list[i])
        composer.append(doc_temp)
    composer.save(filename_master)
Example #5
0
def combine_resumes_and_other_stuff(resume_list):
    number_of_sections = len(resume_list)
    master = Document_compose(filename_master)
    composer = Composer(master)
    for i in range(0, number_of_sections):
        doc_temp = Document_compose(resume_list[i])
        composer.append(doc_temp)
    composer.append(Document_compose(last))
    composer.save(resume_master)
Example #6
0
def combine_all_docx(filename_master, files_list):
    # Функция для объединения документов
    number_of_sections = len(files_list)
    master = Document_compose(filename_master)
    composer = Composer(master)
    for i in range(1, number_of_sections):
        doc_temp = Document_compose(files_list[i])
        composer.append(doc_temp)
    composer.save("Все сертификаты в одном файле.docx")
Example #7
0
def combine_all_docx(filename_master, files_list):
    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)
    open('1.txt', 'w')
    composer.save("ALL_SERTIFICATES.docx")
Example #8
0
def combine_all_env(filename_master,files_list):

    savepath = os.getcwd() + "\\print\\" + name + "_combined_envelope.docx"
    number_of_sections=len(files_list)
    master = Document_compose(filename_master)
    composer = Composer(master)
    for i in range(0, number_of_sections):
        if os.path.isfile(files_list[i]) == True:
            doc_temp = Document_compose(files_list[i])
            composer.append(doc_temp)
    composer.save(savepath)
def combine_all_docx(filename_master, files_list, output):
    print('Merging: %s' % filename_master)
    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)
        print('Merging: %s' % (files_list[i]))
    composer.save(output)
    hr('OUTPUT:')
    print('Output file: %s' % output)
Example #10
0
def press(file1, file2, file3, file4):
    from docxcompose.composer import Composer
    import docx
    from docx import Document as Document_compose
    file_cover = docx.Document('cover.docx')
    file_cover.add_page_break()
    file_cover.save('dummy.docx')
    master = Document_compose('dummy.docx')
    composer = Composer(master)

    filec1 = docx.Document(file1)
    filec1.add_page_break()
    filec1.save('dummy1.docx')
    doc1 = Document_compose('dummy1.docx')
    composer.append(doc1)

    filec2 = docx.Document(file2)
    filec2.add_page_break()
    filec2.save('dummy2.docx')
    doc2 = Document_compose('dummy2.docx')
    composer.append(doc2)

    filec3 = docx.Document(file3)
    filec3.add_page_break()
    filec3.save('dummy3.docx')
    doc3 = Document_compose('dummy3.docx')
    composer.append(doc3)

    filec4 = docx.Document(file4)
    filec4.add_page_break()
    filec4.save('dummy4.docx')
    doc4 = Document_compose('dummy4.docx')
    composer.append(doc4)

    doc5 = Document_compose('end.docx')
    composer.append(doc5)

    return composer
                    help="Cover docx file name",
                    default="cover.docx")
parser.add_argument("-b",
                    "--body",
                    help="Body docx file name",
                    default="body.docx")
parser.add_argument("-o",
                    "--output",
                    help="Output docx file name",
                    default="final.docx")
args = parser.parse_args()
FINISHED = False
TRY_COUNTER = 20
while not FINISHED:
    try:
        cover = Document_compose(args.cover)
        body = Document_compose(args.body)
        composer = Composer(cover)
        composer.append(body)
        composer.save(args.output)
        FINISHED = True

    except PermissionError as exception_thrown:
        print("Files not ready yet-")
        TRY_COUNTER -= 1
        if TRY_COUNTER == 0:
            print("Document Composer Script failed - {}".format(
                exception_thrown))
            sys.exit(1)

        time.sleep(3)