5

我正在尝试使用 C# 在 excel 工作簿中创建数据透视表。来源是 Odata Feed URL。我写了以下代码:

    string connectionString = @"DATAFEED;Data Source=" + odataURL + ";Namespaces to Include=*;Max Received Message Size=4398046511104;Integrated Security=Basic;User ID=" + "xyz" + ";Password=" + "bvby" + ";Persist Security Info=true;Base Url=" + odataURL;
    Excel.PivotCache pivotCache = app.ActiveWorkbook.PivotCaches().Add(Excel.XlPivotTableSourceType.xlExternal, Type.Missing);
    pivotCache.Connection = connectionString;

当我这样做时,它会引发以下异常pivotCache.Connection

System.Runtime.InteropServices.COMException was caught
HResult=-2146827284
Message=Exception from HRESULT: 0x800A03EC
Source=""
ErrorCode=-2146827284

堆栈跟踪:

at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Microsoft.Office.Interop.Excel.PivotCache.set_Connection(Object value)
at ConsoleApplication2.Program.createWorkBookHelper(Application app, Workbook workbook, String odataURL, String nameOfWorkBook) 
in d:\ReportingApp\Dev\PDS\Excel Plugin\ConsoleApplication2\ConsoleApplication2\Program.cs:line 36`
4

0 回答 0