Hi Lucas,
Thanks for your posting and using Aspose.Cells.
After refreshing the AutoFilter, you should check if the row is hidden while iterating the rows. If the rows are hidden, then do not print the values and if they are visible, then print their values.
You can check if the row is hidden or not using Cells.isRowHidden() method.
Please see the following code and its console output for your reference. I have also attached the source Excel file used in this code for you to view. I have tested this code on the latest version: Aspose.Cells for Java (Latest Version).
Java
String filePath = “F:\Shak-Data-RW\Downloads\source.xlsx”;
Workbook workbook = new Workbook(filePath);
Worksheet worksheet = workbook.getWorksheets().get(0);
AutoFilter af = worksheet.getAutoFilter();
af.filter(1, “China”);
af.refresh();
Cells cells = worksheet.getCells();
for (int fila = 1; fila <= cells.getMaxRow(); fila++) {
if (cells.isRowHidden(fila) == false) {
System.out.println("Name: " + cells.get(fila, 0).getStringValue());
System.out.println("Country: " + cells.get(fila, 1).getStringValue());
}//if
}//for
Name: Li
Country: China
Name: Azx
Country: China
Thank you Shakeel
Hi Lucas,
Thanks for your posting and using Aspose.Cells.
Please use AutoFilter.applyFilter() method which will apply or refresh the filter. I have tested the following code with the older version and it worked fine.
I used the same source.xlsx file as used in the previous code.
Java - Old Version
String filePath = “F:\Shak-Data-RW\Downloads\source.xlsx”;
Workbook workbook = new Workbook();
workbook.open(filePath);
Worksheet worksheet = workbook.getWorksheets().getSheet(0);
Cells cells = worksheet.getCells();
AutoFilter autoFilter = worksheet.getAutoFilter();
autoFilter.filter(1, “China”);
autoFilter.applyFilter();
for (int fila = 1; fila <= cells.getMaxRow(); fila++) {
if (cells.isRowHidden(fila) == false) {
System.out.println("Name: " + cells.getCell(fila, 0).getStringValue());
System.out.println("Country: " + cells.getCell(fila, 1).getStringValue());
}//if
}//for
Name: Li
Country: China
Name: Azx
Country: China