Add'需要& # 39;0 & # 39;参数,使用Word互操作
本文关键字:使用 Word 互操作 参数 Add 需要 | 更新日期: 2023-09-27 18:03:57
这是我的代码。
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个参数
你能帮我解决这个错误吗?
我是新手。
我认为这是一个版本问题,您将Type.Missing
传递给其他方法中的可选参数。然后将Type.Missing
也传递给Add
方法的参数。
WordApp.Documents.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
object objTest = new object();
objTest = Type.Missing;
WordApp.Documents.Add(ref objTest, ref objTest, ref objTest, ref objTest);