2

I have made an excel sheet programmatically. and now I want to add conditional formatting on a specific cell range.

The formatting type is all the cells with values greater than 0 (>0)

How to go about doing it? In excel I can do it using an inbuilt formula of Cell Values Greater Than. But how to embed it in excel using C# and epplus?

Dirk
  • 10,668
  • 2
  • 35
  • 49
Parv Sharma
  • 12,581
  • 4
  • 48
  • 80

1 Answers1

9

i coudnt find an exact solution to this problem. so adding my own solution that works

var cellAddress = new ExcelAddress(
                        <startingRow>, 
                        <startingcolumn>, 
                        <endingRow>, 
                        <endingColumn>);

var cf = ws.ConditionalFormatting.AddGreaterThan(cellAddress);
cf.Formula = "0";
cf.Style.Fill.BackgroundColor.Color = Color.LightGreen;
Parv Sharma
  • 12,581
  • 4
  • 48
  • 80
  • This didn't work for me. I used: Formula = "ISBLANK("") // eg ISBLANK(C2) – Jerry May 30 '14 at 21:44
  • 2
    you will also have to change the type of formulla in the line ws.ConditionalFormatting – Parv Sharma May 31 '14 at 00:29
  • Can't edit my comment for some reason... Yes I missed that part of your answer. I was using ConditionalFormatting.AddExpression(cellAddress) with the ISBLANK formula. – Jerry Jun 02 '14 at 12:25