我尝试打开一个名为" Borecheck.docx"的Word文档。但是,当我启动我的程序并收到错误消息时:方法没有重载"打开"需要" 1"参数(CA1501) 有人能帮助我吗?
这是我的源代码:
using System.IO;
using System.Runtime.InteropServices;
using Word = Microsoft.Office.Interop.Word;
{
public partial class MainForm
{
void BoreCheckToolStripMenuItemClick(object sender, EventArgs e)
{
object wordObject = null;
try
{
wordObject = Marshal.GetActiveObject("Word.Application");
}
catch {}
Word.Application word = null;
bool wordInstanceCreated = false;
if (wordObject != null)
{
word = (Word.Application)wordObject;
}
else
{
wordInstanceCreated = true;
word = new Word.Application();
}
word.Visible = true;
string fileName = Path.Combine(Application.StartupPath, "Borecheck.docx");
word.Documents.Open(ref fileName);
}
}
答案 0 :(得分:2)
好吧,Documents.Open需要多个参数:
Document Open(
ref Object FileName,
ref Object ConfirmConversions,
ref Object ReadOnly,
ref Object AddToRecentFiles,
ref Object PasswordDocument,
ref Object PasswordTemplate,
ref Object Revert,
ref Object WritePasswordDocument,
ref Object WritePasswordTemplate,
ref Object Format,
ref Object Encoding,
ref Object Visible,
ref Object OpenAndRepair,
ref Object DocumentDirection,
ref Object NoEncodingDialog,
ref Object XMLTransform
)
答案 1 :(得分:2)
信息很清楚。你没有传递正确数量的参数。来自Interop.Word Documents.Open is null:
object oMissing = System.Reflection.Missing.Value;
Document doc = word.Documents.Open(filename, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);