How to make correct date format when writing data to Excel

后端 未结 10 1915
[愿得一人]
[愿得一人] 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:19

    Try using

    DateTime.ToOADate()
    

    And putting that as a double in the cell. There could be issues with Excel on Mac Systems (it uses a different datetime-->double conversion), but it should work well for most cases.

    Hope this helps.

提交回复
热议问题