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方式写入
  • 相关阅读:
    Android简易注解View(java反射实现)
    android注解[Jake Wharton Butter Knife]
    Android渠道汇总
    SVN管理规范
    马上着手开发iOS应用程序一 todolist
    MVC记录
    OC中intValue要注意的地方
    将从数组中取到的字符串赋值给了UIImage导致的错误
    一个null引发的错误
    记录一些容易忘记的属性 -- UITabBarController
  • 原文地址:https://www.cnblogs.com/chendaoyin/p/3040752.html
Copyright © 2011-2022 走看看