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方式写入
  • 相关阅读:
    .NET Cache缓存
    异步
    es6常用功能
    vue-router路由懒加载
    vue中nextTick和$nextTick
    动态模板中 swiper 划不动问题
    javaScript正则判断手机号
    Mac终端使用技巧
    alert IOS自带域名
    vue css background路径不对
  • 原文地址:https://www.cnblogs.com/chendaoyin/p/3040752.html
Copyright © 2011-2022 走看看