How to make correct date format when writing data to Excel

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

    Did you try formatting the entire column as a date column? Something like this:

    Range rg = (Excel.Range)worksheetobject.Cells[1,1];
    rg.EntireColumn.NumberFormat = "MM/DD/YYYY";
    

    The other thing you could try would be putting a single tick before the string expression before loading the text into the Excel cell (not sure if that matters or not, but it works when typing text directly into a cell).

提交回复
热议问题