zoukankan      html  css  js  c++  java
  • JS 将table导出为Excel文档

                <table id="dataTable"></table>
    
                <button onclick="tableToExcel()">导出当前页列表</button>

    <script> function tableToExcel() { var excelContent = $("#dataTable").html(); var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>"; excelFile += "<head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head>"; excelFile += "<body><table width='10%' border='1'>"; excelFile += excelContent.replace("height: 0px;", "height: 82px;"); excelFile += "</table></body>"; excelFile += "</html>"; var link = "data:application/vnd.ms-excel;base64," + base64(excelFile); var a = document.createElement("a"); a.download = $("#P_PlatformName option:selected").val() + timest() + ".xlsx"; a.href = link; a.click(); } function base64(content) { return window.btoa(unescape(encodeURIComponent(content))); } function timest() { var tmp = Date.parse(new Date()).toString(); tmp = tmp.substr(0, 10); return tmp; } </script>
  • 相关阅读:
    Augular JS里的各种ng-
    JS笔记1
    JQuery实战学习--在dreamweaver 8中配置Jquery自动提示
    android 设置桌面背景图片适应屏幕大小
    canvas实现进度条!
    Javascript之Prototype
    Sql Server 之 for xml (path,raw,auto,root)
    MVC 知识点学习3(linq to sql)
    MVC 知识点学习2
    MVC 知识点学习1
  • 原文地址:https://www.cnblogs.com/ZxtIsCnblogs/p/12786469.html
Copyright © 2011-2022 走看看