导出excel打印

private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  {
   Response.Clear();
   Response.Buffer= true;
   
   Response.AppendHeader("Content-Disposition","attachment;filename=Borrow.xls");
   Response.ContentEncoding=System.Text.Encoding.GetEncoding("gb2312");

   Response.ContentType = "application/ms-excel";
   this.EnableViewState = false;
   
   System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
   System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
   System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); 
   
   Table3.RenderControl(oHtmlTextWriter);

   Response.Charset="gb2312";
   Response.Write(oStringWriter.ToString());
   Response.End();
  }

红色为导出文件名和要导出页面中的table

你可能感兴趣的:(导出Excel)