HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
StringBuilder strBld = new StringBuilder();
strBld.Append("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
strBld.Append("<head>");
strBld.Append("<!--[if gte mso 9]><xml>");
strBld.Append("<x:ExcelWorkbook>");
strBld.Append("<x:ExcelWorksheets>");
strBld.Append("<x:ExcelWorksheet>");
strBld.Append("<x:Name>sheet1</x:Name>");
strBld.Append("<x:WorksheetOptions>");
strBld.Append("<x:Print>");
strBld.Append("<x:ValidPrinterInfo/>");
strBld.Append("</x:Print>");
strBld.Append("</x:WorksheetOptions>");
strBld.Append("</x:ExcelWorksheet>");
strBld.Append("</x:ExcelWorksheets>");
strBld.Append("</x:ExcelWorkbook>");
strBld.Append("</xml>");
strBld.Append("<![endif]--> ");
strBld.Append("</head>");
strBld.Append("<body>");
HttpContext.Current.Response.Write(strBld.ToString());
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMdd") + ".xls");
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.Write("<meta http-equiv='content-type' content='application/ms-excel; charset=UTF-8'/>");
HttpContext.Current.Response.Write(contentHtml);
HttpContext.Current.Response.Write("</body></html>");
HttpContext.Current.Response.End();
contentHtml就是htmltable,比如:<table><tr><td>111</td></tr></table>