我正在尝试使用win32com编辑已有标题的MS Word文档的标题。
我试着这样编辑页眉:
import win32com.client as win32
word = win32.gencache.EnsureDispatch('Word.Application')
doc=word.Documents.Open("C:\\a.docx")
word.Visible = True
word.ActiveDocument.Sections[0].Headers[win32.constants.wdHeaderFooterPrimary].Range.Text='test text'
word.ActiveDocument.Save()
doc.Close(False)
word.Application.Quit()但是没有效果(标题根本没有改变)!!
通过win32com编辑MS Word标题的正确方法是什么?
发布于 2013-01-04 07:01:47
在此行中使用圆括号而不是方括号,以及从1开始的索引。COM中的一切都是函数调用或属性。
word.ActiveDocument.Sections(1).Headers(win32.constants.wdHeaderFooterPrimary).Range.Text='test text'https://stackoverflow.com/questions/14148531
复制相似问题