Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

Created Unassigned: Conditional Formatting not applying to Pivot Table [9394]

$
0
0
I'm creating a pivot table in ClosedXML, then trying to apply conditional formatting to it. When I open the sheet however, the conditional format applies to everywhere but the pivot table; see attached.

My code for setting up the pivot table, and applying a conditional format are as follows:

```
var pWorksheet = workbook.Worksheets.Add(_service.ResolveWorksheetTabName("ptable"));
var pt = pWorksheet.PivotTables.AddNew("PivotTEST", pWorksheet.Cell(2, 1), table);
pt.RowLabels.Add("SurveySectionElementTypeCode");
pt.ColumnLabels.Add("SurveySectionName");
pt.Values.Add(section.FieldName);
pt.SetShowGrandTotalsRows(false);
pt.SetShowGrandTotalsColumns(false);

pWorksheet.Row(3).Style.Alignment.TextRotation = 90;
pWorksheet.Row(2).Hide();
pt.SetPreserveCellFormatting(true);


pWorksheet.Range(1, 1, worksheet.LastRowUsed().RowNumber(), worksheet.LastColumnUsed().ColumnNumber())
.AddConditionalFormat().WhenEquals(1)
.Fill.SetBackgroundColor(XLColor.FromHtml(section.ConditionParameters["Priority-1"]));


```

The pivot table itself works fine, any idea why the conditional format isn't getting applied? (The text rotation of the header isn't working either).

Cheers

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>