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>标签,添加一些内容,来替换后台获取的数据。


相关文章:

  • 2021-08-03
  • 2021-05-30
  • 2022-12-23
  • 2021-10-26
  • 2022-01-21
  • 2021-12-28
  • 2021-08-20
猜你喜欢
  • 2022-12-23
  • 2021-12-28
  • 2021-12-14
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案