Creating an OpenXML Excel File Not Used for Date Formatting

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

+3
source share
1 answer

You need to set a value, which is a floating point number (the number of days from January 1, 1900 or 1904 - there is a parameter in the file to decide which one). Hh: mm: ss is part of a fraction of a number.

. Excel . Excel .

, , . , Excel , , , .

, , .

+1

All Articles