Last post Sep 09, 2009 04:45 AM by burdock1974
Sep 08, 2009 12:03 PM|burdock1974|LINK
Hi, I am automating an Excel worksheet from a C# ASP.NET application. I am writing different values to different cells. However when I try to add a date to a cell, Excel swaps the day and month format from, e.g. '08/09/09' to '09/08/09'.
Here is the code I am using:
Range range= (Range)worksheet.get_Range("G17", "G17");
range.Value2 = "08/09/09";
range.NumberFormat = "dd-MM-yyyy";
range.NumberFormatLocal = "dd-MM-yyyy";
I suspect that I need to change the LCID in the Excel file programatically- is this possible?
The regional settings are set correctly on the server with the ASP.NET application and Excel file.
Many thanks for any help- this is driving me crazy!
Sep 08, 2009 12:26 PM|suthish nair|LINK
sometimes its hard to handle dateformats in excel.
there are workarounds, change the cell format to Text and save the date.
Sep 09, 2009 04:26 AM|burdock1974|LINK
Thanks, can I change the cell format programatically?
I did some Googling, and found the following:
However, when I try that, my date is now output as '40034'.
Sep 09, 2009 04:33 AM|Mohammed.Hassan|LINK
surround the date with single quotes so that excel leaves the value without change
like this "'08/09/09'"
Sep 09, 2009 04:45 AM|burdock1974|LINK
Thanks, that worked! I only needed the first single quote though (it output the second quote into the text).