Learn how to Filter Blank and Non-Blank Cells in Excel using C#
Last active
April 29, 2025 04:55
-
-
Save aspose-com-gists/32f9e2afb85bb9f398dc228501e9dd31 to your computer and use it in GitHub Desktop.
Filter Blank and Non-Blank Cells in Excel using C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Cells; | |
// Load the Excel file | |
Workbook workbook = new Workbook("sample_blanks.xlsx"); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Apply AutoFilter to a specific range | |
worksheet.AutoFilter.Range = "A1:C20"; | |
// Call AddFilter function and set criteria to "" | |
worksheet.AutoFilter.AddFilter(1, ""); | |
worksheet.AutoFilter.Refresh(); | |
// Save the output | |
workbook.Save("filtered_blank_cells.xlsx"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Cells; | |
// Load the Excel file | |
Workbook workbook = new Workbook("sample_blanks.xlsx"); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Set AutoFilter range | |
worksheet.AutoFilter.Range = "A1:C20"; | |
// Add multiple filters in the first column (index 0) | |
worksheet.AutoFilter.AddFilter(1, ""); // Blank cells | |
worksheet.AutoFilter.AddFilter(1, "AFG"); // Specific text value | |
worksheet.AutoFilter.Refresh(); | |
// Save the result | |
workbook.Save("combined_filtered.xlsx", SaveFormat.Xlsx); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Cells; | |
// Load your workbook | |
var workbook = new Workbook("sample_blanks.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Call MatchBlanks function to apply the filter | |
worksheet.AutoFilter.MatchNonBlanks(1); | |
// Call refresh function to update the worksheet | |
worksheet.AutoFilter.Refresh(); | |
// Saving the modified Excel file | |
workbook.Save("filtered_non_blanks.xlsx"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment