Possible duplicate:
Open Xml and Date format in Excel cell
I am trying to take data from a DataGridView and generate an Excel file with the contents. I have a problem with dates.
The problem is that, after writing the worksheet, I saved and opened it in Excel, my date cell has a date value in it, and if I do "Format cells", it has the format that I requested, but Excel does not apply this format . For example, if I export the date value using ".ToOADate ()", I get something like "40690.5270454051" in the cell. If I click on a cell and then again, the correct formatting will be applied.
I tried to miss the "ToOADate" call and the same thing happens (I get a recognizable date value, but only formatting using my custom format after I clicked and left the cell).
I tried to set the DataType of the OpenXml.Spreadsheet.Cell object for CellValues.Date (or EnumValue (CellValues.Date)), but then I get an "unreadable content" error when I try to open the xlsx file.
Thanks Ross
source
share