错误没有重载方法,用于添加'需要' 0'参数,使用Word Interop

时间:2014-05-19 13:11:33

标签: c# office-interop

这是我的代码。

private void button1_Click(object sender, EventArgs e)
{
    {
        // first we are creating application of word.
        Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
        // now creating new document.
        WordApp.Documents.Add();
        // see word file behind your program
        WordApp.Visible = true;
        // get the reference of active document
        Microsoft.Office.Interop.Word.Document doc = WordApp.ActiveDocument;
        // set openfiledialog to select multiple image files
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Filter = "Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF";
        ofd.Title = "Select Image To Insert....";
        ofd.Multiselect = true;
        // if user select OK, then process for adding images
        if (ofd.ShowDialog() == DialogResult.OK)
        {
            // iterating process for adding all images which is selected by filedialog
            foreach (string filename in ofd.FileNames)
            {
                // now add the picture in active document reference
                doc.InlineShapes.AddPicture(filename, Type.Missing, Type.Missing, Type.Missing);
            }
        }
        // file is saved.
        doc.SaveAs("c:\\hello.doc", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
        // application is now quit.
        WordApp.Quit(Type.Missing, Type.Missing, Type.Missing);
    }

}

我在WordApp.Documents.Add();

面临下面提到的错误
  

错误:Add的无过载方法接受0参数

你能帮我解决一下这个错误吗?

我不熟悉编码。

2 个答案:

答案 0 :(得分:2)

我认为这是版本问题,您在其他方法中将Type.Missing传递给可选参数。然后您应将Type.Missing传递给Add的参数方法也是如此。

WordApp.Documents.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);

答案 1 :(得分:0)

object objTest = new object();
objTest = Type.Missing;
WordApp.Documents.Add(ref objTest, ref objTest, ref objTest, ref objTest);