当前位置:网站首页>原生方法合并word
原生方法合并word
2022-07-02 09:32:00 【nongcunqq】
import os
#输入输出函数,用来获取目录路径
import win32com.client as win32
word = win32.gencache.EnsureDispatch('Word.Application')
#启动word对象应用
word.Visible = False #是否可视化,如果改为True,则会在电脑上频繁出现word文档界面
path = r'D:\word'
#存放文件路径
files = []
for filename in os.listdir(path):
filename = os.path.join(path,filename)
files.append(filename)
#获取目录下所有文件的路径
output = word.Documents.Add()
#print(output)
print(files)
#新建空的word文档,
for file in files:
output.Application.Selection.InsertFile(file)
#拼接文档
doc = output.Range(output.Content.Start, output.Content.End)
#获取合并后文档的内容
output.SaveAs('D://word//result.docx') #保存
output.Close()#关闭
参考
https://blog.csdn.net/weixin_44999258/article/details/125163277
边栏推荐
- spritejs
- Implement custom drawer component in quick application
- Primary key policy problem
- One trick to quickly realize custom application titlebar
- 二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
- TIPC Getting Started6
- Indexer in C #
- Pit of the start attribute of enumrate
- Verilog 和VHDL有符号数和无符号数相关运算
- What are the methods of adding elements to arrays in JS
猜你喜欢
Tick Data and Resampling
Special topic of binary tree -- acwing 19 The next node of the binary tree (find the successor of the node in the tree)
Thanos Receiver
Creation and use of unified links in Huawei applinking
【AI应用】海康威视iVMS-4200软件安装
[AI application] Hikvision ivms-4200 software installation
What are the software product management systems? Inventory of 12 best product management tools
从攻击面视角,看信创零信任方案实践
QT学习日记7——QMainWindow
【深入浅出玩转FPGA学习5-----复位设计】
随机推荐
Special topic of binary tree -- acwing 1589 Building binary search tree
Complement (Mathematical Simulation
Implement custom drawer component in quick application
金山云——2023届暑期实习
TIPC Service and Topology Tracking4
洛谷 P5536 【XR-3】核心城市(贪心 + 树形 dp 寻找树的中心)
static 函数中的静态变量
Creation and use of unified links in Huawei applinking
PHP tea sales and shopping online store
二叉树专题--AcWing 19. 二叉树的下一个节点(找树中节点的后继)
What are the software product management systems? Inventory of 12 best product management tools
C# 文件与文件夹操作
TIPC 寻址2
The first white paper on agile practice in Chinese enterprises was released | complete download is attached
Tick Data and Resampling
Array splitting (regular thinking
高德根据轨迹画线
PCL extracts a subset from a point cloud
Functional interfaces and method references
TIPC Cluster5