Filtering information in Excel spreadsheets is an important feature. It enables you to hide irrelevant data and show only the data meeting specific criteria. There might be scenarios where filtering data can prove to be helpful. For example, an organization may want to filter out low-performing products from the sales report to analyze and improve their sales strategies. In this article, you will learn how to add or remove AutoFilter in Excel files using C++.

C++ API to Adding and Removing AutoFilter in Excel Files

We will use the Aspose.Cells for C++ API for adding and removing AutoFilter in Excel files. It is a native C++ library that allows you to create, read and modify Excel files without requiring Microsoft Excel to be installed. You can either install the API through NuGet or download it directly from the Downloads section.

PM> Install-Package Aspose.Cells.Cpp

Apply AutoFilter in Excel Files using C++

You can apply AutoFilter on a range of cells. AutoFilters allow you to sort and filter values in the given range of cells. The following are the steps to add AutoFilter in Excel files.

The following sample code shows how to apply AutoFilter to a range of cells in an Excel file using C++.

The image of the output file generated by the sample code

The image of the output file generated by the sample code

Add Date AutoFilter in Excel Files using C++

Excel files may contain data based on dates. You might find yourself in scenarios where you need to filter and analyze data based on different dates. Therefore, a date filter will prove to be helpful in such scenarios. The following are the steps to add date AutoFilter in Excel files.

The following sample code demonstrates how to add date AutoFilter in Excel files using C++.

Add Dynamic Date AutoFilter in an Excel File using C++

There might be cases where you need a more generic date filter, such as the month irrespective of the year or the month before the current month. For scenarios like this, you can use the dynamic AutoFilter to filter the data. The following are the steps to filter data using a dynamic date AutoFilter.

The following sample code demonstrates how to add a dynamic date AutoFilter in an Excel file using C++.

Apply Custom AutoFilter in Excel Files using C++

In case you want to apply a custom AutoFilter, Aspose.Cells for C++ API has you covered. Using the API, you can apply a custom AutoFilter in Excel files based on your specific requirements. The following are the steps to add custom AutoFilter in Excel files.

The following sample code shows how to add custom AutoFilter in Excel files using C++.

Remove AutoFilter from Excel Files

In the previous sections, you learned how to add different AutoFilters in Excel files. In addition to adding AutoFilters, you can also remove them using the Aspose.Cells for C++ API. The following are the steps to remove AutoFilters from Excel files.

The following sample code shows how to remove AutoFilter from an Excel file using C++.

Get a Free License

You can try the API without evaluation limitations by requesting a free temporary license.

Conclusion

In this article, you have learned how to add and remove AutoFilters from Excel files using C++. Specifically, you have learned how to add Default, Date, Dynamic Date and Custom AutoFilters. You have also seen how to remove AutoFilter using Aspose.Cells for C++ API. The API provides many additional features for working with Excel files. You can explore the API in detail by visiting the official documentation. In case of any questions, please feel free to reach us on our free support forum.

See Also