The end of the semester is approaching, the teacher needs to merge the assignments submitted by the students. The assignments are word documents and merged into one, which is conducive to marking. I
remembered a post on python automation office I read a few days ago, and I want to try it myself
Library requirements: python-docx, docxcompose, os
enter the working directory, and the os module will read the list of files in this directory and save them in the files list.
Traverse the list and insert all the word documents in it
In layman's terms, you enter the documents you want to merge in a directory, and there should be no other things in
the directory. Copy the directory name, all the documents in the directory will be packaged.
You enter the name of the output document, and he will Output the merged document in the directory
import os
from docx import Document
from docxcompose.composer import Composer
print("The software is designed by STL_CC")
print("For more details and useage,just get to my blog:")
print("https://blog.csdn.net/STL_CC/article/details/106387603")
path=input("Please tell me the working directory:")
name=input("Please tell me the name of the new document:")
files = []
for filename in os.listdir(path):
filename = os.path.join(path,filename)
files.append(filename)
new_document = Document()
composer=Composer(new_document)
for f in files:
composer.append(Document(f))
composer.save(path+'\\'+name+'.docx')
The academic committee did not install the python environment, which was troublesome enough,
so the program was packaged with pyinstaller
pyinstaller -F test.py