This project has moved. For the latest updates, please go here.

The Word "Infinity"

Dec 30, 2011 at 12:20 AM

Dear ClosedXML,

I encountered an interesting happening.  I am using ClosedXML to read a text file and magically create an excel spreadsheet.  Most values are strings that get added to cells.  Consider this code:

cell = worksheet.Cell("A1");
cell.Value = firstName;

The variable firstName holds a string that gets assigned to cell.Value.  I stumbled upon a First Name of "Infinity".  It seems that Excel tries to do something special.  I believe "Infinity" is a reserved word for Excel?

I was able to fix this by adding this code directly beneath:

if (firstName == "Infinity")
    cell.SetDataType(XLCellValues.Text);

Are there other special Excel words/commands that I should account for?  Thanks in advance!

Coordinator
Dec 30, 2011 at 1:45 AM

That's because right now ClosedXML tries to convert strings to numbers, dates, etc. and unfortunately Infinity can be converted to Double. I will put a flag that you can use to specify whether you want to interpret strings (useful when dealing with datasets) or to always treat strings as text.

In the meantime you don't have to put that "if" statement, just use cell.SetValue("Your String"), so for example the following will work as expected (the word "Infinity" will appear on cell A1.

worksheet.Cell(1,1).SetValue("Infinity");