简介
本文分享的实例代码主要通过python语言实现批量替换页眉页脚的操作功能,具体如下。
代码
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40#!/usr/bin/env python # -*- coding: utf-8 -*- import win32com,os,sys,re from win32com.client import Dispatch, constants # 打开新的文件 suoyou = os.listdir('d:\\daizhuan') #print suoyou for i in suoyou: wenjian_name = os.path.join('d:\\daizhuan',i) #print wenjian_name if os.path.isfile(wenjian_name): w = win32com.client.Dispatch('Word.Application') w.Visible = 0 w.DisplayAlerts = 0 daizhuan = 'd:\\daizhuan\\%s' % i #准备替换的文件夹 wancheng = 'd:\\wancheng\\%s' % i #替换完成后输出的目录 doc = w.Documents.Open('d:\\biaozhun\\biaozhun.doc') w.ActiveDocument.Sections[0].Headers[0].Range.Copy() wc = win32com.client.constants doc.Close() doc2= w.Documents.Open( daizhuan) w.ActiveDocument.Sections[0].Headers[0].Range.Paste() w.ActiveDocument.SaveAs(wancheng) doc2.Close() doc3 = w.Documents.Open( 'd:\\biaozhun\\biaozhun.doc') w.ActiveDocument.Sections[0].Footers[0].Range.Copy() doc3.Close() doc4= w.Documents.Open( daizhuan) w.ActiveDocument.Sections[0].Footers[0].Range.Paste() doc4.Close() try: w.Documents.Close() w.Quit() except Exception , e: print str(e)
总结
以上就是本文关于python批量替换页眉页脚实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!
最后
以上就是沉默宝马最近收集整理的关于python批量替换页眉页脚实例代码的全部内容,更多相关python批量替换页眉页脚实例代码内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复