Percy
Percy

Reputation: 3125

Gembox null value breaking formula

I am creating an Excel spread sheet using C# and Gembox.

I get the data from SQLServer in a datatable and I have a situation where if a cell in the datatable is null, putting that into the excel object results in any formulas that rely on that Excel cell breaking.

e.g. I get this:

enter image description here

You can see that if the P4 2015 column has an empty cell then the formula in the var column breaks. If I select the cell in Excel and press Delete then Enter the formula works.

So Gembox is putting something into the cell which breaks the formula but I'm not sure what. I tried to check for Null values and insert an empty string instead but that doesn't work.

Has anyone seen this before, or know how to resolve it? (Note - I need the cell to be empty - I don't want to put a 0 in there).

Upvotes: 1

Views: 1283

Answers (1)

Percy
Percy

Reputation: 3125

I managed to get around this error using the following:

Basically I check the value I am inserting into the Excel cell - if it is an empty string then or null then I specifically insert null into the spreadsheet.

if (string.IsNullOrWhiteSpace(value))
{
    worksheet.Cells[columnCode + row].Value = null;
    format = "0";
}
else
{
    //insert as normal...
}

I think all the issues I had were caused by an empty string inserted into a number column on the spreadsheet.

Upvotes: 2

Related Questions