要将Word文档的页眉改为Python,您可以使用Python的`python-docx`库。以下是使用`python-docx`设置页眉的步骤:
1. 首先,确保您已经安装了`python-docx`库。如果尚未安装,可以通过以下命令安装:
pip install python-docx
2. 然后,您可以使用以下代码示例来设置Word文档的页眉:
from docx import Document创建一个新的文档对象doc = Document()添加页眉header = doc.sections.headerparagraph = header.paragraphsparagraph.text = "这是页眉文本"保存文档doc.save('new_document.docx')

如果您想要设置奇偶页不同的页眉,可以使用以下代码:
from docx import Document创建一个新的文档对象doc = Document()设置奇偶页不同的页眉doc.settings.odd_and_even_pages_header_footer = True添加奇数页页眉header_odd = doc.sections.odd_page_headerparagraph_odd = header_odd.paragraphsparagraph_odd.text = "这是奇数页页眉"添加偶数页页眉header_even = doc.sections.even_page_headerparagraph_even = header_even.paragraphsparagraph_even.text = "这是偶数页页眉"保存文档doc.save('new_document.docx')
请根据您的需求修改上述代码中的文本内容。
