python批量替换页眉页脚
2015-06-19 15:46
681 查看
#!/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)
# -*- 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)
相关文章推荐
- virtualenv中安装python3.2的numpy包
- 基于python:opencv简单图片操作
- python资料汇总
- Python学习 之 函数
- Python学习路径8——Python对象2
- python实例26[计算MD5]
- python类库26[读写Excel]
- python日志打印重复(诡异)
- python , angular js 学习记录【1】
- sqlite python脚本
- Python学习 之 流程控制
- setuptools 和easy_install介绍和安装方法
- Python学习笔记(3)--- Flask安装
- webdriver+python 对三大浏览器的支持
- Python学习之库引用错误
- python-Levenshtein几个计算字串相似度的函数解析
- Python标准库:内置函数zip(*iterables)
- Python标准库:内置函数zip(*iterables)
- 《Writing Idiomatic Python》前两部分的中文翻译
- python logging