导入代码,原句是:
1.workBooks.Open(strFileName, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1); 2. wbs = excel1.Workbooks.Open(FileName, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing);
修改成以下:
workBooks.Open(strFileName, 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);就不会再报XML什么错误的提示框了(也就是把1或者Nothing改为Type.Missing)
Type.Missing:
表示 Type 信息中的缺少值。使用 Missing 字段通过反射进行调用,以获取参数的默认值。如果传入一个参数值的 Missing 字段,并且该参数没有默认值,则引发 ArgumentException。一般在ComInterop使用比较多。如果接触过VSTO,就会发现有很多地方要用到Type.Missing字段。许多C++写的com组件API参数列表中有很多默认值,而C#是没有参数默认值的。使用这个字段可以直接使用API参数的默认值。