GridView 顯示數據時常常會有多種字段格式,比如:時間、數字、貨幣、身份證號等,尤其是身份證號的顯示常常會顯示成科學計數法,
要解決其實很容易,給每個字段設置類型就可以了:
常用格式:
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%
使用方法:
gridview 的 RowDataBound 事件中添加
//其中i表示列數,從0開始
e.Row.Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat:@;");