第一种:(导出格式:csv、txt、excel、word、png)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <div> <ul class="dropdown-menu"> <li> <a οnclick="$('#stats_datatable').tableExport({type:'csv',escape:'false',filename:'(2016-02-29_2016-03-06)'});" href="#"> 导出格式-CSV </a> </li> <li> <a οnclick="$('#stats_datatable').tableExport({type:'txt',escape:'false',filename:'(2016-02-29_2016-03-06)'});" href="#"> 导出格式-TXT </a> </li> <li> <a οnclick="$('#stats_datatable').tableExport({type:'excel',escape:'false',filename:'(2016-02-29_2016-03-06)'});" href="#"> 导出格式-Excel </a> </li> <li> <a οnclick="$('#stats_datatable').tableExport({type:'doc',escape:'false',filename:'(2016-02-29_2016-03-06)'});" href="#"> 导出格式-Word </a> </li> <li> <a οnclick="$('#stats_datatable').tableExport({type:'png',escape:'false',filename:'(2016-02-29_2016-03-06)'});" href="#"> 导出格式-PNG </a> </li> </ul> </div> <div class="panel-body"> <table id="stats_datatable" class="table datatable"> <thead> <tr> <th>名称</th> <th>里程</th> <th>次数</th> <th>天数</th> <th>签到</th> <th>活动</th> <th>时间周期</th> <th>更新时间</th> </tr> </thead> <tbody></tbody> </table> </div> <!-- START SCRIPTS --> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <!-- 数据表 --> <script src="js/tableExport.js"></script> <script src="js/mybase.js"></script> <script> $(function () { //=======让解码后中文不出现乱码的方法 data = $.base64({ data: "已经编码过后的base64", type: 1, unicode: true }); //=或 data = $.base64({ data: "已经编码过后的base64", type: 1 }); console.log(data); //downloadFile("myexcel.xls", data); }); </script> </body> </html>
第二种:(导出数据量少的情况导出带样式的)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>数据量少的情况导出带样式的</title> <style> table td { font-size: 12px; width: 200px; height: