简体   繁体   English

如何使用包含“ODM”之类的值的 C# 过滤 excel 中的整个列?

[英]How can I filter a whole column in excel using C# that CONTAINS some value like “ODM”?

Does anybody know how to filter a column of excel using the INTEROP C#, and filter all the values that contains 'ODM', or 'AAS'.有谁知道如何使用 INTEROP C# 过滤 excel 列,并过滤所有包含“ODM”或“AAS”的值。 I've already tried to use the namedRange.autofilter but it returns just those VALUES that is write ONLY 'ODM' or 'AAS' and nothing else.我已经尝试使用 namedRange.autofilter 但它只返回那些只写“ODM”或“AAS”的值,没有别的。

This link seems to indicate Excel filters do not support regex. 此链接似乎表明 Excel 过滤器不支持正则表达式。 My own experience resonates with that.我自己的经历与此产生了共鸣。 So, taking a step back, how can we solve your problem?那么,退后一步,我们如何解决您的问题? Well, looking at what the VBA guys did , the idea seems to be as follows:好吧,看看VBA 的家伙做了什么,想法似乎如下:

  • Read the entire column into an array: Interop lets you do this in one efficient swoop将整列读入一个数组:Interop 让您一举搞定
  • Use C#'s powerful Regex engine to filter that array down to a set of values conforming to your regex使用 C# 强大的正则表达式引擎将该数组过滤为一组符合您的正则表达式的值
  • Call the Autofilter function with Criteria1 dynamically generated as the array you just created using the regex filter in the last step.调用Autofilter function并动态生成 Criteria1 作为您刚刚在上一步中使用正则表达式过滤器创建的数组。

I'm not going to code that for you, but I'm quite certain the above approach will work and am happy to consult with you if you need assistance on it.我不会为你编写代码,但我很确定上述方法会奏效,如果你需要帮助,我很乐意与你协商。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用C#替换包含反斜杠的字符串中的某些值? - How can I replace some values in a string that contains backslashes using C#? 在使用C#在A列的合并单元格上垂直写入特定值之后,如何在excel中插入新行? - How can I insert a new row in excel after a specific value written vertically on merged cells in column A, using C#? 如何使用C#从excel文件创建树状结构? - How can I create a tree like structure from excel file using C#? c#如何过滤数据库表的列名? - c# How can I filter the column names of a database table? 如何使用excel列中的字段填充comboBox? C# - How can I populate a comboBox using the fields in an excel column? C# 如何使用OLEDB for C#在Excel中执行“从[sheet1 $]其中列为L的*中选择*”? - How can I do this “select * from [sheet1$] where column is L” in Excel using OLEDB for C#? 如何使用DocumentFormat.OpenXml C#获取excel工作表中的特定列? - How can I get the specific column in excel worksheet using DocumentFormat.OpenXml C#? 如何使用C#解析出现在文件中某个位置的值 - How can I parse a value that appears some place in a file using C# 如何使用C#为OData查询中指定的每个过滤器获取一组键/值对? - How can I obtain a set of Key/Value pairs for each filter specified in an OData query using C#? c# 如何按预期名称在 excel 文件中搜索,无需类型如 '%example'% 或列名 = 'row value' - c# how to search in excel file by intended name without type like '%example'% or column name = 'row value'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM