none
How to know when is an Empty String or a NULL in an Excel Spreadsheet? RRS feed

  • Question

  • I'm reading some Excel spreadsheets (.xlsb) with the following piece of code:

    private string GetCellVal(Excel.Worksheet sheet, int line, int col)
    {
        try
        {
            var val = sheet.Cells[line, col].Value != null ? sheet.Cells[line, col].Value.ToString() : null;
            return val;
        }
        catch
        {
            return null;
        }
    }

    I am using the NetOffice.Excel API and works fine, but I have noticed that in some spreadsheets the "empty cells" can have "no value" and return a NULL or have a "value" and they are casted as an Empty String (""); however, I cannot identify the main reason of this behavior since from my user's perspective they are empty when I open them in Excel.

    Also, I already checked that is not during the catch since that's a very rare instance.

    Has anyone experienced something like this? Or have any idea the reason behind this behavior?



    Federico Navarrete

    Tuesday, November 26, 2019 9:57 AM