How to make correct date format when writing data to Excel

后端 未结 10 1909
[愿得一人]
[愿得一人] 2020-11-30 04:56

Iam exporting a DataTable to an Excel-file using office interop. The problem is, that Excel does not recognize dates as such, but instead it displays numbers. In another cas

10条回答
  •  攒了一身酷
    2020-11-30 05:12

    This worked for me:

    sheet.Cells[currentRow, ++currentColumn] = "'" + theDate.ToString("MM/dd/yy");
    

    Note the tick mark added before the date.

提交回复
热议问题