Extracting Tracked Changes - Section/Paragraph number

Hello,

Just wondering if it’s possible when extracting tracked changes from a document, if you can identity the section or paragraph number where each tracked change occurred?

@Kayleigh

To extract tracked changes along with their section or paragraph numbers from a Word document using Aspose.Words, you can utilize the Document class and iterate through the Revisions collection. Each revision provides information about its location in the document.

Here’s a sample code snippet to help you achieve this:

using Aspose.Words;
using Aspose.Words.Revisions;

Document doc = new Document("path/to/your/document.docx");

// Iterate through all revisions in the document
foreach (Revision revision in doc.Revisions)
{
    // Get the paragraph where the revision occurred
    Paragraph paragraph = (Paragraph)revision.ParentNode;
    
    // Get the section number (1-based index)
    int sectionIndex = doc.IndexOf(paragraph.Section) + 1;

    // Get the paragraph number (1-based index)
    int paragraphIndex = paragraph.Index + 1;

    // Output the revision details
    Console.WriteLine($"Revision Type: {revision.RevisionType}, Section: {sectionIndex}, Paragraph: {paragraphIndex}");
}

In this code:

  • The document is loaded, and we iterate through its revisions.
  • For each revision, we determine the paragraph it belongs to and its section.
  • We then print out the type of revision along with its section and paragraph numbers.

Make sure to replace "path/to/your/document.docx" with the actual path to your document. This will provide a clear view of where each tracked change is located within the document structure.

Please note that this approach is specific to Word documents. If you are working with a different file type, such as plain text, the method for extracting changes will differ significantly.