Getting custom format

Aug 25, 2010 at 10:06 PM

In an XLS file, I have some cells with custom formatting ("d-mmm").  When loaded in NPOI v1.2.3, the CellType is STRING.  I can't find any properties on the Cell object that provide access to this format string.  I can set the cell value using the SetCellValue( string ) function, but the cells in the new XLS show the exact value passed into SetCellValue(), which is not in the custom format.

Is there any way to retrieve the format string from the cell, or alternately to tell the sheet to automatically apply formatting to all cells?

Aug 26, 2010 at 2:54 PM

I was able to retrieve the format string like this:

cell.CellStyle.GetDataFormatString ();


Aug 27, 2010 at 1:21 PM

It looks like my problem was that I was embedding custom script strings in cells with non-text formatting.  The idea was to evaluate the script in the row and replace with an actual value (like a date or number).  The text in the cell meant the cell's type was loaded into NPOI as STRING, which caused a lot of issues when I tried to re-write the correct auto-formatted value to the cell.

The lesson here is that CellType is based on cell content over the data format.