我正在尝试使用find并使用win32com.client Python库替换为Word文档添加多个字符串值.
我可以找到并替换一个值,但我不知道如何为多个值执行此操作.
这是我到目前为止:
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
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我试图在python-docx(https://github.com/mikemaccana/python-docx)的帮助下自动创建.docx文件(WordML ).我当前的脚本使用以下循环手动创建ToC:
for chapter in myChapters:
body.append(paragraph(chapter.text, style='ListNumber'))
Run Code Online (Sandbox Code Playgroud)
有没有人知道使用"内置单词"ToC功能的方法,它会自动添加索引并创建各个章节的段落链接?
非常感谢!
有没有办法用 Python 有效地获取 word 文档(.doc、.docx)的页数?
对于 .odt 文件?
我想将它用于 Linux 上基于 Web2py 的 Web 应用程序。
谢谢 !