Conditional Formatting by Expression using EPPlus

前端 未结 3 2064
北恋
北恋 2020-12-09 04:27

I\'m trying to format some range by using conditional Formatting feature of EPPlus. I read many document but there is nowhere mentions about Conditional Formatting Expressio

3条回答
  •  暖寄归人
    2020-12-09 04:47

    After many moons I found way more flexible and fast approach to do this using LINQ and EPPlus. All you need to do is: add extra property to your list to save Excel Row Numbers, and then retrieve cell addresses using LINQ. In this case it would look like this:

    string sRng = string.Join(",", YourModel.Where(f => f.YourField == null)
        .Select(a => "H" + a.iRow + ",L" + a.iRow + ",AA" + a.iRow)); // this address could be many pages and it works
    
    if (sRng.Length > 0) {
        ws.Cells[sRng].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Green); 
    }
    

    Here is the full article:

    https://www.codeproject.com/Tips/1231992/Conditional-Formatting-in-Excel-with-LINQ-and-EPPl

    Also see here another example: https://stackoverflow.com/a/49022692/8216122 hope this helps somebody in the future.

提交回复
热议问题