zoukankan      html  css  js  c++  java
  • execl导出(HTML,repearter控件)

    protected void btn_execl_Click(object sender, EventArgs e)
            {
                Response.Clear();
                Response.Buffer = true;
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMdd") + ".xls");
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                Response.ContentType = "application/vnd.ms-excel";
                this.EnableViewState = false;
              //Export("application / force - download", "测试.xls");
            }

    注意:只是转成execl文件的格式,页面不是表格。

      function getBodyHtml() {
                  var html = $("html").html();
                      //$("html").html();
                      //$("#html_container").html();
                  $("#hfHtml2Excel").val(html);        
              }

    <asp:Button ID="btnExportExcel" runat="server" Text="To Excel" OnClick="btnExportExcel_Click" OnClientClick="return getBodyHtml();"/>

     protected void btnExportExcel_Click(object sender, EventArgs e)
            {
                string html = hfHtml2Excel.Value;

                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">");


                #region 样式的读取

                //string fileCss = System.AppDomain.CurrentDomain.BaseDirectory +"template/stock_summary.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>");

                #endregion

                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();

            }

  • 相关阅读:
    CodeForces979D:Kuro and GCD and XOR and SUM(Trie树&指针&Xor)
    HDU4188:RealPhobia (连分数的运用之一)
    从HDU2588:GCD 到 HDU5514:Frogs (欧拉公式)
    SPOJ:Eagle and Dogs(求树上每个点最远可以走到哪里---树的直径||DP)
    【字符串】BZOJ上面几个AC自动机求最为字串出现次数的题目
    codeforces round #405 B. Bear and Friendship Condition
    codeforces round #419 C. Karen and Game
    codeforces round #419 B. Karen and Coffee
    codeforces round #419 A. Karen and Morning
    【ZOJ 3609】Modular Inverse 最小乘法逆元
  • 原文地址:https://www.cnblogs.com/suan1717/p/7840091.html
Copyright © 2011-2022 走看看