We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to clear autofilters

Hi,

I'm trying to clear autofilters, but can't figure out how to do it. Is there any example code somewhere? IWorksheet.AutoFilters.FilterRange seems to be close, but how to set it to an empty range? I can't set it to null.

Thanks!

Wout

5 Replies

GM Geetha M Syncfusion Team July 1, 2009 11:48 AM UTC

Hi Wout,

Thank you for your continued interest in Syncfusion products.

Currently it is not possible to clear filters. But you can workaround this by changing the current FilterRange. You can check the code snippet below.

sheet.AutoFilters.FilterRange = sheet[30,20];

Please try this and let me know if you have any questions.

Regards,
Geetha


WD Wout de Zeeuw July 1, 2009 03:36 PM UTC

Hi,

I tried this workaround, which works ok luckily:

CType(newWorkSheet.AutoFilters, Syncfusion.XlsIO.Implementation.Collections.AutoFiltersCollection).Clear()

If the AutoFilters (IAutoFilters) interface could expose the Clear() method, then the ugly cast wouldn't be needed.

Best regards,

Wout


GM Geetha M Syncfusion Team July 2, 2009 06:21 AM UTC

Hi Wout,

Thank you for the details.

I have logged a feature request on this regard and will get back to you once it is implemented.

Regards,
Geetha


PM Paul Meems August 6, 2019 10:24 AM UTC

I know this is an old question but is the suggested answer still the best solution:
((Syncfusion.XlsIO.Implementation.Collections.AutoFiltersCollection) worksheet.AutoFilters).Clear();

I need to remove the filters before saving my workbook under a different name (SaveAs) because the rows that are filtered out don't make it to the new workbook.


AV Abirami Varadharajan Syncfusion Team August 7, 2019 02:08 PM UTC

Hi Paul, 
 
You can unhide the filtered out rows after clearing the autofilters using ShowRange of IWorksheet . Please refer to below code to achieve the same. 
 
Code Example: 
                  (worksheet.AutoFilters as AutoFiltersCollection).Clear(); 
                  worksheet.ShowRange(worksheet.UsedRange, true); 
 
Please refer to below documentation to know more on show or hide specific range. 
 
 
Kindly try this and let us know if this meets your requirement. 
 
Regards, 
Abirami 


Loader.
Live Chat Icon For mobile
Up arrow icon