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
  • 相关阅读:
    [BZOJ5339] [TJOI2018]教科书般的亵渎
    拉格朗日插值法
    [LOJ#2340] [WC2018] 州区划分
    [洛谷4609] [FJOI2016]建筑师
    [CF960G] Bandit Blues
    [BZOJ2115] [WC2011] Xor
    [Codeforces 809E] Surprise me!
    无需AutoCAD,用C#生成DWG文件
    扩展方法的几点总结
    RedirectStandardOutput
  • 原文地址:https://www.cnblogs.com/pfs1314/p/1699314.html
Copyright © 2011-2022 走看看