0

I'm trying to insert datetime value. It works, but when I open the excel file, in the column I see only date. To see time I must click on cell and look at the formula bar

DateTime valueDate = DateTime.Now;
string valueString = valueDate.ToOADate().ToString();
CellValue cellValue = new CellValue(valueString);

Cell cell = new Cell();
cell.DataType = new EnumValue<CellValues>(CellValues.Number);
cell.StyleIndex = 8;
cell.Append(cellValue);

My cell style:

new CellFormat() 
{
    BorderId = 1,
    NumberFormatId = 14,
    ApplyNumberFormat = true 
}

I believe I should apply a custom style in my code somehow.

amplifier
  • 1,793
  • 1
  • 21
  • 55
  • Check this, seems to have the same problem and a solution. https://stackoverflow.com/questions/6033376/openxml-and-date-format-in-excel-cell/6392555 – agileMike Dec 16 '19 at 00:36
  • Also, the answer recommends using ClosedXML library. You might want to check that out, or some other library for working with Excel a little more easily than the OpenXML sdk. – agileMike Dec 16 '19 at 00:37

0 Answers0