我將不用的列用GridView.Columns.Visible = false;隱藏,接著再導(dǎo)出excel。
發(fā)現(xiàn)隱藏其他的列都沒事,就是一旦隱藏那些包含超出11位數(shù)字的列時,導(dǎo)出的excel就會亂碼。
(不知道是不是跟excel中數(shù)字超過11位就用科學(xué)計算法表示有關(guān),可是我在導(dǎo)出前都將其轉(zhuǎn)化為文字式數(shù)字時依然有這個問題。)
求遇到過相同的問題以及知道解決辦法的大神幫幫忙。
設(shè)置gridview的RowdataBound代碼如下
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { GridView1.Columns[5].Visible = false;//這里隱藏列中有數(shù)字超過11位的 foreach (TableCell tc in e.Row.Cells) { tc.Attributes["style"] = "border-color:Black"; } if (e.Row.RowIndex != -1) { int id = GridView1.PageIndex * GridView1.PageSize + e.Row.RowIndex + 1; e.Row.Cells[0].Text = id.ToString(); } for (int i = 0; i < e.Row.Cells.Count; i++) { if (e.Row.RowType == DataControlRowType.DataRow) e.Row.Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat:@"); } }
- 1 回答
- 0 關(guān)注
- 301 瀏覽
添加回答
舉報
0/150
提交
取消