0

我使用以下代码将gridview导出到excel

System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
HtmlForm frm = new HtmlForm();

Response.ContentType = "application/vnd.ms-excel";


Response.Charset = "";
EnableViewState = false;
Controls.Add(frm);

frm.Controls.Add(this.myGridView);
frm.RenderControl(hw);

上述导出代码的来源

一切都像魅力一样。除了我现在必须在它导出到 Excel 之前对 gridview 进行更改。例如,一个变化是我需要删除一列。然而我不能这样做:

  //I can't remove columns here, since it has not been rendered yet and has 0 columns
  frm.Controls.Add(this.myGridView);
  frm.RenderControl(hw);

有没有办法在导出之前编辑 Gridview?例如。删除一列

4

0 回答 0