zoukankan      html  css  js  c++  java
  • 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 = "<style>td{mso-number-format:\"\\@\";}</style>";
            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 = "<style>td{"\\@\";}</style>";//写入方式
    stringWrite.WriteLine(strStyle);//使用定义的strStyle方式写入
  • 相关阅读:
    IT综合学习网站收集
    使用CSS实现表格细边框的三种方式
    安装Ionic遇到的问题
    未能解析此远程名称:'nuget.org' 的解决方法
    webapi 安全验证与权限验证
    iOS模拟器可以编译,真机无法编译
    Mac上安装FFmpeg命令行
    写在工作三周年
    MPMoviePlayerController概述
    NSStream概述
  • 原文地址:https://www.cnblogs.com/chendaoyin/p/3040752.html
Copyright © 2011-2022 走看看