sha*_*pan 7 c# excel automation vsto
我正在为我的项目使用Excel Interop程序集,如果我想使用自动过滤器那么可能使用
sheet.UsedRange.AutoFilter(1,SheetNames[1],Microsoft.Office.Interop.Excel.XlAutoFilterOperator.xlAnd,oMissing,false)
但是如何获得过滤后的行?
谁能有想法?
Mik*_*lum 14
过滤范围后,您可以通过使用Range.SpecialCells方法访问传递过滤条件的单元格,传入值为"Excel.XlCellType.xlCellTypeVisible"以获取可见单元格.
根据上面的示例代码,访问可见单元格应如下所示:
Excel.Range visibleCells = sheet.UsedRange.SpecialCells(
                               Excel.XlCellType.xlCellTypeVisible, 
                               Type.Missing)
从那里你可以通过'Range.Cells'集合访问可见范围内的每个单元格,或访问每一行,首先通过'Range.Areas'集合访问区域,然后迭代'Rows'中的每一行每个区域的集合.例如:
foreach (Excel.Range area in visibleCells.Areas)
{
    foreach (Excel.Range row in area.Rows)
    {
        // Process each un-filtered, visible row here.
    }
}
希望这可以帮助!
麦克风
| 归档时间: | 
 | 
| 查看次数: | 10543 次 | 
| 最近记录: |