通過向頁面寫html代碼匯出excel

來源:互聯網
上載者:User

標籤:

 1 //excel檔案名稱 2 string filename = "考勤匯總"; 3 StringBuilder ExcelHtml = new StringBuilder(); 4 ExcelHtml.Append("<table border=‘1‘ style=‘vnd.ms-excel.numberformat:@‘>"); 5 //拼接<tr><th></th></tr>第一列名 6 //迴圈拼接<tr><td></td></tr>每一行的內容 7 ExcelHtml.Append("</table>"); 8 DownloadExcelByTtml(ExcelHtml.ToString(), filename); 9 10 11 /// <summary>12 /// 下載 Excel13 /// </summary>14 /// <param name="ExcelHtml"></param>15 /// <param name="filename"></param>16 /// <returns></returns>17 public void DownloadExcelByTtml(string ExcelHtml, string filename)18 {19     Page p = HttpContext.Current.Handler as Page;20     p.Response.Clear();21     p.Response.Buffer = true;22     p.Response.Charset = "UTF-8";23     p.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, Encoding.UTF8) + ".xls");24     p.Response.ContentEncoding = Encoding.UTF8;25     p.Response.ContentType = "application/vnd.ms-excel";26     p.EnableViewState = false;27     p.Response.Write("<html><head><meta http-equiv=‘Content-Type‘ content=‘application/vnd.ms-excel; charset=utf-8‘ /></head>" + ExcelHtml + "</html>");28     p.Response.End();29 }

 

通過向頁面寫html代碼匯出excel

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.