中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

python在windows下操作word的方法

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
import win32com
from win32com.client import Dispatch, constants
 
w = win32com.client.Dispatch('Word.Application')
# 或者使用下面的方法,使用啟動(dòng)獨(dú)立的進(jìn)程:
# w = win32com.client.DispatchEx('Word.Application')
 
# 后臺(tái)運(yùn)行,不顯示,不警告
w.Visible = 0
w.DisplayAlerts = 0
 
# 打開新的文件
doc = w.Documents.Open( FileName = filenamein )
# worddoc = w.Documents.Add() # 創(chuàng)建新的文檔
 
# 插入文字
myRange = doc.Range(0,0)
myRange.InsertBefore('Hello from Python!')
 
# 使用樣式
wordSel = myRange.Select()
wordSel.Style = constants.wdStyleHeading1
 
# 正文文字替換
w.Selection.Find.ClearFormatting()
w.Selection.Find.Replacement.ClearFormatting()
w.Selection.Find.Execute(OldStr, False, False, False, False, False, True, 1, True, NewStr, 2)
 
# 頁(yè)眉文字替換
w.ActiveDocument.Sections[0].Headers[0].Range.Find.ClearFormatting()
w.ActiveDocument.Sections[0].Headers[0].Range.Find.Replacement.ClearFormatting()
w.ActiveDocument.Sections[0].Headers[0].Range.Find.Execute(OldStr, False, False, False, False, False, True, 1, False, NewStr, 2)
 
# 表格操作
doc.Tables[0].Rows[0].Cells[0].Range.Text ='123123'
worddoc.Tables[0].Rows.Add() # 增加一行
 
# 轉(zhuǎn)換為html
wc = win32com.client.constants
w.ActiveDocument.WebOptions.RelyOnCSS = 1
w.ActiveDocument.WebOptions.OptimizeForBrowser = 1
w.ActiveDocument.WebOptions.BrowserLevel = 0 # constants.wdBrowserLevelV4
w.ActiveDocument.WebOptions.OrganizeInFolder = 0
w.ActiveDocument.WebOptions.UseLongFileNames = 1
w.ActiveDocument.WebOptions.RelyOnVML = 0
w.ActiveDocument.WebOptions.AllowPNG = 1
w.ActiveDocument.SaveAs( FileName = filenameout, FileFormat = wc.wdFormatHTML )
 
# 打印
doc.PrintOut()
 
# 關(guān)閉
# doc.Close()
w.Documents.Close(wc.wdDoNotSaveChanges)
w.Quit()

標(biāo)簽: isp

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:python多線程模塊threading使用范例代碼

下一篇:python實(shí)現(xiàn)ping操作并接收返回信息