C#中将DataGridView的内容导出道Excel,并且前面的00要显示出来,代码如何实现?如下图:

2025-03-23 19:10:37
推荐回答(1个)
回答1:

在gridview的RowDataBound事件中增加格式:
如给第0、4列添加样式,避免导出时变成科学计数或去掉前导0
If (e.Row.RowType == DataControlRowType.DataRow )
{
e.Row.Cells(0).Attributes.Add("style", "vnd.ms-excel.numberformat:@;");
e.Row.Cells(4).Attributes.Add("style", "vnd.ms-excel.numberformat:@;");
}