在word中替换关键文字
from win32com.client import Dispatch
import time
# def tihuan(before,content):
# word = Dispatch('Word.Application')
# doc = word.Documents.Open(r"E:\sxx\test2.docx")
# word.Selection.Find.Execute(before, False, False, False, False, False, True, 1, True, content, 2)
f=open("mingdanB.txt")
i=0
for each in f:
listeach=each.split("\t")
time.sleep(1)
word = Dispatch('Word.Application')
doc = word.Documents.Open(r"E:\sxx\test.docx")
word.Selection.Find.Execute("朱红", False, False, False, False, False, True, 1, True, listeach[0], 2)
word.Selection.Find.Execute("SHA603", False, False, False, False, False, True, 1, True, listeach[1], 2)
word.Selection.Find.Execute("2016.3.26-2017.12.31", False, False, False, False, False, True, 1, True, listeach[2], 2)
word.Selection.Find.Execute("3042.2", False, False, False, False, False, True, 1, True, listeach[3],2)
word.Selection.Find.Execute("2014.10.1-2017.9.30", False, False, False, False, False, True, 1, True, listeach[4], 2)
word.Selection.Find.Execute("704", False, False, False, False, False, True, 1, True, listeach[5], 2)
word.Selection.Find.Execute("3746.2", False, False, False, False, False, True, 1, True, listeach[6].strip("\n"), 2)
word.Selection.Find.Execute("3746.3", False, False, False, False, False, True, 1, True, listeach[6].strip("\n"), 2)
time.sleep(1)
doc.SaveAs(r"E:\sxx\test"+str(i)+".docx")
doc.Close()
i=i+1