We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Extract table revisions from word document along with insertion and deletion revisions

Hi Team,

I want to get the below values from table and other normal paragraphs.
As per the attached sample.docx,Sample.docx (15.6 KB)

need the details as
Normal Paragraph:
Change Type: Insertion/Deletion
Text Changed :

Table Changes
Change Type: Insertion
Text Changed in Table:Employee

Change Type: Deletion
Text Changed in Table:NY

Change Type: Deletion
Text Changed in Table:2
can we get column name, before text and after text for each change in table ?
Change Type: Deletion
Text Changed in Table:2
Column Name: Id

Please suggest

@sureshkap You can use Revision class to access information bout revisions in your document. For example see the following code:

Document doc = new Document(@"C:\Temp\Sample.docx");

Dictionary<RevisionGroup, List<Revision>> groups = new Dictionary<RevisionGroup, List<Revision>>();
List<Revision> individualRevisions = new List<Revision>();

foreach (Revision rev in doc.Revisions)
{
    if (rev.Group == null)
    {
        individualRevisions.Add(rev);
        continue;
    }

    if (!groups.ContainsKey(rev.Group))
    {
        groups.Add(rev.Group, new List<Revision>());
    }

    groups[rev.Group].Add(rev);
}

Console.WriteLine("There are {0} revision groups in the document.", groups.Count);
Console.WriteLine("There are {0} individual revisions in the document.", individualRevisions.Count);
foreach (RevisionGroup g in groups.Keys)
{
    Console.WriteLine("==============================================");
    Console.WriteLine("Revision group type : {0}", g.RevisionType);
    Console.WriteLine("Revision group author : {0}", g.Author);
    Console.WriteLine("Revision group modified text : \"{0}\"", g.Text);

    // Print an individual revision information within a group.
    foreach (Revision r in groups[g])
        PrintRevisionInfo(r);
}

Console.WriteLine("==============================================");
// Print an individual revisions
if (individualRevisions.Count > 0)
{
    Console.WriteLine("Individual revisions.");
    foreach (Revision r in individualRevisions)
        PrintRevisionInfo(r);
}
private static void PrintRevisionInfo(Revision r)
{
    Console.WriteLine("\t--------------------------------------");
    Console.WriteLine("\tDate: {0}", r.DateTime);
    Console.WriteLine("\tAuthor: {0}", r.Author);
    Console.WriteLine("\tRevisionType: {0}", r.RevisionType);
    Console.WriteLine("\tRevision is applied to text: \"{0}\"", r.ParentNode.ToString(SaveFormat.Text));
}

Thank you for your valuable solution. It is working fine.
Now I have to get the revisions data from the table with merged cells.
In the attached document, need revisions data from table 2 and table3. Is it possible to get the row wise data like
Capital gain Very Great To do 86
or only possible to get cell wise data? Please clarify.
Sample.docx (21.3 KB)

@sureshkap You can use Revision.ParentNode property to get the parent node of the revision. On this node you can find whether the node is in a table row using GetAncestor method and passing NodeType.Row as a parameter.

Could you please elaborate with the sample code related to get the data from a new row insertion.
It is working fine for the merged cells but not for the new row insertion.
Scarlet 3 UK
How to get the new row data

@sureshkap Please modify PrintRevisionInfo like shown below:

private static void PrintRevisionInfo(Revision r)
{
    Console.WriteLine("\t--------------------------------------");
    Console.WriteLine("\tDate: {0}", r.DateTime);
    Console.WriteLine("\tAuthor: {0}", r.Author);
    Console.WriteLine("\tRevisionType: {0}", r.RevisionType);
    Console.WriteLine("\tRevision is applied to: {0}", r.ParentNode.NodeType);
    if(r.ParentNode.NodeType == NodeType.Run)
        Console.WriteLine("\tRevision is applied to text: \"{0}\"", r.ParentNode.ToString(SaveFormat.Text));
}

In this case the output of the last revision group will look like this:

Revision group type : Insertion
Revision group author : Suresh Kapisetty
Revision group modified text : "Capital gain"
        --------------------------------------
        Date: 3/8/2022 11:44:00 AM
        Author: Suresh Kapisetty
        RevisionType: Insertion
        Revision is applied to: Row
        --------------------------------------
        Date: 3/8/2022 11:44:00 AM
        Author: Suresh Kapisetty
        RevisionType: Insertion
        Revision is applied to: Paragraph
        --------------------------------------
        Date: 3/8/2022 11:44:00 AM
        Author: Suresh Kapisetty
        RevisionType: Insertion
        Revision is applied to: Run
        Revision is applied to text: "Capital gain"
        --------------------------------------
        Date: 3/8/2022 11:44:00 AM
        Author: Suresh Kapisetty
        RevisionType: Insertion
        Revision is applied to: Paragraph
        --------------------------------------
        Date: 3/8/2022 11:44:00 AM
        Author: Suresh Kapisetty
        RevisionType: Insertion
        Revision is applied to: Run
        Revision is applied to text: "Very Great"
        --------------------------------------
        Date: 3/8/2022 11:44:00 AM
        Author: Suresh Kapisetty
        RevisionType: Insertion
        Revision is applied to: Paragraph
        --------------------------------------
        Date: 3/8/2022 11:44:00 AM
        Author: Suresh Kapisetty
        RevisionType: Insertion
        Revision is applied to: Run
        Revision is applied to text: "To do"
        --------------------------------------
        Date: 3/8/2022 11:44:00 AM
        Author: Suresh Kapisetty
        RevisionType: Insertion
        Revision is applied to: Paragraph
        --------------------------------------
        Date: 3/8/2022 11:44:00 AM
        Author: Suresh Kapisetty
        RevisionType: Insertion
        Revision is applied to: Run
        Revision is applied to text: "86"
        --------------------------------------
        Date: 3/8/2022 11:44:00 AM
        Author: Suresh Kapisetty
        RevisionType: Insertion
        Revision is applied to: Paragraph
        --------------------------------------
        Date: 3/8/2022 11:44:00 AM
        Author: Suresh Kapisetty
        RevisionType: Insertion
        Revision is applied to: Paragraph
        --------------------------------------
        Date: 3/8/2022 11:44:00 AM
        Author: Suresh Kapisetty
        RevisionType: Insertion
        Revision is applied to: Paragraph

As you can see row insertion revisions are grouped under one group with the first revision applied to the Row node.