首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打开单词文档

打开单词文档
EN

Stack Overflow用户
提问于 2015-02-18 12:40:46
回答 2查看 1.5K关注 0票数 0

我试图打开一个名为"Borecheck.docx“的Word文档!但是当我启动我的程序并得到错误消息时:没有重载的方法"Open“需要"1”参数(CA1501),有人能帮我吗?

这是我的源代码:

代码语言:javascript
复制
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);
    }   

}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-02-18 12:43:28

信息很清楚。你不能传递正确数量的参数。来自Interop.Word Documents.Open为空

代码语言:javascript
复制
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);
票数 2
EN

Stack Overflow用户

发布于 2015-02-18 12:43:02

好的,Documents.Open接受多个参数:

代码语言:javascript
复制
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
)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28583956

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档