I\'m using Microsoft Open XML SDK 2 and I\'m having a really hard time inserting a date into a cell. I can insert numbers without a problem by setting Cell.DataType = Cell
You have to convert DateTime
to double
using function ToOADate
i.e.:
DateTime dtValue = DateTime.Now;
string strValue = dtValue.ToOADate().ToString(CultureInfo.InvariantCulture);
then set it as CellValue
Cell cell;
cell.DataType = new EnumValue(CellValues.Date);
cell.CellValue = new CellValue(strValue);
Remember to format cell using DateTime
formatting, otherwise you will see double
value, not date.