Adding filter to pivot table

I am trying to add a filter to a range of columns (38 to 43). The following code is not working:


AutoFilter autoFilter = pwkSheet.AutoFilter;
pwkSheet.AutoFilter.SetRange(0,38,43);
autoFilter.Custom(1, FilterOperatorType.Equal, “LAB”);
autoFilter.Refresh();

Hi,


Thanks for your posting and using Aspose.Cells.

Please see the following sample code, its source excel file and its output excel file for a reference. It shows, how to apply filter on 3rd column and select multiple filter values.

If you open the output excel file, you will see, autofilter has been applied successfully. I have also attached the screenshot for your reference.

Note:
You can use the similar code to apply auto filter on Pivot Table. If you are unable to do so, then please share with us your source excel file containing the pivot table and your expected excel file on which you have applied the filter manually. We will look into your issue and help you asap.

C#
//Load sourc excel file
Workbook wb = new Workbook(“source.xlsx”);

//Access first worksheet.
Worksheet ws = wb.Worksheets[0];

//Apply auto filter on this range
ws.AutoFilter.Range = “A1:H1”;

//Apply filter on 3rd column
//Selected filter values are 1, 4, 6, 8
ws.AutoFilter.AddFilter(2, “1”);
ws.AutoFilter.AddFilter(2, “4”);
ws.AutoFilter.AddFilter(2, “6”);
ws.AutoFilter.AddFilter(2, “8”);

//Refresh the autofilter
ws.AutoFilter.Refresh();

//Save the output excel file
wb.Save(“output.xlsx”);