1

Am opening a word document in track change mode using Interop method. once revision is done i have to get only revised content from the document. likely old phrase: an new phrase: a and so on. Is there anyway to get it through C#.

EDIT:

I got the solution for the previous issue by using the code specified by KDT. Now the new issue is, i also have to get the style and format changes from the revised document likely bold, underline, numbering and bullets.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Suressh
  • 15
  • 7

1 Answers1

2

This might be a start for you Suresh:

using Word = Microsoft.Office.Interop.Word;

//...

foreach (Word.Section s in final.Sections)
{
    foreach (Word.Revision r in s.Range.Revisions)
    {
             counter += r.Range.Words.Count;
             if (r.Type == Word.WdRevisionType.wdRevisionDelete) // Deleted
                delcnt += r.Range.Words.Count;
             if (r.Type == Word.WdRevisionType.wdRevisionInsert) // Inserted
                inscnt += r.Range.Words.Count;
             if (r.Type == Word.WdRevisionType.wdRevisionProperty) // Formatting (bold,italics)
                inscnt += r.Range.Words.Count;
    }
}

See this link:

How to iterate and count Revisions in a Word document using C#?

I haven't tried this but apparently the code works. This guy just had an issue saving the file as text thereafter which is also confusing.

Community
  • 1
  • 1
KDT
  • 671
  • 1
  • 6
  • 15
  • thanks for your reply. Word refers to an Word.Application or Word.Document bcoz .section property is not available for Application. In first loop if use Word application it is showing missing directive or assembly reference. But i already add reference to interop namespace in the file. – Suressh Oct 16 '13 at 09:59
  • You need to reference the interop library first by right clicking references, .NET tab and looking for MS.Office.Interop.Word I think. After that you specify "Word" (in this case) as the reference to the assembly i.e. using Word = Microsoft.Office.Interop.Word; "final" in this case is the MS Word document that was created earlier and what you need to use. – KDT Oct 17 '13 at 12:21
  • So in other words you need to do something like : var wdApp = new Word.Application(); var docs = wdApp.Documents; var doc = docs.Open(/*your path*/); After this the above code should work although it's from a different link and I haven't tried it. Just note in my example, doc represents final. It makes sense though. Hope it helps! – KDT Oct 17 '13 at 12:30
  • Hi KDT any idea about how to solve the new issue. Thanks for your previous help. – Suressh Oct 25 '13 at 08:02
  • I've updated the answer to include a check for formatting @Suressh (bold, underline, italics). You should check out all the options available under the revision type (Word.WdRevisionType.X) to include everything you want to. Cheers! – KDT Oct 28 '13 at 07:43