2017-05-09 4 views
0

일부 테이블을 기반으로 Excel 응용 프로그램을 만들어야합니다.다중 테이블로 Powerpivot 데이터 모델을로드하는 방법은 무엇입니까?

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 설치 를 사용하여 신청." 내가 "전역을 사용하는 경우 불행하게도, 내가에게 현재 인스턴스

xlApp = Globals.ThisAddIn.Application 

필요 ,

Dim xlApp As NEW Excel.Application 

을하지만 :

나는 우리가 새로운 인스턴스를 생성 할 때, 작동하는지 깨달았다. ThisAddIn.Application "WorkbookConnection 개체를 생성 할 때 예외가 throw됩니다.

더 자세한 정보 2013

  • 사무실

는 **** 당신은 내 스택 추적을 아래에 볼 수있는 업데이트 업데이트

  • 비주얼 스튜디오 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: 
    
  • 답변