Free Support Forum - aspose.com

AutoFilter Question

I am creating an autofilter on a column by setting the range to the column I want to filter, and then doing my merges,etc.

When I am finished with the workbook, I don't want the user to see the filter. How do I remove the filter like pressing the filter link in Excel?

Thanks,

Steve

Hi Steve,



To remove auto-filters, you may try AutoFilter.RemoveFilter() method.

Thank you.

Amjad,

I have attached two files, test.xlsx and testfiltered.xlsx. Here is the code used to generate the autofilter:

Workbook workbook = new Workbook(@"c:\test.xlsx");

Worksheet worksheet = workbook.Worksheets[0];

worksheet.AutoFilter.SetRange(0,0,0);

worksheet.AutoFilter.Filter(0,"1");

worksheet.AutoFilter.RemoveFilter(0,"1");

workbook.Save(@"c:\testfiltered.xlsx");

As you can see in the attached file, testfiltered.xslx still shows the dropdown for the filter, even though I used RemoveFilter.

I want to be able to remove the dropdown on the column.

Thanks,

Steve

Hi,


I think you may call AutoFilter.Refresh() method after using RemoveFilter method. Also, you may set Range to null if you need to off the AutoFilter drop downs:
e.g
worksheet.AutoFilter.Range = null;

Thank you.