[英]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. 我已经在C#中编写了一种方法,该方法逐个单元格逐行循环浏览excel范围,并将其(边框)颜色与我要寻找的颜色进行比较。 This works - of course - but it is pretty slow... 这当然有效-但速度很慢...
Is there a possibility I could use the Find method on my range? 我可以在自己的范围内使用Find方法吗? 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. @ Denise我怀疑您可以在互操作上使用任何Find方法来检查单元格样式。 If you're limiting the range already and going cell-by-cell on a foreach, my only advice is to use EPPlus . 如果您已经限制了范围并在一个foreach上逐个单元地进行,我唯一的建议是使用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. 当我们意识到对于具有至少30,000行的工作表,速度提高了十倍以上时,我们感到非常满意,而且您可以使用LINQ,而不会出现混乱的互操作性。
Using EPPlus you would only need to do something like: 使用EPPlus,您只需要执行以下操作:
//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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.