We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to determine the worksheet is empty (blank worksheet)?

Workbook NewWorkbook = new Workbook();
Workbook workbook = null;
Worksheet worksheet = null;
workbook = new Workbook(spath, Lop);
.....
.....
if(worksheet.Cells.MaxRow == -1 && worksheet.Cells.MaxDisplayRange.Value == null)
Is there a better way?

Hi Huang,

Thanks for your posting and using Aspose.Cells.

You can check if the worksheet is empty or not using one of the following conditions.

C#


Workbook workbook = new Workbook(“source.xlsx”);


Worksheet worksheet = workbook.Worksheets[0];


if (worksheet.Cells.MaxRow == -1 && worksheet.Cells.MaxColumn == -1)

{

Debug.WriteLine(“Sheet is emtpty”);

}


//Or you can use this condition

if (worksheet.Cells.LastCell == null)

{

Debug.WriteLine(“Sheet is emtpty”);

}



Hi,


I think you are doing Ok to evaluate if a worksheet is empty. You can also try to use the following code to check if the worksheet is empty or not.
e.g
Sample code:

if(worksheet.Cells.Count == 0)

{

//Worksheet is empty

}

Thank you.