使用 Python REST API 在 Word 中插入脚注

本文介绍如何使用 Python REST API 在 Word 中插入脚注。您将学习如何使用 Aspose.Words for Python Cloud SDK 通过 Python Low Code API 添加 Word 脚注。我们将讨论在将脚注添加到文档之前可以设置的各种属性。

先决条件

使用 Python REST API 在 Word 中添加脚注的步骤

  1. 通过提供客户端 ID 和密钥来实例化 WordsApi 对象以插入尾注
  2. 读取输入的Word文件并将其存储在文件流中
  3. 通过设置各种属性来创建 FootnoteInsert 对象
  4. 通过设置请求、FootnoteInsert 和目标文件名来创建 InsertFootnoteOnlineRequest 方法
  5. 调用 在线插入脚注 方法在源 Word 文件中插入脚注
  6. 从结果中获取输出流并将其保存在磁盘上

上述步骤描述了如何使用 Python REST API 在 Word 中创建脚注。首先,将源 Word 文件加载到 FileStream 对象中,并使用 FootnoteInsert 类创建脚注。使用此脚注创建 InsertFootnoteOnlineRequest,最终可以使用 InsertFootnoteOnline 方法在 Word 文件中创建脚注。

使用 Python REST API 在 Word 中创建脚注的代码

此示例代码演示了如何使用 Python REST API 在 Word 中添加脚注。FootnoteInsert 类包含各种属性,例如 Position,可以将其设置为指向范围起始节点和引用标记的链接。调用的响应包含 Document.TryGetValue() 方法,该方法将生成的 Word 文件返回到流对象中,以便保存到磁盘或数据库中。

In this topic, we have learned the process of adding a footnote in a Word document. If you are looking to replace text in a Word file, refer to the following article: Replace a Word in Word with Python REST API.

 简体中文