private void ToExcel(string html)
{
Response.ContentType = "application/force-download";
Response.AddHeader("content-disposition",
"attachment; filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
Response.Write("<head>");
Response.Write("<META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
string fileCss = Server.MapPath("~/UI/themes/DRP.UI.Ext.css");
string cssText = string.Empty;
StreamReader sr = new StreamReader(fileCss);
var line = string.Empty;
while ((line = sr.ReadLine()) != null)
{
cssText += line;
}
sr.Close();
Response.Write("<style>" + cssText + "</style>");
Response.Write("<!--[if gte mso 9]><xml>");
Response.Write("<x:ExcelWorkbook>");
Response.Write("<x:ExcelWorksheets>");
Response.Write("<x:ExcelWorksheet>");
Response.Write("<x:Name>Report Data</x:Name>");
Response.Write("<x:WorksheetOptions>");
Response.Write("<x:Print>");
Response.Write("<x:ValidPrinterInfo/>");
Response.Write("</x:Print>");
Response.Write("</x:WorksheetOptions>");
Response.Write("</x:ExcelWorksheet>");
Response.Write("</x:ExcelWorksheets>");
Response.Write("</x:ExcelWorkbook>");
Response.Write("</xml>");
Response.Write("<![endif]--> ");
Response.Write(html);//HTML
Response.Flush();
Response.End();
}
還可以看看
其他文章,謝謝您的閱讀。
網(wǎng)站申明:系本文編輯轉載,來(lái)源于網(wǎng)絡(luò ),目的在于傳遞更多信息,并不代表本網(wǎng)贊同其觀(guān)點(diǎn)和對其真實(shí)性負責,所有權歸屬原作者。如內容、圖片有任何版權問(wèn)題,請
聯(lián)系我們刪除。