Exporting to excel loses the date format

前端 未结 3 1607
我在风中等你
我在风中等你 2020-12-18 13:07

I am exporting the contents of SP to excel. One of the columns brings the date format as 08/2015 but when exporting to excel, the format gets changed to Aug-2015.

I

3条回答
  •  佛祖请我去吃肉
    2020-12-18 13:53

    I don't really understand a fair bit of the code (not fluent in asp.net) but I will say that if you want to force text in an excel sheet you need to define the target area as text before putting your data in there.

    If my understanding of the code is correct this:

    response.Write(style);
    

    Needs to be before this.

    dgrExport.RenderControl(htmlWrite);
    

    Edit: Perhaps an alternate solution

    The bit of google code you have found sets the format of the cells as text. In all likelyhood you want excel to treat the date as a date which has a display format of MM/YYYY.

    maybe try replacing this:

    string style = @" "
    

    with

    string style = @" "
    

    I am not sure if / or \ is an escape character in ASP.net so the exact snytax might be different. In excel terms number format @ means text and mm/yyyy will mean a date with the display format that you want.

提交回复
热议问题