我使用下面的代码来应用AutoFilter方法后从Excel文件中获取行计数。但它总是将我作为行数返回1。请帮忙
Excel.Range rngFilter = (Excel.Range)applicationObject.get_Range("Staffing", Type.Missing);
rngFilter.AutoFilter(1, "Transition", XlAutoFilterOperator.xlAnd, Type.Missing, true);
Excel.Range rngResult = rngFilter.SpecialCells(XlCellType.xlCellTypeVisible, Type.Missing);
MessageBox.Show(rngResult.Rows.Count.ToString());
答案 0 :(得分:0)
我试过这个(作为例子)
Excel.Range rngFilter = this.Application.get_Range("A1:A14", missing);
rngFilter.AutoFilter(1, "Transition", Excel.XlAutoFilterOperator.xlAnd, missing, true);
Excel.Range rngResult = rngFilter.SpecialCells(XlCellType.xlCellTypeVisible, missing);
MessageBox.Show(rngFilter.Rows.Count.ToString());
发现它有效。输出为14。
您也可以查看Worksheet.AutoFilter Property
希望这会对你有所帮助。