PC Review


Reply
Thread Tools Rate Thread

Creating an Excel Pivot Table using COM in C# producing 0x800A03EC

 
 
MattW
Guest
Posts: n/a
 
      30th Apr 2009
I am attempting to create an excel pivot table programatically using the
Excel 12.0 Library. The code I am using is below and I have marked the point
where the error occurs with *******

this.excelApp = new Excel.ApplicationClass();
Excel.Workbook wb = this.excelApp.Workbooks.Add(missing);

Excel.PivotCache pivotCache =
this.excelApp.ActiveWorkbook.PivotCaches().Add(Excel.XlPivotTableSourceType.xlExternal, missing);
pivotCache.Connection = this.txtConnStr.Text;
pivotCache.MaintainConnection = true;
pivotCache.CommandText = this.txtQuery.Text;
pivotCache.CommandType = Excel.XlCmdType.xlCmdSql;

Excel.Worksheet sheet = (Excel.Worksheet)this.excelApp.ActiveSheet;
Excel.PivotTables pivotTables = (Excel.PivotTables)sheet.PivotTables(missing);

******* ERROR HAPPENS ON NEXT LINE
Excel.PivotTable pivotTable = pivotTables.Add(pivotCache,
this.excelApp.ActiveCell, missing, missing, missing);

pivotTable.SmallGrid = false;
pivotTable.ShowTableStyleRowStripes = true;
pivotTable.TableStyle2 = "PivotStyleLight1";

Excel.PivotField pageField =
(Excel.PivotField)pivotTable.PivotFields("Control");
pageField.Orientation = Excel.XlPivotFieldOrientation.xlPageField;


It appears that the problem may have to do with the second parameter which
as I understand is the location on the sheet to put the pivot table. I have
tried all variations of the Range object I could think of. Examples of this
I've seen online used Application.ActiveCell which is what I'm using above,
but I always get the same error. The only thing I've been able to find online
references making sure Excel security is set to allow VBA code to run, which
my excel version is. Please help!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003 Pivot table: creating Fields from Consolidated muti ran Javier Johnson Microsoft Excel Programming 0 8th Apr 2009 04:08 PM
Excel 2003 hangs on save after creating pivot table Ed Klein Microsoft Excel Programming 0 11th Jan 2008 08:54 PM
Creating key in datatable to not overload excel pivot table =?Utf-8?B?ZGVudG9u?= Microsoft Access 1 19th Apr 2007 03:20 AM
Creating pivot table with multiple ranges in excel =?Utf-8?B?UGhpbCBQb2xpY2VsbGk=?= Microsoft Excel Worksheet Functions 2 19th Sep 2004 05:07 PM
Excel hangs when creating pivot table =?Utf-8?B?Um9nZXIgTnll?= Microsoft Excel Misc 0 1st Aug 2004 03:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:45 PM.