Compare the consistency between the two Word files. C # Solution

Source: Internet
Author: User
Using system; using system. windows. forms; using system. diagnostics; using Microsoft. office. interOP. word; namespace windowsformsapplication1 {public partial class form1: FORM {public form1 () {initializecomponent ();} private void button1_click (Object sender, eventargs E) {// determine whether the system contains word before loading. EXE process. If it contains, killprocess (); MessageBox. show (comparewordfile (@ "C: \ 1.doc", @" C: \ 2.doc "). tostring () );} Public bool comparewordfile (string source, string target) {object filename = source; var targetfilename = target; object missing = system. reflection. missing. value; object readonlyobj = false; var APP = new applicationclass {visible = false}; var Doc = app. documents. open (ref filename, ref missing, ref readonlyobj, ref missing, ref missing, Ref missing, ref missing, ref missing); Doc. trackrevisions = true; Doc. showrevisions = true; Doc. printrevisions = true; object comparetarget = wdcomparetarget. wdcomparetargetnew; Doc. compare (targetfilename, ref missing, ref comparetarget, ref missing); var changecount = app. activedocument. revisions. count; object savechanges = wdsaveoptions. wddon Otsavechanges; Doc. close (ref savechanges, ref missing, ref missing); app. quit (ref savechanges, ref missing, ref missing); Return changecount = 0;} public void killprocess () {const string processname = "winword"; var process = process. getprocessesbyname (processname); try {foreach (var p in process) {P. kill () ;}} catch (exception) {MessageBox. show ("Disable winword in the system first. EXE process! "," File comparison failed ", messageboxbuttons. OK); Return ;}}}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.