I am building a winform based Desktop application. As part of the application, I am generating the Excel output.
I am getting a error, when I am trying to enter the date value.
In C#, the date value is "11-10-12". However, in Excel, it is printing as 10-11-2012.
Here is the code, which does it :
String Date1 = "11-10-12";
oSheet.Cells[i + 2, 1] = DateTime.ParseExact(Date1, "dd-MM-yy", CultureInfo.InvariantCulture).ToString("dd-MM-yyyy");
Any idea what could could be wrong ?
EDIT
The Cell format in Excel was by default General. However, when the values are entered, it is changed to Date.

None of the suggestion helped unfortunately. So, I disabled the automatic formatting in Excel :
So, here is the code snippet which disables the automatic (Date) formatting in Excel :
So, the trick is to preceed the String with an apostrophe which worked.
Thanks