This project has moved and is read-only. For the latest updates, please go here.

Excel PivotItems and C#

Topics: Resolved
Nov 16, 2009 at 1:47 PM

I am working on a C# add-in that modifies pivot tables.  I have done
this work in VBA, and the object model seems straightforward, e.g.,
PivotTable-PivotFields-PivotItems, but I can not get the object for
PivotItems, or iterate through the items. Do I need something other
than PivotItems?

Code for PivotFields, that works:

IExcel.PivotFields pvtfs = (IExcel.PivotFields)pvtTable.get_PageFields(Missing.Value); 
foreach (IExcel.PivotField pvtf in pvtfs) 

Code for the does not work, and PivotItems shows no values (as in count):

IExcel.PivotItems pvtis =
foreach (IExcel.PivotItem pvti in pvtis) 


Similarly, even though I can iterate the CubeFields, I can not edit
some parameters, although I can retrieve its value, e.g., trying to
modify EnablemultiplePageitems throws an error:

IExcel.CubeFields cbfs = (IExcel.CubeFields)pvtTable.CubeFields;
foreach (IExcel.CubeField cbf in cbfs)

     string cbfname = cbf.Name; 
     bool cbfMultiPage = cbf.EnableMultiplePageItems;

     if (cbfname == dimensionName & cbfMultiPage == false) 

          cbf.EnableMultiplePageItems = true;


Nov 17, 2009 at 4:04 PM

i downloaded the solution, and I can see some differences, in how the objects are referenced, that might provide me a solution.