1 public void ToExcel(System.Web.UI.Control ctl, string c,string keyword)
2 {
3 try
4 {
5 if (c == "1")
6 {
7 //导出的名字
8 HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=ProductExcel.xls");
9 }
10 if (c == "0")
11 {
12 HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=TradeExcel.xls");
13 }
14 if (c == "2")
15 {
16 HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Province.xls");
17 }
18 HttpContext.Current.Response.Charset = "utf-8";
19 HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
20 HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
21 ctl.Page.EnableViewState = false;
22 System.IO.StringWriter tw = new System.IO.StringWriter();
23 System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
24 ctl.RenderControl(hw);
25 HttpContext.Current.Response.Write(tw.ToString());
26 HttpContext.Current.Response.End();
27 }
28 catch(Exception ex)
29 {
30 // System.Web.HttpContext.Current.Response.Write(ex.ToString());
31 }
32 }
2 {
3 try
4 {
5 if (c == "1")
6 {
7 //导出的名字
8 HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=ProductExcel.xls");
9 }
10 if (c == "0")
11 {
12 HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=TradeExcel.xls");
13 }
14 if (c == "2")
15 {
16 HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Province.xls");
17 }
18 HttpContext.Current.Response.Charset = "utf-8";
19 HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
20 HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
21 ctl.Page.EnableViewState = false;
22 System.IO.StringWriter tw = new System.IO.StringWriter();
23 System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
24 ctl.RenderControl(hw);
25 HttpContext.Current.Response.Write(tw.ToString());
26 HttpContext.Current.Response.End();
27 }
28 catch(Exception ex)
29 {
30 // System.Web.HttpContext.Current.Response.Write(ex.ToString());
31 }
32 }