ぷ行走de猫げ

在快乐中成长,在快乐中学习!

ASP.Net中導出Excel時數字較長會自動轉換為科學計數法的解決方法

在我們把DataGrid上的資料導入到Excel的時候,如果遇到比較長的數位字串,比如身份證號碼,就會在Excel裏當成數位看待,並轉換成科學計數法的格式,造成資料的丟失,解決此問題的方法其實很簡單,只需在DataGrid的ItemDataBound事件中寫以下代碼:

   if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
 {
    e.Item.Cells[7].Attributes.Add("style","vnd.ms-excel.numberformat:@");

}

 

參考網址:

http://dotnet.aspx.cc/article/8a4cbf47-b888-4832-3389-ed3a3a3c8aab/read.aspx

posted @ 2009-01-05 09:23  李天翔  阅读(1637)  评论(3编辑  收藏  举报