Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Document-Processing-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -6299,6 +6299,9 @@
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-retrieve-the-name-of-the-chart-in-an-Excel-worksheet">How to retrieve the name of the chart in an Excel worksheet?</a>
</li>
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-check-if-a-worksheet-is-empty-in-excel">How to check if a worksheet is empty in Excel?</a>
</li>
</ul>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
title: Check if a worksheet is empty in Excel | Syncfusion
description: Code example to check if a worksheet is empty in Excel using Syncfusion .NET Excel library (XlsIO).
platform: document-processing
control: XlsIO
documentation: UG
---

# How to check if a worksheet is empty in Excel?

The following code examples demonstrate how to check whether a worksheet is empty in Excel using C# (Cross-platform and Windows-specific) and VB.NET.

{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/Worksheet/.NET/CheckIfWorksheetIsEmpty/CheckIfWorksheetIsEmpty/Program.cs,180" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));
IWorksheet worksheet;
for (int i = 0; i < workbook.Worksheets.Count; i++)
{
// Access the worksheet
worksheet = workbook.Worksheets[i];

// Check if worksheet is empty
if (worksheet.UsedCells.Length == 0)
Console.WriteLine("The worksheet with name \""+ worksheet.Name + "\" is empty");
}
}
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open("Input.xlsx");
IWorksheet worksheet;
for (int i = 0; i < workbook.Worksheets.Count; i++)
{
// Access the worksheet
worksheet = workbook.Worksheets[i];

// Check if worksheet is empty
if (worksheet.UsedCells.Length == 0)
Console.WriteLine("The worksheet with name \""+ worksheet.Name + "\" is empty");
}
}
{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
Using excelEngine As New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx

Dim workbook As IWorkbook = application.Workbooks.Open("Input.xlsx")
Dim worksheet As IWorksheet

For i As Integer = 0 To workbook.Worksheets.Count - 1
' Access the worksheet
worksheet = workbook.Worksheets(i)

' Check if worksheet is empty
If worksheet.UsedCells.Length = 0 Then
Console.WriteLine("The worksheet with name """ & worksheet.Name & """ is empty")
End If
Next
End Using
{% endhighlight %}
{% endtabs %}

A complete working example in C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/FAQ/Worksheet/.NET/CheckIfWorksheetIsEmpty">this GitHub page</a>.