Ravi@asp.net


Hi All,

I have to compare the text of two word documents using C#. These word documents contain images and text also. But I just wanted to compare the text.

Can anybody please let me know how to do this

Thanks,

Ravi Mullick




Re: Compare Word Documents c#

vtortola


I think that you must use Visual Studio Tools for Office.

Regards.






Re: Compare Word Documents c#

bi-lya

See this (for VB.NET) http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=2128816&SiteID=1 and references in it






Re: Compare Word Documents c#

Ravi Medium

Hi friend

Thanks for ur reply.I just want to compare the text of two word documents and create a new document in

which i know the difference in red color along with the data.

Thanks & regards





Re: Compare Word Documents c#

bi-lya

See the simplest example. For VBA

Code Snippet

For a = 1 To Documents("doc1.doc").Words.Count


Documents("doc1.doc").Words(a).Copy
Documents("doc3.doc").Words(a).Paste

If Documents("doc1.doc").Words(a).Text <> Chr(13) _
And Documents("doc1.doc").Words(a).Text <> Chr(1) Then
If Documents("doc1.doc").Words(a).Text <> Documents("doc2.doc").Words(a).Text Then _
Documents("doc3.doc").Words(a).Font.Color = wdColorRed
End If


Next





Re: Compare Word Documents c#

Ravi@asp.net

object missing = System.Reflection.Missing.Value;

//create a readonly variable of object type and assign it to false.

object readonlyobj = false;

object filename = txtfile1.Text;

//create a word application object for processing the word file.

Word.Application app = new Word.ApplicationClass();

//create a word document object and open the above file..

Word.Document doc = app.Documents.Open(

ref filename, ref missing, ref readonlyobj, ref missing, ref missing,

ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

string filenm = txtfile2.Text;

string nm = txtpath.Text + @"\" + getfilename(txtfile1.Text);

object filesavename = nm;

doc.SaveAs(ref filesavename, ref missing, ref missing, ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing, ref missing, ref missing);

doc.TrackRevisions = true;

doc.ShowRevisions = true;

doc.PrintRevisions = true;

doc.Compare(filenm);

doc.Close(ref missing, ref missing, ref missing);

app.Quit(ref missing, ref missing, ref missing);

MessageBox.Show("Process complete");