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:
Cheers
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