是否有在 Python 中动态添加 Microsoft Word 脚注的解决方法?

Is there a workaround for adding Microsoft Word footnotes dynamically in Python?

目前我正在使用 Python Flask 构建一个应用程序,以根据存储在 sql 数据库中的数据生成格式化文档。我的想法是检测文本中的脚注标记并在 运行:

上呈现脚注
text = ''' This is a sample text {{footnotes:Yes it is!}} It's just that. '''
footnote = text[text.find("{{footnotes:")+12:text.find("}}")]

但是,python-docx 似乎不提供脚注操作,非常 moment.Are 还有 Python(或 node.js 中的任何其他包,最好不要因为应用程序将重新从头开始制作)以将脚注添加到 .doc 文件?

首先制作文档 Markdown 然后以某种方式将其转换为具有脚注属性的 .docx 是否可行?

来自 python-docx 文档 (https://python-docx.readthedocs.io/en/latest/user/documents.html):

The feature set is still being built out, so you can’t add or change things like headers or footnotes yet

但是您可以使用 xml 结构来定位它们,如 https://github.com/python-openxml/python-docx/issues/1

中所讨论的

或者

中显示了更好的解决方案

如果我理解这个解决方案,他建议基本上创建一个带有您想要的脚注的模板,然后将其加载到 python。这不会是 "dynamic",但也可能不是您要找的东西。

似乎在 2014 年,python-docx 的一位开发人员在 https://groups.google.com/forum/#!topic/python-docx/4iQoFG2X03I 进行了一次谈话,他说他几个月内不会参与该项目。也许您可以尝试在那里或通过主 docx 站点与他联系并帮助他构建模块(这样您就不必自己处理所有 xml 处理)。否则你将不得不找到另一个解决方案(你提到了 Node.js,但我对此一无所知,所以我无能为力)。祝你好运!