Web页面的数据导出excel时的格式问题

本文介绍如何在Web页面中使用GridView导出数据到Excel时,针对不同类型的数据显示正确的格式,包括文本、日期、数字、货币及百分比等,并提供了一个具体的代码示例。
  1. Web页面的数据导出excel时的格式问题  
  2. 文本:vnd.ms-excel.numberformat:@
  3. 日期:vnd.ms-excel.numberformat:yyyy/mm/dd
  4. 数字:vnd.ms-excel.numberformat:#,##0.00
  5. 货币:vnd.ms-excel.numberformat:¥#,##0.00
  6. 百分比:vnd.ms-excel.numberformat: #0.00%
  7. 在GridView中执行RowDataBound事件
  8.     protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
  9.     {
  10.         if (e.Row.RowType == DataControlRowType.DataRow)
  11.         {
  12.             e.Row.Cells[4].Attributes.Add("style""vnd.ms-excel.numberformat:@");
  13.             e.Row.Cells[5].Attributes.Add("style""vnd.ms-excel.numberformat:@");
  14.             e.Row.Cells[6].Attributes.Add("style""vnd.ms-excel.numberformat:@");
  15.             e.Row.Cells[7].Attributes.Add("style""vnd.ms-excel.numberformat:@");
  16.             e.Row.Cells[8].Attributes.Add("style""vnd.ms-excel.numberformat:@");
  17.         }
  18.     }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值