zoukankan      html  css  js  c++  java
  • 转:通过tableExport.js插件来实现导出Excel/Pdf/txt/json等

    Jquery tableExcel.js下载地址:https://github.com/kayalshri/tableExport.jquery.plugin
    
     
    
    tableExport.jquery.plugin
    
    导出的格式可以是:如下
    JSON
    XML
    PNG
    CSV
    TXT
    SQL
    MS-Word
    Ms-Excel
    Ms-Powerpoint
    PDF
    jquery Plugin(jquery插件添加)
     <script type="text/javascript" src="tableExport.js">
     <script type="text/javascript" src="jquery.base64.js">
    PNG Export(导出png需要添加插件)
     <script type="text/javascript" src="html2canvas.js">
    
    4.PDF Export(导出PDF需要添加插件)
    
     <script type="text/javascript" src="jspdf/libs/sprintf.js">
     <script type="text/javascript" src="jspdf/jspdf.js">
     <script type="text/javascript" src="jspdf/libs/base64.js">
    
    5.Usage(用法)
    
     onClick ="$('#tableID').tableExport({type:'pdf',escape:'false'});"
    
    6.Options(可选的属性)
    
     separator: ','
     ignoreColumn: [2,3],
     tableName:'yourTableName'
     type:'csv'
     pdfFontSize:14
     pdfLeftMargin:20
     escape:'true'
     htmlContent:'false'
     consoleLog:'false' 
    
     
    
    效果图
    
    
     
    
    
    
    
    
     
    
     
    
    实例代码
     
    
    <!--实现导出Excel的功能 -->
    
    <scripttype="text/javascript"src="./js/tableExport.js"></script>
    
    <scripttype="text/javascript"src="./js/FileSaver.min.js"></script>
    
    <scripttype="text/javascript"src="./js/jquery.base64.js"></script>
    
     
    
     
    
    1:导出Excel
    <inputonclick="export_excel()"id="btnExport1"type="submit"value="导出Excel">
    
    <scripttype="text/javascript">
    
    function export_excel(){
    
        $('#table_1').tableExport({type:'excel', fileName: new Date().getTime(), escape:'false', ignoreColumn:'[5]'});
    
    }
    
    </script>    
    
                    
    
    解析:
    
    $("#table_1").tableExport({…});//获取到所指定的表,将其导出
    
    即:$(表的id).tableExport({…});
    
    type:'excel',//将表导出的格式,这边为excel,也可以为txt/pdf/json/xml等
    
    fileName: new Date().getTime(),//设置导出的表的默认名称
    
    escape:'false', //这边设置为false
    
    ignoreColumn:'[5]'}//表示忽略列数,在这表示把第五列的数据给忽略掉,不在Excel中显示
    
     
    
    2:导出带有样式的Excel
     
    
    <inputonclick="$('#table_1').tableExport({type:'excel', fileName: new Date().getTime(), escape:'false', ignoreColumn:'[3]', excelstyles: ['background-color', 'color', 'font-weight', 'border']});"id="btnExport2"type="submit"value="Export to Formatted MS-Excel">
    
     
    
    3:导出txt                
     
    
    <inputonclick="$('#table_1').tableExport({type:'txt', fileName: new Date().getTime(), escape:'false', ignoreColumn:'[3]', });"id="btnExport3"type="submit"value="Export to CSV">
    
     
    
    <tableid="table_1"class="table table-bordered table-hover"style="margin-top:20px;">
    
    <thead>
    
    <thstyle="120px;">编号</th>
    
    <thstyle="220px;">账户名</th>
    
    <thstyle="220px;">昵称</th>
    
    <thstyle="150px;">创建时间</th>
    
    <thstyle="150px;">负责人</th>
    
    <th>操作</th>
    
    </thead>
    
    <tbodyclass="tbody"></tbody>
    
    </table>
    
     
    
    表中的数据是通过获取数据库中的数据进行显示的;
    
    测试时,可以在网页中自己添加一个<table>标签,添加一些内容,来替换后台获取的数据。
    --------------------- 
    作者:xingyuqihuan 
    来源:CSDN 
    原文:https://blog.csdn.net/xingyuqihuan/article/details/79139778 
    
  • 相关阅读:
    libyuv 代码结构分析,借用其NEON/ARM64优化代码
    Android 交叉编译 IPerf3
    Android Change TCP Congestion Control
    Unpack & Repack Android system.img & data.img
    Android can only be built by versions 3.81 and 3.82
    Build Android Kernel && Kernel Module
    换行符
    python之%s、%d、%f的使用
    Python+selenium 实现不定位元素,输入enter键
    进程间通信 (IPC) 方法总结(三)
  • 原文地址:https://www.cnblogs.com/yang1018/p/10118601.html
Copyright © 2011-2022 走看看