How to Remove Auto Filters in Excel Using C#

Visual guide for removing auto filters in Excel using Spire.XLS for .NET and C#

Auto filters in Excel are a powerful feature for sorting and analyzing data. However, once you’ve finished your data review or need to share the file in its original, unfiltered form, it’s often necessary to remove auto filters from Excel worksheets. If you’re building .NET applications, you can automate this task easily using Spire.XLS for .NET — whether you're removing filters from a single sheet or processing Excel files in batches.

In this article, you'll learn how to remove auto filters in Excel using Spire.XLS for .NET in C# programs.

Here’s what we will cover:

Why Remove Auto Filters in Excel?

Removing auto filters in Excel can be essential for:

  • Restoring full visibility of your data after filtering
  • Preparing spreadsheets for export, printing, or presentation
  • Sharing files without hidden or partial data views

In other words, removing filters in Excel files helps maintain data clarity, especially when passing documents to clients, teams, or reports.

How to Remove Auto Filters in Excel Using Spire.XLS

Setting Up Spire.XLS for .NET

Before getting started, install the Spire.XLS library via NuGet:

PM> Install-Package Spire.XLS

Or install the free version for lightweight Excel processing:

PM> Install-Package FreeSpire.XLS

You can also download Spire.XLS for .NET or Free Spire.XLS for .NET, and install the version you choose manually.

Key Methods and Properties Used

  • Workbook.LoadFromFile() – Loads an existing Excel file into the Workbook object for processing.
  • Workbook.Worksheets[] – Accesses a specific worksheet by index from the workbook.
  • Worksheet.AutoFilters.Clear() – Removes all existing filter rules and makes all rows visible.
  • Worksheet.AutoFilters.Range – Defines or updates the range of cells to which auto filters are applied.
  • Workbook.SaveToFile() – Saves the modified workbook as a new Excel file.

C# Code Example: Remove All AutoFilters in Excel

Here’s a complete example of how to remove all auto-filters in Excel using C# and Spire.XLS:

  • C#
using Spire.Xls;

// Create a Workbook instance
Workbook workbook = new Workbook();

// Load an Excel workbook
workbook.LoadFromFile("Sample.xlsx");

// Get a worksheet
Worksheet sheet = workbook.Worksheets[0];

// Remove auto-filters
sheet.AutoFilters.Clear();

// Save the workbook
workbook.SaveToFile("output/RemoveExcelFilter.xlsx");
workbook.Dispose();

Excel Worksheet Before and After Removing All Auto Filters

Excel sheet with filters applied and then removed using Spire.XLS for .NET

Removing a Specific Filter Column in an Excel Worksheet

In Excel, auto filters are applied to a continuous range of columns. This means you can’t directly remove the filter from just one column if it's part of a larger filter range. If you need to exclude a specific column from filtering, you’ll have to reset the filter range in Excel worksheets to adjacent columns.

Here’s how you can do it using Spire.XLS:

  • C#
using Spire.Xls;

// Create a Workbook instance
Workbook workbook = new Workbook();

// Load an Excel workbook
workbook.LoadFromFile("Sample.xlsx");

// Get a worksheet
Worksheet sheet = workbook.Worksheets[0];

// Remove the current filters to show all data (to avoid missing data)
sheet.AutoFilters.Clear();

// Reset the filter range
sheet.AutoFilters.Range = sheet.Range[1, 3, 5, 5];

// Save the workbook
workbook.SaveToFile("output/ResetExcelFilter.xlsx");
workbook.Dispose();

Note: Before resetting the filter range, make sure to remove any existing auto filters. Skipping this step can result in hidden (filtered-out) rows being excluded from the new range, potentially causing data to be lost or missed.

Excel Worksheet Before and After Removing a Specific Filter Column

Excel sheet showing filters applied to all columns, then reapplied to selected columns using Spire.XLS

Why Use Spire.XLS to Remove Filters?

  • Fast & efficient: No need to open Excel files manually.
  • Easy to integrate: Compatible with .NET Framework and .NET Core.
  • No dependencies: Does not require Microsoft Office.
  • Production-ready: Great for batch jobs and enterprise systems.

See Also: How to Add, Update, and Remove Excel Slicers in C#

Conclusion

Removing auto filters in Excel with Spire.XLS for .NET is quick and simple. Whether you're processing reports or resetting spreadsheets for clean data presentation, you can automate it easily using C#.

Frequently Asked Questions

  • Q: How do you remove auto filters in Excel using C#?

    Use the AutoFilters.Clear() method from Spire.XLS. It removes all filters from the specified worksheet in just one line of code.

  • Q: What’s the easiest way to remove auto filters on Excel programmatically?

    Using Spire.XLS for .NET, you can remove filters with a few lines of C# without opening Excel. It's fast, lightweight, and reliable.

  • Q: Can I remove only specific filters instead of all of them?

    In Excel (and Spire.XLS), auto filters must be applied to a continuous block of columns. You can’t directly remove a filter from just one column in the middle of a filtered range. To remove a specific filter, you need to clear all filters first using Worksheet.AutoFilters.Clear(), then reset the filter range using Worksheet.AutoFilters.Range to exclude the unwanted column.

  • Q: Is there a free version of Spire.XLS for .NET?

    Yes! We offer a free version – Free Spire.XLS for .NET, which is completely free to use and does not add watermarks to output files. It’s ideal for lightweight Excel processing.

If you want to evaluate the full feature set without any limitations, you can request a temporary license.