Manage Comments in DOC or DOCX Files

如何在Word文档中添加、管理和跟踪评论和更改

有效的文档合作往往依赖于无缝添加、管理和跟踪变更的能力。Aspose.Words for .NET 使开发人员能够在应用程序中编程地集成这些关键功能,使文档审查工作流动可靠。本指南提供了一个步骤步骤的 如何添加、管理和解决评论,以及通过Aspose.Words在 Word 文档中启用和使用变更跟踪。

建立你的环境

在您开始实施文档合作功能之前,确保您的开发环境正确配置:

  • Install the .NET SDK: Download and install the latest version of the .NET SDK from http://dotnet.microsoft.com/下载. 确保与 .NET 的 Aspose.Words 兼容性。
  • 添加 Aspose.Words 到您的项目: 使用 NuGet Package Manager 将 Aspose.Words 集成到您的 .NET 项目中:
dotnet add package Aspose.Words
  • Prepare a Word document: Create a sample Word document (e.g., review.docx)测试评论并改变跟踪功能。

一个步骤指南

本部分提供了一个详细的指南,伴随着代码示例,如何在Word文档中添加评论和跟踪更改,使用Aspose.Words for .NET。

步骤1:下载Word文档并添加评论

using System;
using Aspose.Words;
using Aspose.Words.Comment;

class Program
{
    static void Main()
    {
        string filePath = "review.docx";
        Document doc = new Document(filePath);

        // Step 1: Add a comment to the document
        Comment comment = new Comment(doc, "Reviewer Name", "RN", DateTime.Now)
        {
            Text = "This section needs additional explanation."
        };
        Paragraph para = doc.FirstSection.Body.FirstParagraph;
        para.AppendChild(comment);

        // Step 2: Enable change tracking
        doc.StartTrackRevisions("Reviewer Name");

        // Step 3: Modify the content
        para.AppendChild(new Run(doc, "Updated content added during review."));

        // Step 4: Save the updated document
        string outputPath = "ReviewedDocument.docx";
        doc.Save(outputPath);

        Console.WriteLine("Comments and change tracking applied successfully.");
    }
}

代码解释

  • 编码先加载“Word”文件(review.docx).
  • 创建一个新的评论,并与一个特定的段落相关联。
  • Change tracking is enabled using StartTrackRevisions.
  • 文档内容被修改(在这种情况下,添加了新的文本版本)。
  • Finally, the updated document is saved as ReviewedDocument.docx.

步骤2:检查文档中的评论和变更

  • Open the ReviewedDocument.docx file in Microsoft Word.
  • 确保您添加的评论在文档中正确显示。
  • 确认您所做的内容变更被跟踪为变更,与其相关的审查员信息。

常见问题

  • 未显示的评论:

  • 确保评论在文档结构内的有效段落或其他内容节点上正确附上。

  • 检查评论显示是否在 Word 的视图设置中被启用。

  • 未追踪的变化:

  • Verify that the StartTrackRevisions method is called 之前 any modifications are made to the document content.

  • Ensure that the user name provided to StartTrackRevisions is not empty or null.

  • 未支持的功能:

  • 请注意,在更新的 Word 版本中引入的一些先进的评论或更改跟踪功能可能与更旧的 Word 版本不完全兼容。

资源

Enhance your document collaboration workflows today! Download a free trial of Aspose.Words for .NET from http://releases.aspose.com/词语/ and explore its powerful features for adding, managing, and tracking comments and changes in Word documents. Visit our 人们在说什么 for more information and code examples. Explore our 产品 and check out our 博客 for the latest updates and tips.

 中文