刷新自动筛选后获取所有隐藏行索引
可能的使用场景
当您在工作表单元格上应用自动筛选器时,某些行会自动隐藏。但可能某些行已被 Excel 最终用户手动隐藏,并且未被自动筛选器隐藏。因此,很难知道哪些行被自动筛选器隐藏,哪些行被 Excel 最终用户手动隐藏。 Aspose.Cells 使用 int[] 处理这个问题[AutoFilter.refresh(bool hideRows) ](https://reference.aspose.com/cells/java/com.aspose.cells/autofilter#refresh(boolean) ) 方法。此方法返回自动过滤器隐藏的所有行的行索引,而不是 Excel 最终用户手动隐藏的行索引。
刷新自动筛选后获取所有隐藏行索引
请参阅以下加载的示例代码示例 Excel 文件 其中包含一些由 Excel 最终用户手动隐藏的行。该代码应用自动过滤器并使用 int[] 刷新它[AutoFilter.refresh(bool hideRows) ](https://reference.aspose.com/cells/java/com.aspose.cells/autofilter#refresh(boolean) 方法返回自动筛选器隐藏的所有行的行索引。然后它在控制台上打印隐藏行的索引以及单元格名称和值。
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load the sample Excel file
Workbook wb = new Workbook(srcDir + "sampleGetAllHiddenRowsIndicesAfterRefreshingAutoFilter.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Apply autofilter
ws.getAutoFilter().addFilter(0, "Orange");
//True means, it will refresh autofilter and return hidden rows.
//False means, it will not refresh autofilter but return same hidden rows.
int[] rowIndices = ws.getAutoFilter().refresh(true);
System.out.println("Printing Rows Indices, Cell Names and Values Hidden By AutoFilter.");
System.out.println("--------------------------");
for(int i=0; i<rowIndices.length; i++)
{
int r = rowIndices[i];
Cell cell = ws.getCells().get(r, 0);
System.out.println(r + "\t" + cell.getName() + "\t" + cell.getStringValue());
}
控制台输出
Copy Printing Rows Indices , Cell Names and Values Hidden By AutoFilter .
\ --------------------------
1 A2 Apple
2 A3 Apple
3 A4 Apple
6 A7 Apple
7 A8 Apple
11 A12 Pear
12 A13 Pear