Exporting to excel loses the date format

前端 未结 3 1610
我在风中等你
我在风中等你 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 14:01

    Here is some sample code.

    Response.AddHeader("content-disposition", "attachment; filename=Report.xls");
    Response.Charset = "";
    Response.ContentType = "application/vnd.xls";
    System.IO.StringWriter stringWrite = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
    DataGrid g = new DataGrid();
    DataTable d = new System.Data.DataTable();
    d = (DataTable)Session["ReportData"];        
    g.DataSource = d;
    g.DataBind();       
    foreach (DataGridItem i in g.Items)
    {
        foreach (TableCell tc in i.Cells)
            tc.Attributes.Add("class", "text");
    }
    g.RenderControl(htmlWrite);
    string style = @" ";
    Response.Write(style);
    Response.Write(stringWrite.ToString());
    Response.End();
    

提交回复
热议问题