DeniseMeander
DeniseMeander

Reputation: 838

How to search an excel range on cell's (border) colour in C#?

I've written a method in C# which loops through an excel range cell by cell, row by row and compare it's (border) colour against the colour I'm looking for. This works - of course - but it is pretty slow...

Is there a possibility I could use the Find method on my range? I googled this but I can't find anything related to finding something else than text.

Upvotes: 0

Views: 531

Answers (1)

Tyress
Tyress

Reputation: 3653

@Denise I doubt you can use any Find methods on interop to check for cell style. If you're limiting the range already and going cell-by-cell on a foreach, my only advice is to use EPPlus. We were converted when we realized that the speed is increased more than tenfold for sheets with at least 30,000 rows, plus you can use LINQ and no messy interop stuff.

Using EPPlus you would only need to do something like:

//looking for cells with a yellow border on its left side
IEnumerable<ExcelRangeBase> matches = worksheet.Cells.Where(c => c.Style.Border.Left.Color.Rgb == "FFFFFF00"); 

Upvotes: 0

Related Questions