在行绑定的时候加上下面的语句就可以了。
e.Row.Cells[5].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
注意你可以将上面的方法添加到GridView1_RowDataBound 方法里面。
示例:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex >= 0)
{
e.Row.Attributes.Add("id", "row" + this.GridView1.DataKeys[e.Row.RowIndex].Value.ToString().Trim());
e.Row.Cells[4].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
e.Row.Cells[0].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
e.Row.Cells[1].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
}
}