简体   繁体   中英

Does EPPlus support ConditionalFormatting for Pivot tables?

I am using EPPlus to create a pivot table and now i am trying to use ConditionalFormatting on the pivot table and it simply doesn't seem to work. I have taken the example from here: https://github.com/EPPlusSoftware/EPPlus/wiki/Three-color-scale-example and trying to apply it on the cells of the pivot table

     var rng = worksheet.Cells["N3:Y88"];  //(this is the output of the pivot table)

     var cfRule = rng.Worksheet.ConditionalFormatting.AddThreeColorScale(rng);
     cfRule.LowValue.Color = ColorTranslator.FromHtml("#FF63BE7B");
     cfRule.MiddleValue.Color = ColorTranslator.FromHtml("#FFFFEB84");
     cfRule.MiddleValue.Type = eExcelConditionalFormattingValueObjectType.Percentile;
     cfRule.MiddleValue.Value = 50;
     cfRule.HighValue.Color = ColorTranslator.FromHtml("#FFF8696B");

and there is no impact. I use the same code on a set of regular cells and it works fine. Does EPPlus support the ability to conditionalformat a pivot table?

Found the answer here: https://github.com/JanKallman/EPPlus/issues/399

public static void AddConditionalFormattingToPivotTable(ExcelPivotTable pivotTable)
{
var worksheetXml = pivotTable.WorkSheet.WorksheetXml;
var element = worksheetXml.GetElementsByTagName("conditionalFormatting")[0];
((XmlElement)element).SetAttribute("pivot", "1");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM