Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以Odata为源在excel工作簿中以编程方式创建数据透视表_C#_Excel_Pivot - Fatal编程技术网

C# 以Odata为源在excel工作簿中以编程方式创建数据透视表

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

我正在尝试使用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=" + "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`