我正在使用Office.Interop v15运行我传递参数的.exe。它在使用Office 2013的Windows 7的开发机器上工作正常。当我移动到运行Windows XP和Office 2010的VM时,我得到一个运行时错误说明
System.Runtime.InteropServices.COMException(0x80020005):类型不匹配。 (HRESULT异常:0x80020005(DISP_E_TYPEMISMATCH))
是因为互操作v15不支持较低版本的办公室吗?
发生错误的片段
doc = app.Documents.Open(fileToPrint) /happens here
doc.PrintOut(False)
doc.Close()
app.Quit()
奇怪的是它运行但只是运行时错误。
答案 0 :(得分:1)
试试这个。
替换此代码:
doc = app.Documents.Open(fileToPrint) /happens here
用这个(在VB.NET中)
Dim s_missing As Object = System.Reflection.Missing.Value
doc = app.Documents.Open (fileToPrint, s_missing, s_missing, s_missing, s_missing,s_missing, s_missing, s_missing, s_missing, s_missing, s_missing, s_missing, s_missing, s_missing, s_missing, s_missing)
或者用这个(在C#中)
static object s_missing = System.Reflection.Missing.Value;
doc = app.Documents.Open ( ref fileToPrint,
ref s_missing,
ref s_missing,
ref s_missing,
ref s_missing,
ref s_missing,
ref s_missing,
ref s_missing,
ref s_missing,
ref s_missing,
ref s_missing,
ref s_missing,
ref s_missing,
ref s_missing,
ref s_missing,
ref s_missing );