類似身份證純數字的格式時 ,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>