We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Set a pivot filter to a pre-selected value

Hello

I have the following question regarding the use of Aspose cell:

(i) How do you set a pivot table's filter to a pre-selected value?

(ii)Pivot tables are drawn with auto-generated headings such as "Row Labels" and "Column Labels". How do you change these labels to something more suitable?

Thanks

Hi,


Thanks for your query.

i) See the following code segments for your reference:
e.g
Sample code:

1)
PivotField pageField = pivotTable.PageFields[0];
int pageItemCount = pageField.PivotItems.Count;
for (int i = 0; i < pageItemCount; i++)
{
//Select “Feb 16”
if (“Feb 16”.Equals(pageField.PivotItems[i].Value))
{
pageField.CurrentPageItem = (short)i;
}
}

2)
PivotField pageField = pivotTable.PageFields[0];
pageField.IsMultipleItemSelectionAllowed = true;

int pageItemCount = pageField.PivotItems.Count;

//Select all except Vinod and Gopal
for (int i = 0; i < pageItemCount; i++)
{
PivotItem item = pageField.PivotItems[i];

if (item.Name.Contains(“Vinod”) == true)
{
item.IsHidden = true;
}

if (item.Name.Contains(“Gopal”) == true)
{
item.IsHidden = true;
}

}

ii) You may try to use PivotTable.RowHeaderCaption and PivotTable.ColumnHeaderCaption attributes.

Hope, this helps a bit.

Thank you.
Hi Sahi
One more thing. How do you collapse all items in a pivot? I found the following thread but it was for Java and not .NET:
https://forum.aspose.com/t/111770

I need a solution urgently please!

Thanks

Hi,


Well, you may try to use PivotField.HideDetail() method, see the sample line of code for your reference:
e.g
Sample code:

pivotTable.RowFields[0].HideDetail(true);

Hope, this helps a bit.

Thank you.