如何使用多个表加载 powerpivot 数据模型?
How to load powerpivot data model with multiple tables?
我需要根据一些表创建一个 Excel 应用程序。
我运行 VBA 中的代码并且有效。在 "Visual Studio" 中它不起作用。
我的代码在这里:
Dim xlApp As Excel.Application
xlApp = Globals.ThisAddIn.Application
xlApp.ActiveWorkbook.Connections.Add2("Target Connection Name", "", _
"OLEDB;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Data Source=SERVER\SQLEXPRESS;Use Procedure for Prepare=1;Auto Translate=True;Packet
Size=8192;Workstation ID=NAME;Use Encryption for Data=False;Tag with column collation when possible=False;Initial Catalog=MYSQLDATABASE;", _
"""TAB_CATEGORIA"",""TAB_MOVIMENTO""", Excel.XlCmdType.xlCmdTableCollection, vbTrue, vbTrue)
当我执行这段代码时,我收到以下消息:
"The cartridge directory could not be found. Use the Windows Installer
to repair the application."
我意识到当我们生成一个新实例时,它起作用了:
Dim xlApp As NEW Excel.Application
但是,不幸的是,我需要当前实例
xlApp = Globals.ThisAddIn.Application
当我使用"Globals.ThisAddIn.Application"生成WorkbookConnection对象时,抛出异常。
More information,
- Office 2013 updated
- Visual Studio 2015 updated
**** 您可以在我的堆栈跟踪下方看到 *****
System.Runtime.InteropServices.COMException was unhandled by user code
ErrorCode=-2146827284
HelpLink=xlmain11.chm
HResult=-2146827284
Message=Não pudemos obter dados do Modelo de Dados. Veja a mensagem de erro que recebemos:
The cartridge directory could not be found. Use the Windows Installer to repair the application.
Source=Microsoft Excel
StackTrace:
em System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
em Microsoft.Office.Interop.Excel.Connections.Add2(String Name, String Description, Object ConnectionString, Object CommandText, Object lCmdtype, Object CreateModelConnection, Object ImportRelationships)
em ExcelAddIn2.Conectar.Button1_Click(Object sender, RibbonControlEventArgs e) na D:\work\projetos\SPHERA\OmieDecisionMaker\OmieDecisionMaker\ExcelAddIn2\Ribbon1.vb:linha 37
em Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ControlActionRaise(IRibbonControl control)
em Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ButtonClickCallback(RibbonComponentImpl component, Object[] args)
em Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.Invoke(RibbonComponentCallback callback, Object[] args)
em Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.System.Reflection.IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)
InnerException:
貌似不兼容,office 2016是单线程应用。它使 Add2 命令被阻止 Excel UI
谢谢!
我需要根据一些表创建一个 Excel 应用程序。
我运行 VBA 中的代码并且有效。在 "Visual Studio" 中它不起作用。
我的代码在这里:
Dim xlApp As Excel.Application
xlApp = Globals.ThisAddIn.Application
xlApp.ActiveWorkbook.Connections.Add2("Target Connection Name", "", _
"OLEDB;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Data Source=SERVER\SQLEXPRESS;Use Procedure for Prepare=1;Auto Translate=True;Packet
Size=8192;Workstation ID=NAME;Use Encryption for Data=False;Tag with column collation when possible=False;Initial Catalog=MYSQLDATABASE;", _
"""TAB_CATEGORIA"",""TAB_MOVIMENTO""", Excel.XlCmdType.xlCmdTableCollection, vbTrue, vbTrue)
当我执行这段代码时,我收到以下消息:
"The cartridge directory could not be found. Use the Windows Installer to repair the application."
我意识到当我们生成一个新实例时,它起作用了:
Dim xlApp As NEW Excel.Application
但是,不幸的是,我需要当前实例
xlApp = Globals.ThisAddIn.Application
当我使用"Globals.ThisAddIn.Application"生成WorkbookConnection对象时,抛出异常。
More information,
- Office 2013 updated
- Visual Studio 2015 updated
**** 您可以在我的堆栈跟踪下方看到 *****
System.Runtime.InteropServices.COMException was unhandled by user code
ErrorCode=-2146827284
HelpLink=xlmain11.chm
HResult=-2146827284
Message=Não pudemos obter dados do Modelo de Dados. Veja a mensagem de erro que recebemos:
The cartridge directory could not be found. Use the Windows Installer to repair the application.
Source=Microsoft Excel
StackTrace:
em System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
em Microsoft.Office.Interop.Excel.Connections.Add2(String Name, String Description, Object ConnectionString, Object CommandText, Object lCmdtype, Object CreateModelConnection, Object ImportRelationships)
em ExcelAddIn2.Conectar.Button1_Click(Object sender, RibbonControlEventArgs e) na D:\work\projetos\SPHERA\OmieDecisionMaker\OmieDecisionMaker\ExcelAddIn2\Ribbon1.vb:linha 37
em Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ControlActionRaise(IRibbonControl control)
em Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ButtonClickCallback(RibbonComponentImpl component, Object[] args)
em Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.Invoke(RibbonComponentCallback callback, Object[] args)
em Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.System.Reflection.IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)
InnerException:
貌似不兼容,office 2016是单线程应用。它使 Add2 命令被阻止 Excel UI
谢谢!