我正在使用GridView將表格導出到Excel。單元格填充不起作用
我有這個在我的控制器:
GridView gv = new GridView();
gv.DataSource = lstExportedExcel.ToList(); // lstExportedExcel does have stuff in it
gv.DataBind();
gv.HeaderRow.Cells[0].BackColor = System.Drawing.Color.LightCyan;
gv.HeaderRow.Cells[1].BackColor = System.Drawing.Color.LightCyan;
gv.HeaderRow.Cells[2].BackColor = System.Drawing.Color.LightCyan;
gv.HeaderRow.Cells[3].BackColor = System.Drawing.Color.LightCyan;
gv.HeaderRow.Cells[4].BackColor = System.Drawing.Color.LightCyan;
gv.HeaderRow.Cells[5].BackColor = System.Drawing.Color.LightCyan;
gv.HeaderRow.Cells[6].BackColor = System.Drawing.Color.LightCyan;
gv.HeaderRow.Cells[7].BackColor = System.Drawing.Color.LightCyan;
gv.HeaderRow.Cells[8].BackColor = System.Drawing.Color.LightCyan;
gv.HeaderRow.Cells[9].BackColor = System.Drawing.Color.LightCyan;
gv.HeaderRow.Cells[10].BackColor = System.Drawing.Color.LightCyan;
gv.HeaderRow.Cells[11].BackColor = System.Drawing.Color.LightCyan;
gv.HeaderRow.Cells[12].BackColor = System.Drawing.Color.LightCyan;
gv.CellPadding = 10; //doesn't work
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=DailySummaryExport.xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
我已經做了研究這一點,很多解決方案都在前端,但我如何得到這個工作?當我打開Excel電子表格時,每個單元格中的文本都沒有從默認邊框獲取填充。
任何幫助表示讚賞。
您必須更加明確,試試這個: http://stackoverflow.com/questions/316931/how-to-define-cellpadding-in-gridview-in-asp- net – IrishChieftain
@IrishChieftain我沒有這個* gridview *的特定視圖,這個gridview正在被創建,所以我將如何獲得* CSS *的工作?GridView有一個* CssClassName *屬性..但我失去了如何使這項工作 –