diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index a1e86d792..95d7105f0 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6299,6 +6299,9 @@
  • How to retrieve the name of the chart in an Excel worksheet?
  • +
  • + How to check if a worksheet is empty in Excel? +
  • diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-check-if-a-worksheet-is-empty-in-excel.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-check-if-a-worksheet-is-empty-in-excel.md new file mode 100644 index 000000000..5384e65b0 --- /dev/null +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-check-if-a-worksheet-is-empty-in-excel.md @@ -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 this GitHub page. \ No newline at end of file