如何比较C#中的2个word文档与未安装Ms office版本的文档

如何比较C#中的2个word文档与未安装Ms office版本的文档,c#,asp.net,C#,Asp.net,我想在c#中并排比较两个word文档,并在word文档(.doc或.docx)中获得不同的文本或句子作为报告,报告可以并排突出显示差异,我使用以下代码 Application wordApp = new Application(); wordApp.Visible = true; object wordTrue = (object)true; object wordFalse = (object)false; object

我想在c#中并排比较两个word文档,并在word文档(.doc或.docx)中获得不同的文本或句子作为报告,报告可以并排突出显示差异,我使用以下代码

Application wordApp = new Application();

        wordApp.Visible = true;

        object wordTrue = (object)true;

        object wordFalse = (object)false;

        object fileToOpen = @"D:\MyWorks\test1.doc";

        object missing = Type.Missing;

        Document doc1 = wordApp.Documents.Open(ref fileToOpen,

               ref missing, ref wordFalse, ref wordFalse, ref missing,

               ref missing, ref missing, ref missing, ref missing,

               ref missing, ref missing, ref wordTrue, ref missing,

               ref missing, ref missing, ref missing);



        object fileToOpen1 = @"D:\MyWorks\test2.doc";

        Document doc2 = wordApp.Documents.Open(ref fileToOpen1,

               ref missing, ref wordFalse, ref wordFalse, ref missing,

               ref missing, ref missing, ref missing, ref missing,

               ref missing, ref missing, ref missing, ref missing,

               ref missing, ref missing, ref missing);



        Document doc = wordApp.CompareDocuments(doc1, doc2, WdCompareDestination.wdCompareDestinationNew, WdGranularity.wdGranularityWordLevel,

            true, true, true, true, true, true, true, true, true, true, "", true);
上面的代码给出了以下错误

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
请在这方面帮助我,我想在不包含ms office安装版本的系统中运行此程序。请提供一些Gudiline

谢谢


Sree

如果未安装Office,则无法使用Microsoft Office Interop-这完全是不可能的。 此外:您处于服务器环境中,Microsoft不建议您运行Office,因为存在许多线程问题,有时Office的messagebox会挂起您的线程

你有两个选择: -使用OfficeOpenXMLSDK来比较文档,但这是一项大量的工作,因为它与互操作非常不同。 有一本免费的书“OpenXMLExplained”,可以帮助您入门。 -使用包含Office Open XMl SDK的库-我从未将这些库用于word,因此我无法给您提供建议