How to find if Workbook is empty??

4 posts, 0 answers
  1. Dhananjay
    Dhananjay avatar
    2 posts
    Member since:
    Feb 2015

    Posted 10 Feb 2015 Link to this post

    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
    }
  2. Tanya
    Admin
    Tanya avatar
    404 posts

    Posted 11 Feb 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Dhananjay
    Dhananjay avatar
    2 posts
    Member since:
    Feb 2015

    Posted 12 Feb 2015 in reply to Tanya Link to this post

    Tanya,

    Thanks for the reply.

    That's a lot of code to find if the activeworksheet is empty, plus the catches :-).
  5. Tanya
    Admin
    Tanya avatar
    404 posts

    Posted 12 Feb 2015 Link to this post

    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.

     
Back to Top