我使用这段代码来比较两个word文档,使用的是office word interopt:
object missing = System.Reflection.Missing.Value;
object readonlyobj = false;
object filename = FirstDocx;
//Call assemblys dynamically
dynamic objEApp = Activator.CreateInstance(Type.GetTypeFromProgID("Word.Application"));
string strAssemblyOff2007 = "Microsoft.Office.Interop.Word, Version=" + objEApp.Version + ".0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c";
Assembly xslWordAssembly = Assembly.Load(strAssemblyOff2007); //Load Assembly
Type type = xslWordAssembly.GetTypes().Single(t => t.Name == "ApplicationClass");
dynamic app = Activator.CreateInstance(type);
//var docs = app.Documents;
//
//Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
var 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 = SecondDocx;
string nm = FirstDocx;
object filesavename = nm;
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);
第一和第二个Docx是我的文件。 在代码中,我动态加载程序集,但当我想打开第一个docx时,在 var doc = app.Documents.Open(这里,我遇到了以下错误:
Could not convert argument 0 for call to Open.
我该怎么解决它?
FirstDocx
不包含有效的路径/文件名。没有看到FirstDocx
和SecondDocx
的值,很难确定。 - Kevin