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

            }

  • 相关阅读:
    RealView MDK在链接时提示空间不够的解决方案总结
    不同的LCD之间程序移植时配置参考
    S3c2440ALCD控制器配置实例
    mini2440裸机之PWM
    对增益大于等于10时保持稳定的放大器进行补偿以在较低增益下工作
    ASP.NET HttpContext的时间戳属性
    C#验证邮箱,电话,手机,数字,英文,日期,身份证,邮编,网址,IP类.. (转)
    sqlhelper 实现回滚事务
    JQuery全选和反选
    js 获取前天、昨天、今天、明天、后天的时间 (转)
  • 原文地址:https://www.cnblogs.com/suan1717/p/7840091.html
Copyright © 2011-2022 走看看