您好,登錄后才能下訂單哦!
本文分享的實(shí)例代碼主要通過(guò)python語(yǔ)言實(shí)現(xiàn)批量替換頁(yè)眉頁(yè)腳的操作功能,具體如下。
#!/usr/bin/env python # -*- coding: utf-8 -*- import win32com,os,sys,re from win32com.client import Dispatch, constants # 打開(kāi)新的文件 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 #準(zhǔn)備替換的文件夾 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)
以上就是本文關(guān)于python批量替換頁(yè)眉頁(yè)腳實(shí)例代碼的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。