C# 以Odata为源在excel工作簿中以编程方式创建数据透视表
我正在尝试使用C#在excel工作簿中创建数据透视表。源是Odata提要URL。 我编写了以下代码:C# 以Odata为源在excel工作簿中以编程方式创建数据透视表,c#,excel,pivot,C#,Excel,Pivot,我正在尝试使用C#在excel工作簿中创建数据透视表。源是Odata提要URL。 我编写了以下代码: string connectionString = @"DATAFEED;Data Source=" + odataURL + ";Namespaces to Include=*;Max Received Message Size=4398046511104;Integrated Security=Basic;User ID=" + "xyz" + ";Password=" + "bvb
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`