使用 Python 的 docx 库时如何配置页眉(和页脚)的 "Header from Top" 值?
How to configure header's (and footer's) "Header from Top" value when using Python's docx library?
我正在尝试从头开始创建 docx 文件报告,因此我使用的是 python-docx 库版本 0.8.10,效果很好。当我向文档添加页眉时,页眉的默认值为 "Header from Top:" = 0.5 英寸。当我创建 docx 文件并在 MS WORD 中打开它时,我看到了这个值。
那么,如何配置 "Header from Top" 和 "Footer from Bottom" 默认值?例如,如何将页眉配置为 "Header from Top" = 0.1 英寸?类似于 header.top_margins = 英寸 (0.1)。我上网查了,没找到相关的。
提前致谢
我认为您正在寻找 Section.header_distance
和 .footer_distance
:
https://python-docx.readthedocs.io/en/latest/api/section.html#docx.section.Section.header_distance
header_distance
Length object representing the distance from the top edge of the page to the top edge
of the header. None if no setting is present in the XML.
我正在尝试从头开始创建 docx 文件报告,因此我使用的是 python-docx 库版本 0.8.10,效果很好。当我向文档添加页眉时,页眉的默认值为 "Header from Top:" = 0.5 英寸。当我创建 docx 文件并在 MS WORD 中打开它时,我看到了这个值。
那么,如何配置 "Header from Top" 和 "Footer from Bottom" 默认值?例如,如何将页眉配置为 "Header from Top" = 0.1 英寸?类似于 header.top_margins = 英寸 (0.1)。我上网查了,没找到相关的。
提前致谢
我认为您正在寻找 Section.header_distance
和 .footer_distance
:
https://python-docx.readthedocs.io/en/latest/api/section.html#docx.section.Section.header_distance
header_distance
Length object representing the distance from the top edge of the page to the top edge of the header. None if no setting is present in the XML.