Python batch replacement of header and footer instance code, python header and footer instance
Introduction
The example code shared in this article mainly uses the python language to replace the header and footer in batches. The details are as follows.
Code
#! /Usr/bin/env python #-*-coding: UTF-8-*-import win32com, OS, sys, re from win32com. client import Dispatch, constants # Open the new file suoyou = OS. listdir ('d: \ daizhuan ') # print suoyoufor 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 # The folder to be replaced wancheng = 'd: \ wancheng \ % s '% I # directory output after replacement is complete 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 () failed t Exception, e: print str (e)
Summary
The above is all the content about the python batch replacement of the header and footer instance code in this article. I hope it will be helpful to you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!