我知道如何从word文档中获取页眉和页脚,但我要做的是操作这些页眉和页脚(如添加更多文本或从页眉或页脚中删除现有文本)。我的问题是如何使用python程序和pywin32操作页眉和页脚?请列出一些方法,以便我可以操作页眉和页脚。提前谢谢你。
import win32com.client as win32
word = win32.Dispatch("Word.Application")
word.Visible = 0
word.Documents.Open("a.docx")
doc = word.ActiveDocument
footer = doc.sections[0].footers[0] #get footer
header = doc.sections[0].headers[0] #get header
print(str(header)+" "+str(footer)) #printing both输出:页眉和页脚
发布于 2018-03-14 02:54:25
这对我很有效。请记住,根据您的需要,格式可能需要调整。
doc = word.ActiveDocument
sections = doc.Sections
for section in sections:
headersCollection = section.Headers
for header in headersCollection:
header.Range.Text = header.Range.Text + "hello world"
print(header.Range.Text)https://stackoverflow.com/questions/44261994
复制相似问题