简体   繁体   English

如何在C#中的单元格(边框)颜色上搜索Excel范围?

[英]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.

相关问题 根据 excel 表中的值获取单元格范围/位置,并在 c# 中为单元格数据网格视图着色 - Get cell range/location based on value at excel sheet and colour the cell datagridview in c# 如何在C#中向Excel范围添加底部边框? - How can I add a bottom border to an Excel range in C#? 如何以编程方式在C#Excel vsto中为单元格添加彩色边框? - How to programmatically add colored border to a cell in C# Excel vsto? C#擅长如何在使用范围内查找第一个单元格。 - c# excel how to Find First Cell in a used range. 将 Excel 单元格范围转换为 DataTable C# - Convert Excel cell range into DataTable C# 有没有办法使用C#更改Excel单元格的颜色? - Is there Any way to change the colour of an Excel Cell using C#? C#Excel宏-如何检查单元格值是否为负并更改其字体颜色? - C# Excel Macro - how to check if cell value is negative and change its font colour? 如何在C#中将Excel单元格的值类型设置为Text? - How to set a Excel cell's value type to Text in C#? c# npoi excel 如何获取单元格的公式值? - c# npoi excel How to get a cell's formula VALUE? C# Excel 互操作 - 如何检查范围内的单个单元格是否具有单元格边界? - C# Excel Interop — How to check if a single cell in a range has cell borders?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM