不適用于GridView
public void ToExcel(System.Web.UI.Control ctl)
{
Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("Big5");
Response.ContentType = "application/ms-excel";
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new StringWriter();
System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
public void OnClick(object sender, EventArgs e)
{
ToExcel(datagrid);
}
阅读(1426) | 评论(0) | 转发(0) |