利用python-docx和docxcompose实现word合并,自动化办公

期末临近,老师需要合并学生提交的作业,作业是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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值