C# GridView导出excel,字段值前边带0的,导出后不显示0的解决方法

        Response.Clear();
        Response.AddHeader( " content-disposition "" attachment;filename= " + System.Web.HttpUtility.UrlEncode(DateTime.Now.ToString( " yyyy-MM-dd ") +  " .xls ");
        Response.Charset =  " utf-8 ";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding( " utf-8 ");
        Response.ContentType =  " application/vnd.ms-excel ";
         string strStyle =  " ";
        System.IO.StringWriter stringWrite =  new System.IO.StringWriter();
        stringWrite.WriteLine(strStyle);
        System.Web.UI.HtmlTextWriter htmlWrite =  new HtmlTextWriter(stringWrite);

        P_GridView.RenderControl(htmlWrite);

        Response.Write(stringWrite.ToString());
        Response.End();*/
         /////////////////////
         // *********************重新设置
        P_GridView.AllowPaging =  false;
        P_GridView.AllowSorting =  false;
         this.P_GridView.PageSize =  65000; // 最大为65535
        dataBind();
        P_GridView.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        Response.End();
        
         this.P_GridView.PageSize =  10;
        dataBind();
最重要的就是下面两行
string strStyle = "";//写入方式
stringWrite.WriteLine(strStyle);//使用定义的strStyle方式写入

你可能感兴趣的:(C# GridView导出excel,字段值前边带0的,导出后不显示0的解决方法)