C#将html table 导出成excel

 1     public void ProcessRequest (HttpContext context) {
 2 
 3        string elxStr = "<table><tbody><tr><td>1</td><td>11</td></tr><tr><td>2</td><td>22</td></tr></tbody></table>";
 4        context.Response.Clear();
 5        context.Response.Buffer = true;
 6        context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMdd") + ".xls");
 7        context.Response.ContentEncoding = System.Text.Encoding.UTF8;
 8        context.Response.ContentType = "application/vnd.ms-excel";
 9        context.Response.Write(elxStr);
10        context.Response.End();
11     }
12  
13     public bool IsReusable {
14         get {
15             return false;
16         }
17     }

 

posted @ 2013-04-18 10:29  Servant  阅读(1073)  评论(0编辑  收藏  举报