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

            }

  • 相关阅读:
    cocos2dx-基本动画制作
    cocos2dx-CCScrollView的制作
    回调函数的作用
    cocos2dx-Action动作
    cocos2dx-cpptest的结构
    重载函数
    .h和.cpp的用法与区别
    NDK配置之体会
    Cocos2d-x 3.1 内存管理机制
    idea spring boot
  • 原文地址:https://www.cnblogs.com/suan1717/p/7840091.html
Copyright © 2011-2022 走看看