I’m trying to format an excel column that I created in a .net application. I send the excel sheet the correct formatted date, however, Excel for some reason seems to be formatting it in a way of its own. The following is what I have, but it doesn’t work:
sheet.Cells[i, 2] = String.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(dr["date"].ToString())); //yyyy-mm-dd
((Excel.Range)sheet.Cells[i, 2]).EntireColumn.NumberFormat = "yyyy-MM-dd";
The format I’m getting is mm/dd/yyyy. How can I format this column? Thank you in advance.
Added
Don’t know if this matters but this is how I’m saving the excel file:
wb.SaveAs(FileName, Excel.XlFileFormat.xlCSV,
null, null, false, false, Excel.XlSaveAsAccessMode.xlNoChange,
false, false, null, null, null);
Try this:
or simply (using strings)