Hi Aspose Team,
We have a requirement in Word Document where we need to Extract Before Text and After Text from Track Changes.
Example :
-
A word(eg: “Tiger”) Is Deleted in a word document.I should be able to build response as .
Before Text : “Tiger”
After Text: “”
Operation : “Delete”
-
A word(eg: “Tiger”) Is updated to new Word(eg: Cub) in a word document.I should be able to build response as .
Before Text : “Tiger”
After Text: “Cub”
Operation : “Update”
- A word(eg: “Cub”) Is Inserted in a word document.I should be able to build response as .
Before Text : “”
After Text: “Cub”
Operation : “Insert”
Second Point is little tricky as in revisions/Revision Groups we have only inserrt,delete,move,format change but not update.
Can you please help me with a possibility to achieve this.
Thanks & Regards,
Kamal
@tejkamalleo We can offer the following code.
bool skipNext = false;
for (int i = doc.Revisions.Count - 1; i != -1; i-- )
{
if (skipNext)
{
skipNext = false;
continue;
}
Revision curRevision = doc.Revisions[i];
string curText = (curRevision.ParentNode as Run).Text;
if (i > 0)
{
Revision prevRevision = doc.Revisions[i - 1];
string prevText = (prevRevision.ParentNode as Run).Text;
if (curRevision.RevisionType == RevisionType.Insertion &&
prevRevision.RevisionType == RevisionType.Deletion &&
(curRevision.ParentNode.PreviousSibling == prevRevision.ParentNode))
{
Console.WriteLine("Before: {0}; After: {1}; Operation: {2}", prevText, curText, "Edit");
skipNext = true;
}
}
if (!skipNext)
switch (curRevision.RevisionType)
{
case RevisionType.Insertion:
Console.WriteLine("Before: __; After: {0}; Operation: Insert", curText);
break;
case RevisionType.Deletion:
Console.WriteLine("Before: {0}; After: __; Operation: Delete", curText);
break;
}
}
Please note, the code is very naive, does not contain all the necessary checks, and it serves only for demonstrating the idea.
The point is that we shall look for a pair of Delete-Insert revisions where the adjacent runs are involved.