日期:2014-05-17 浏览次数:20435 次
public void ExportResult(DataTable dt, string excelName)
{
Response.Clear();
Response.Charset = "";
Response.ContentType = "applicationnd.ms-xls";
StringWriter sw = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(sw);
DataGrid dg = new DataGrid();
dg.DataSource = dt;
dg.DataBind();
dg.RenderControl(htmlWrite);
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(excelName));
Response.Write(sw.ToString());
Response.End();
}
/// <summary>
/// 导出Excel
/// </summary>
protected void btn_exl_Click(object sender, EventArgs e)
{
ToExcel();
}
//必须有 不然会出错
public override void VerifyRenderingInServerForm(Control control)
{
}