Please check the following piece of code that reads a spreadsheet and sets the conditional formatting on cell range A1:A10, ranking the top 5 in red color. Also attached are the input & output spreadsheets for your reference.
C#
var workbook = new Workbook(“D:/sample.xlsx”);
var sheet = workbook.Worksheets[0];
//Adds an empty conditional formatting int index = sheet.ConditionalFormattings.Add();
FormatConditionCollection fcs = sheet.ConditionalFormattings[index];
//Sets the conditional format range.
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 9;
ca.StartColumn = 0;
ca.EndColumn = 0;
fcs.AddArea(ca);
//Adds condition. int conditionIndex = fcs.AddCondition(FormatConditionType.Top10); FormatCondition fc = fcs[conditionIndex]; //Sets Rank value.
fc.Top10.Rank = 5; //Sets the background color.
fc.Style.BackgroundColor = Color.Red;
//Saving the Excel file
workbook.Save(“D:/output.xlsx”);
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.