本主题介绍如何使用 Node.js 的 REST API 在 DOCX 中插入注释。我们将使用 Aspose.Words for Node.js Cloud SDK,通过 Node.js 的 Low Code API 在 Word 文档中添加注释。您将获得设置开发环境以及遵循给定步骤和 Node.js REST API 代码的所有详细信息。
先决条件
- 创建帐户并获取 API 凭证 在 DOC 文件中插入注释
- 下载 适用于 Node.js 的 Aspose.Words Cloud SDK 以在 Word 文件中添加注释
- 使用上述 SDK 设置 Nodej.s 解决方案项目以添加 DOCX 注释
使用 Node.js REST API 将注释插入 Word 文档的步骤
- 设置 API 的客户端 ID 和客户端密钥以在 Word 文件中添加注释
- 使用您的客户帐户凭据创建 WordsAPI 类的对象
- 通过提供评论的开始和结束范围来创建 CommentInsert 的对象
- 通过提供文件名,使用 InsertCommentOnlineRequest 实例创建添加评论的请求
- 在 Word 文档中插入注释 在线使用 InsertComment 方法
- 使用response.Documents字典中的流从云端下载生成的文件
- 将下载的文件流保存为磁盘上的 DOCX 文件
上述步骤解释了如何使用 Node.js 的 REST API 在 Word 文档中插入注释。我们将首先使用 ClientSecret 和 ClientId 初始化 WordsApi 类实例,然后通过设置注释的起始和范围来创建 InsertComment 类实例。接下来,我们将创建 InsertCommentOnlineRequest 请求,并使用 InsertCommentOnline 获取已添加注释的 DOCX 文件流。最后,我们将已添加注释的文件流以 DOCX 文件的形式保存到磁盘上。
使用 Nodej.s REST API 在 Word 文档中添加注释的代码
此示例代码演示了使用 Node.js 的 Low Code API 在 DOCX 中创建注释的过程。CommentInsert 类公开了用于设置注释起始和结束范围、注释首字母、作者和文本的属性。您也可以在文档中添加多条注释。我们为 requesInsertCommentOnlineRequest 设置的文件名将用于从响应对象中提取相应的文档文件流。
In this topic, we have learned to add comments in Word document with Nodej.s REST API. If you are looking to create a Word Document, refer to the article on how to create a Word File with Nodej.s REST API.