添加using System.Reflection; using Microsoft.Office.Interop.Word; 引用
在d盘下建立1.doc文档作为测试
string filepath = "D://1.doc"; Microsoft.Office.Interop.Word.Application oword = new Microsoft.Office.Interop.Word.Application(); // oword.Documents = new Microsoft.Office.Interop.Word.Document();
//oword.Documents= oword.Application.Documents.Open(filepath, ref Missing.Value , System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value); Object filename = filepath; Object ConfirmConversions = false; Object ReadOnly = false; Object AddToRecentFiles = false; Object PasswordDocument = System.Type.Missing; Object PasswordTemplate = System.Type.Missing; Object Revert = System.Type.Missing; Object WritePasswordDocument = System.Type.Missing; Object WritePasswordTemplate = System.Type.Missing; Object Format = System.Type.Missing; Object Encoding = System.Type.Missing; Object Visible = System.Type.Missing; Object OpenAndRepair = System.Type.Missing; Object DocumentDirection = System.Type.Missing; Object NoEncodingDialog = System.Type.Missing; Object XMLTransform=System.Type.Missing; oword.Documents.Open(ref filename, ref ConfirmConversions, ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate, ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format, ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection, ref NoEncodingDialog, ref XMLTransform); //wordDoc = wordApp.Documents.Open(ref filename, ref ConfirmConversions, //ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate, //ref Revert,ref WritePasswordDocument, ref WritePasswordTemplate, ref Format, //ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection, ref NoEncodingDialog); oword.Visible = true; 调试成功!
总结一下,如果调用用原来的excel的System.Reflection.Missing.Value默认缺省值就不行,调用word的时候必须使用System.Type.Missing默认缺省值。