StringBuilder sbScript
=
new
StringBuilder();
sbScript.Append( " <script> " );
sbScript.Append( " window.open('ExportExcel.aspx','_perent' " );
sbScript.Append( " </script> " );
Page.RegisterStartupScript( "" ,sbScript.ToString());
sbScript.Append( " <script> " );
sbScript.Append( " window.open('ExportExcel.aspx','_perent' " );
sbScript.Append( " </script> " );
Page.RegisterStartupScript( "" ,sbScript.ToString());
ExportExcel.aspx.cs部分代码:
1
System.Web.HttpContext.Current.Response.Clear();
2 System.Web.HttpContext.Current.Response.Buffer = true ;
3 System.Web.HttpContext.Current.Response.Charset = " UTF-8 " ;
4 System.Web.HttpContext.Current.Response.ClearHeaders();
5 System.Web.HttpContext.Current.Response.AppendHeader( " Content-Disposition " , " attachment;filename= " + strFileName + " .xls " ); // attachment,下载;inline 在线打开
7 System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding( " UTF-8 " );
8 System.Web.HttpContext.Current.Response.ContentType = " application/ms-excel " ;
9 System.Web.HttpContext.Current.Response.Write(sbExcel.ToString()); // sbExcel:用于生成Excel的HTML代码
10 System.Web.HttpContext.Current.Response.Flush();
11 System.Web.HttpContext.Current.Response.End();
2 System.Web.HttpContext.Current.Response.Buffer = true ;
3 System.Web.HttpContext.Current.Response.Charset = " UTF-8 " ;
4 System.Web.HttpContext.Current.Response.ClearHeaders();
5 System.Web.HttpContext.Current.Response.AppendHeader( " Content-Disposition " , " attachment;filename= " + strFileName + " .xls " ); // attachment,下载;inline 在线打开
7 System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding( " UTF-8 " );
8 System.Web.HttpContext.Current.Response.ContentType = " application/ms-excel " ;
9 System.Web.HttpContext.Current.Response.Write(sbExcel.ToString()); // sbExcel:用于生成Excel的HTML代码
10 System.Web.HttpContext.Current.Response.Flush();
11 System.Web.HttpContext.Current.Response.End();