簡體   English   中英

如何使用多個表加載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)

執行此代碼時,收到以下消息:

“找不到盒帶目錄。使用Windows Installer修復應用程序。”

我意識到,當我們生成一個新實例時,它可以工作:

Dim xlApp As NEW Excel.Application 

但是,不幸的是,我需要當前實例

xlApp = Globals.ThisAddIn.Application

當我使用“ Globals.ThisAddIn.Application”生成WorkbookConnection對象時,將引發異常。

更多信息,

  • Office 2013更新
  • Visual Studio 2015更新

****您可以在我的堆棧跟蹤下面看到*****

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中被阻止

您可以在此處看到完整的答案: https : //social.msdn.microsoft.com/Forums/en-US/ddf2ab36-14a5-431c-b465-114aee6eb5d6/how-to-load-powerpivot-data-model-with-多表,VSTO-Excel的應用程序?論壇= VSTO

謝謝!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM