[Asp.Net]GridView导出Excel长数字显示成科学计数
类似身份证纯数字的格式时 ,excel默认是数字格式 变成了科学计数法 ,
GridView:RowDataBound
添加e.Row.Cells[2].Attributes.Add(“style”, “vnd.ms-excel.numberformat:@;”);
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //你的身份证是第3列,只需将其格式化为字符即可。 e.Row.Cells[2].Attributes.Add("style", "vnd.ms-excel.numberformat:@;"); }
}
Repeater
添加:
style=“vnd.ms-excel.numberformat:@”
<th scope="col"><%# DataBinder.Eval(Container.DataItem,"[性别]") %></th><th scope="col" style="vnd.ms-excel.numberformat:@"><%# DataBinder.Eval(Container.DataItem,"[出生日期]") %></th>
<th scope="col" style="vnd.ms-excel.numberformat:@"><%# (DataBinder.Eval(Container.DataItem,"[身份证号码]")).ToString() %></th><th scope="col"><%#(DataBinder.Eval(Container.DataItem,"[手机号码]")).ToString() %></th>