我想从我的内容页面将 html 表(不是网格)导出到 excel。我知道如何将网格导出到 excel。相同的方式还是不同的方式?
问问题
795 次
1 回答
2
尝试使用以下代码,这将对您有所帮助:
private void ExportToExcel(string strFileName,Table dg)
{
Response.Clear();
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
Response.ClearHeaders();
Response.AddHeader("content-disposition", "attachment;filename=" + strFileName + ".xls");
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dg.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
于 2012-07-12T05:40:05.173 回答