ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel Pivot Items Using C# - Unable to Access (https://www.excelbanter.com/excel-programming/436156-excel-pivot-items-using-c-unable-access.html)

james

Excel Pivot Items Using C# - Unable to Access
 
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 nto work, and PivotItems shows no values (as in
count):

IExcel.PivotItems pvtis = (IExcel.PivotItems)pvtf.PivotItems
(Missing.Value);
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;

james

Excel Pivot Items Using C# - Unable to Access
 

I should add I've been unable to find any information regarding this,
mostly unanswered questions.

On Nov 13, 10:31*am, james wrote:
I am working on aC#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 nto work, and PivotItems shows no values (as in
count):

IExcel.PivotItems pvtis = (IExcel.PivotItems)pvtf.PivotItems
(Missing.Value);
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;




All times are GMT +1. The time now is 06:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com