Python batch replacement of header and footer instance code, python header and footer instance

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.