zoukankan      html  css  js  c++  java
  • gridview操作excel导出时解决显示成科学计数法的问题

    对单元格数据进行格式化:

    常见的格式如下: (除文本格式测试通过外,日期好像不行,其他未测试)

    1) 文本:vnd.ms-excel.numberformat:@
    2) 日期:vnd.ms-excel.numberformat:yyyy/mm/dd
    3) 数字:vnd.ms-excel.numberformat:#,##0.00
    4) 货币:vnd.ms-excel.numberformat:¥#,##0.00
    5) 百分比:vnd.ms-excel.numberformat: #0.00%

    代码
    1 protected void GVExport_RowDataBound(object sender, GridViewRowEventArgs e)
    2 {

    8 if( e.Row.RowIndex > -1 )
    9 {
    10 //for (int i = 0; i < e.Row.Cells.Count; i++)
    11 //{
    12 // e.Row.Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
    13 //}
    14   e.Row.Cells[1].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
    15 e.Row.Cells[2].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
    16 //e.Row.Cells[17].Attributes.Add("style", "vnd.ms-excel.numberformat:yyyy/mm/dd");
    20   }
    21 }

     实在不行,再加上如下操作试试,在导出excel的方法中加上如下代码:

    代码
    1 System.Web.UI.WebControls.GridView gv = new GridView();
    2 gv.RowDataBound += new System.Web.UI.WebControls.GridViewRowEventHandler(gv_ItemDataBound); //绑定格式转换方法
    3 gv.DataSource = dt.DefaultView;
    4 gv.DataBind();
    5
  • 相关阅读:
    获取文件mime类型
    PHP的CURL
    PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案
    MySQL中的group_concat函数
    MYSQL批量修改表前缀与表名sql语句
    ubuntu18.04 无法连接有线
    ffmpeg接收udp输入的h264文件流,推流到rtmp服务器
    nginx-rtmp
    tf.image.crop_and_resize
    tf.reduce_sum
  • 原文地址:https://www.cnblogs.com/pfs1314/p/1699314.html
Copyright © 2011-2022 走看看