python-3.x - 如何使用 python-docx 在 docx 中设置页脚
问题描述
我无法在 Docx 中使用python-docx
.
我有这样的代码:
from docx import Document
from docx.shared import Cm
from docx.enum.text import WD_ALIGN_PARAGRAPH
document = Document()
document.add_heading('Document Title', 0)
section = document.sections[0]
footer = section.footer
footer.add_paragraph("This is page number")
footer.footer_distance = Cm(3)
footer.bottom_margin = Cm(5.0)
footer.alignment = WD_ALIGN_PARAGRAPH.RIGHT
document.save('mydoc.docx')
我将页脚设置为bottom = Cm(5.0)
, footer_distance = Cm(3)
, 对齐RIGHT
。但什么也没有发生。
有人可以帮助我吗?也许我错过了什么?谢谢。
解决方案
页脚对象没有.footer_distance
或.bottom_margin
属性。这些在该部分。
https://python-docx.readthedocs.io/en/latest/api/section.html#docx.section.Section.footer_distance
如果您将代码更改为:
section.footer_distance = Cm(3)
您应该看到文档中的间距发生了变化。
推荐阅读
- c - 在 repl.it 上的 C 中的“迷宫”数组中开辟一条清晰的路径
- graph - 如何使用 Microsoft Graph API 访问组/团队邮箱
- visual-studio-code - 无法使用 MSVC 构建工具使用 Visual Studio Code 编译文件
- java - Eclipse 和 Struts 2 缺少“s:text”的结束标记
- linux - 为什么触摸 - 不返回任何错误但没有创建文件 - ?
- flutter - 使用 BottomNavigationBar 时如何通过屏幕导航缓存 FutureBuilder 异步结果?
- javascript - 强制用户仅使用地点自动完成结果
- r - 读取 csv 文件无法打开连接
- excel - 尽管操作成功,但对象需要错误
- javascript - 多 div 的动画 scrollTop 问题