我正在使用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 *属性..但我失去了如何使这项工作 –