Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspose-com-gists/32f9e2afb85bb9f398dc228501e9dd31 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/32f9e2afb85bb9f398dc228501e9dd31 to your computer and use it in GitHub Desktop.
Filter Blank and Non-Blank Cells in Excel using C#
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");
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);
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