方法“Microsoft.Office.Interop.Word._Document.Close(ref object, ref object, ref object)”和非方法“Microsoft.Office.Interop.Word.DocumentEvents2_Event.Close”之间存在二义性。

方法一:修改创建对象

Word.Application app = new Word.Application();//可以打开word
Word.Document doc = null; //需要记录打开的word

改为:加下划线

Word._Application app = new Word.Application();//可以打开word
Word._Document doc = null; //需要记录打开的word

Word._Application 操作对应的word文件的应用程序。 Word._Document 操作对应的word文件文档。

oDoc = oWord.Documents.Open(ref oFileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing,ef oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,ef oMissing, ref oMissing, ref oMissing, ref oMissing);
//打开FileName对应的word文档,并将文档句柄指定给oDoc,
后面的ref oMissing一样的参数,因为所有的参数正常情况下都不需要设置,所以都是Missing

 方法二:使用显式转换:

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

改为:((Word._Document)doc).Close(ref missing, ref missing, ref missing);

猜你喜欢

转载自www.cnblogs.com/net5x/p/12346337.html