We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to Apply multiple filters on a column simultaneously in excel Worksheet JAVA

Hello Team,

I would like to apply multiple filters on a column simultaneously.

Below is my actual data and I would like to apply filter on name column to have only “ABC”,“DEF” and “PQR”.

The issue is only the last filter PQR is getting applied and others are getting removed. I tried using custom also but then only 2 filters can be applied at a time and not more than that.

image.png (2.5 KB)

Below is the output I require,

image.png (2.6 KB)

Can you please help here. Attaching excel for your reference.

Excel.zip (6.3 KB)

@sourav24,

Please see the following sample code to accomplish your task. I tested the code and it works fine:
e.g.
Sample code:

Workbook workbook = new Workbook("e:\\test2\\Book1.xlsx");

            Worksheet sheet = workbook.Worksheets[0];

            //Represents the range to which the specified AutoFilter applies
            sheet.AutoFilter.Range = "A1:B8";

            //Add your desired filters
            sheet.AutoFilter.AddFilter(0, "ABC");
            sheet.AutoFilter.AddFilter(0, "DEF");
            sheet.AutoFilter.AddFilter(0, "PQR");


            sheet.AutoFilter.Refresh();


            workbook.Save("e:\\test2\\out1.xlsx");

Hope, this helps a bit.

1 Like

Thanks, this was exactly what was needed.

@sourav24,

Good to know that your issue is sorted out by the suggested code segment. In the event of further queries or issue, feel free to write us back.

1 Like