This is a migrated thread and some comments may be shown as answers.

How to find if Workbook is empty??

3 Answers 246 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Dhananjay
Top achievements
Rank 1
Dhananjay asked on 10 Feb 2015, 01:11 PM
Team,

What property is available on a RadSpreadsheet to find if the workbook/activeWorkSheet is empty ?

Currently Im using the below code to find the same.
var stream = new MemoryStream();
new XlsxFormatProvider().Export(radSpreadsheet.Workbook, stream);
if (stream.Length == 3309) 
{
 //Empty Workbook
}

3 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 11 Feb 2015, 02:08 PM
Hello Dhananjay,

You can use the UsedCellRange property of Worksheet. It should be checked if it is empty and, since it is returning a range always containing the first cell, the same should be checked for the cell too:
CellRange range = this.radSpreadsheet.Workbook.Worksheets.First().UsedCellRange;
CellIndex cellIndex = new CellIndex(0, 0);
 
CellSelection cell = this.radSpreadsheet.Workbook.Worksheets.First().Cells[cellIndex];
ICellValue value = cell.GetValue().Value;
if (range.ColumnCount == 1 && range.RowCount == 1 && value.ValueType == CellValueType.Empty)
{
    MessageBox.Show("The document is empty");
}
else
{
    MessageBox.Show("The document is NOT empty");
}

However, you should be aware that the property UsedCellRange stores all the cells used in the Worksheet, even if their content was already deleted. This means that if you type some text in one of the cells and then delete its content, this cell will be included in the UsedCellProperty. This also includes any style changes applied to cells.

Hope this helps.

Regards,
Tanya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Dhananjay
Top achievements
Rank 1
answered on 12 Feb 2015, 01:07 PM
Tanya,

Thanks for the reply.

That's a lot of code to find if the activeworksheet is empty, plus the catches :-).
0
Tanya
Telerik team
answered on 12 Feb 2015, 05:05 PM
Hello Dhananjay,

We logged this in our backlog. I suggest you to vote and subscribe to the public item in the feedback portal and will be immediately notified for changes on its status. 

Let me know if I can assist you with anything else.

Regards,
Tanya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Spreadsheet
Asked by
Dhananjay
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Dhananjay
Top achievements
Rank 1
Share this question
or