简体   繁体   中英

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.

@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"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM