Set Conditional Formatting on Pivot Table Field (dataField)

I need to set the format on a datafield in a pivot table .  I see examples on setting conditional formatting when you hard-code a range. I'm unable to find examples for a datafield nor find a way to get the range from an iPivotField.

It was easy in COM - get the range and set the formatting:

chRange = chPivotTable:DataFields("<data field name>"):dataRange

How would I do this using Sycfusion XlsIO?  All the examples I'm finding have a hard-coded range:

IConditionalFormats conditionalFormats = worksheet.Range["C7:C46"].ConditionalFormats;
IConditionalFormat conditionalFormat = conditionalFormats.AddCondition();

Thanks!


2 Replies

AR Anbazhagan Raja Syncfusion Team December 7, 2023 02:07 PM UTC

Hi Gerry,


As per Microsoft Excel location, there is no separate way to set the conditional formatting for pivot table. It should be set using cell range. However, it is not possible to get the pivot table field range using XlsIO. But, you can get the pivot table location. Based on this, you can set conditional formatting to the pivot table range.


pivot table location code snippet:

// Code for get the pivot table location

IRange pivotTableLocation = workbook.Worksheets["SheetName"].PivotTables[0].Location;


Regards,

Anbazhagan R.



GW Gerry Winning December 7, 2023 02:26 PM UTC

Thanks for the code snippet!  


Loader.
Up arrow icon