通过tableExport.js插件来实现导出Excel/Pdf/txt/json等

Jquery tableExcel.js下载地址:https://github.com/kayalshri/tableExport.jquery.plugin

 

tableExport.jquery.plugin

  1. 导出的格式可以是:如下
  • JSON
  • XML
  • PNG
  • CSV
  • TXT
  • SQL
  • MS-Word
  • Ms-Excel
  • Ms-Powerpoint
  • PDF
  1. jquery Pluginjquery插件添加)
     <script type="text/javascript" src="tableExport.js">
     <script type="text/javascript" src="jquery.base64.js">
  2. 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="width:120px;">编号</th>

<thstyle="width:220px;">账户名</th>

<thstyle="width:220px;">昵称</th>

<thstyle="width:150px;">创建时间</th>

<thstyle="width:150px;">负责人</th>

<th>操作</th>

</thead>

<tbodyclass="tbody"></tbody>

</table>

 

表中的数据是通过获取数据库中的数据进行显示的;

测试时,可以在网页中自己添加一个<table>标签,添加一些内容,来替换后台获取的数据。


评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值