VSTO Excel Interop ListObject.AddEx(2010+)到ListObject.Add(2003)转换

作为我正在开发的Excel帮助程序实用程序的一部分,我正在将大型常用Excel电子表格移至MS SQL,以进一步确保性能以及通过SSIS包的数据validation。

作为这个的一部分,我写了一个基本的数据库连接类,模仿数据 – >从其他来源 – >从SQL Serverbutton。 我在家中使用Office 2013的副本在家里工作,我预料到一些转换问题,主要是在Excel Interop API发生变化,升级到Office 2010或更高版本的情况下不可选。 我的主要问题似乎是转换新的命令AddEx:

MyListObjects.AddEx(ExcelAPI.XlListObjectSourceType.xlSrcQuery, MyConnection, Type.Missing, ExcelAPI.XlYesNoGuess.xlYes,StartRange);

到2003/2007年版本添加按照MSDN( https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.listobjects.add ( v=office.11 ) .aspx )

// 2007年命令

  ExcelAPI.ListObject CurrentTable = MyListObjects.Add(ExcelAPI.XlListObjectSourceType.xlSrcExternal, MyConnection,Type.Missing,ExcelAPI.XlYesNoGuess.xlYes,StartRange); 

我得到的例外是:

 An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code Additional information: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) 

我最初的想法是在ExcelAPI.XlYesNoGuess枚举的变化,所以我尝试手动值,但我然后遇到编译器错误。 我已经尝试一次删除参数使用Type.Missing跟踪罪魁祸首但是这似乎已经造成了更多的错误比它解决尽pipeMSDN陈述这些都是可选的。

连接string如下所示:

 String FullString = "OLEDB;Provider=SQLOLEDB.1;Data Source= " + PCNameOrIP + @"\" + InstanceName + @";Initial Catalog=" + DatabaseName + @";User ID=" + DatabaseUserName + @";Password=" + DatabasePassword; 

方法testing调用参数:

 Globals.ThisAddIn.DM.EstablishConnection("BREWL14H58107", "SQLEXPRESS", "TestDB", "sa", "Password0", "SELECT * FROM TestDB.dbo.Test", "Demo File", "Testing"); 

已经完成了这一些更多。 看来我的代码工作正常,从家里修改后的添加。 但是从工作中我仍然得到:

 An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code. Additional information: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))