5
Tôi đang cố thêm nhiều giá trị chuỗi vào tài liệu Word bằng cách tìm và thay thế bằng thư viện Python win32com.client.sử dụng win32com.client trong python cách tìm và thay thế nhiều văn bản
Tôi có thể tìm và thay thế một giá trị, nhưng tôi không biết cách thực hiện điều này cho nhiều giá trị.
Đây là những gì tôi có cho đến nay:
import win32com.client
word = win32com.client.DispatchEx("Word.Application")
word.Visible = True
word.DisplayAlerts = 0
word.Documents.Open("C:\TEMP\Testing\Me.docx")
word.Selection.Find
find.Text = "First Name"
find.Replacement.Text = "John"
find.Execute(Replace=1, Forward=True)
# the following part doesn't run
find.Text = "Last Name"
find.Replacement.Text = "Smith"
find.Execute(Replace=1, Forward=True)
word.ActiveDocument.SaveAs('C:\TEMP\Testing\Me2.docx')
word.Quit() # releases Word object from memory
Bất kỳ lời đề nghị?