期末臨近,老師需要合併學生提交的作業,作業是word文檔,合併到一個,利於閱卷
想起前幾天看過的一篇python自動化辦公的帖子,想自己動手試一試
庫需求:python-docx、docxcompose、os
輸入工作目錄,os模塊會讀取該目錄下的文件列表,將其保存在files列表中
遍歷該列表,將裏面的word文檔都插進去
通俗點講,就是你輸入你把要合併的文檔都放在一個目錄,目錄裏不要有其他東西
把目錄名複製上來,目錄裏所有的文檔將會被打包
你輸入要輸出文檔的名字,他會在目錄裏輸出合併後的文檔
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')
學委沒裝python環境,裝起來夠麻煩的
所以將程序又用pyinstaller打了包
pyinstaller -F test.py