-
Notifications
You must be signed in to change notification settings - Fork 295
Conditional Formatting Specific Text Formulas
OssianEPPlus edited this page Aug 28, 2025
·
2 revisions
Specific Text Conditional Formattings now has the .Formula property instead of just .Text
Specific Text refers to the following Conditional Formatting types:
- BeginsWith
- EndsWith
- ContainsText
- NotContainsText
This feature represents the ability to enter a formula into the field with the IF formula in this image:
With this feature we can re-create this excel Conditional Formatting in epplus with this code:
using (var pck = new ExcelPackage())
{
var ws = pck.Workbook.Worksheets.Add("Sheet1");
ws.Cells["A1"].Value = 6;
for(int i = 1; i <= 8; i++)
{
ws.Cells[i, 2].Value = i % 2 == 0 ? "Small" : "Large";
}
var cf = ws.ConditionalFormatting.AddContainsText(new ExcelAddress("B1:B8"));
cf.Formula = "IF($A$1 > 5, \"Large\", \"Small\")";
cf.Style.Fill.PatternType = ExcelFillStyle.Solid;
cf.Style.Fill.BackgroundColor.Theme = eThemeSchemeColor.Accent2;
pck.SaveAs("C:\\temp\\TextFormula.xlsx");
}
EPPlus Software AB - https://epplussoftware.com
- What is new in EPPlus 5+
- Breaking Changes in EPPlus 5
- Breaking Changes in EPPlus 6
- Breaking Changes in EPPlus 7
- Breaking Changes in EPPlus 8
- Addressing a worksheet
- Dimension/Used range
- Copying ranges/sheets
- Insert/Delete
- Filling ranges
- Sorting ranges
- Taking and skipping columns/rows
- Data validation
- Comments
- Freeze and Split Panes
- Header and Footer
- Hyperlinks
- Autofit columns
- Grouping and Ungrouping Rows and Columns
- Formatting and styling
- The ExcelRange.Text property
- Conditional formatting
- Using Themes
- Working with custom named table- or slicer- styles