如何使用Excel Interop获取过滤行的范围?

我正在使用Excel互操作程序集为我的项目,如果我想使用自动filter,那么可能使用

sheet.UsedRange.AutoFilter(1,SheetNames[1],Microsoft.Office.Interop.Excel.XlAutoFilterOperator.xlAnd,oMissing,false) 

但我怎么能得到过滤行?

任何人都可以有想法?

一旦过滤了范围,就可以通过使用Range.SpecialCells方法访问传递过滤条件的单元格,传递一个“Excel.XlCellType.xlCellTypeVisible”值来获取可见单元格。

根据上面的示例代码,访问可见单元格应如下所示:

 Excel.Range visibleCells = sheet.UsedRange.SpecialCells( Excel.XlCellType.xlCellTypeVisible, Type.Missing) 

从那里,您可以通过“Range.Cells”集合访问可见范围内的每个单元格,或访问每行,首先通过“Range.Areas”集合访问区域,然后在“行”为每个地区收集。 例如:

 foreach (Excel.Range area in visibleCells.Areas) { foreach (Excel.Range row in area.Rows) { // Process each un-filtered, visible row here. } } 

希望这可以帮助!

麦克风