上篇写的是jQuery 导出word,就试试导出excel。看见网上写的很乱,我这就把我写的整理下来,有部分来自网上capy

1.   js文件的引用

<script type="text/javascript" src="/resources/jQuery/jquery.min.js"></script>
<script type="text/javascript" src="/resources/lib/tableExport/tableExport.js"></script>
<script type="text/javascript" src="/resources/lib/encrypt/base64.js"></script>

网上找js很麻烦,这有链接

tableExport.js :  https://github.com/hhurz/tableExport.jquery.plugin

base64.js  :https://github.com/davidchambers/Base64.js

 2.要导出的数据(页面展示样式)

<%-- 表格的样式--%>
<style>
html,body{
width: 99%;
height: 99%;
font-family: "微软雅黑";
font-size: 12px;
}
#tables{
width: 100%;
text-align: center;
border: 1px #000 solid;
border-collapse: collapse;
}
#tables th,#tables td{
border: 1px solid #000000;
}
#tables th{
font-size: 14px;
font-weight: bolder;
}
</style>
<%-- 表格 (具体样式看上图)--%>
<table id="tables">
<thead>
<tr>
<th>姓名</th>
<th>性别</th>
<th>年龄</th>
<th>地址</th>
</thead>
<tbody>
<tr>
<td>张三</td>
<td>男</td>
<td></td>
<td>湖北省武汉市</td>
</tr>
<tr>
<td>张三</td>
<td>男</td>
<td></td>
<td>湖北省武汉市</td>
</tr>
</tbody>
</table> <input type="button" id="export" value="导出"/>

3. jquery的tableExport应用

<script>
$(document).ready(function(){
$("#export").click(function(){
//导出
$("#tables").tableExport({type:"excel",escape:"false"});
});
});
</script>

完整代码:  (更改js路径后,复制可直接使用)

<script type="text/javascript" src="/resources/jQuery/jquery.min.js"></script>
<script type="text/javascript" src="/resources/lib/tableExport/tableExport.js"></script>
<script type="text/javascript" src="/resources/lib/encrypt/base64.js"></script>
<%----%>
<style>
html,body{
width: 99%;
height: 99%;
font-family: "微软雅黑";
font-size: 12px;
}
#tables{
width: 100%;
text-align: center;
border: 1px #000 solid;
border-collapse: collapse;
}
#tables th,#tables td{
border: 1px solid #000000;
}
#tables th{
font-size: 14px;
font-weight: bolder;
}
</style>
<table id="tables">
<thead>
<tr>
<th>姓名</th>
<th>性别</th>
<th>年龄</th>
<th>地址</th>
</thead>
<tbody>
<tr>
<td>张三</td>
<td>男</td>
<td>34</td>
<td>湖北省武汉市</td>
</tr>
<tr>
<td>张三</td>
<td>男</td>
<td>34</td>
<td>湖北省武汉市</td>
</tr> </tbody>
</table>
<input type="button" id="export" value="导出"/>
</body>
<script>
$(document).ready(function(){
$("#export").click(function(){
//导出
$("#tables").tableExport({type:"excel",escape:"false"});
});
});
</script>

  


扩展:导出文件的名字不能自定义,在这里我们更改下tableExport.js 的代码

原代码:

 $.fn.tableExport = function (options) {
var defaults = {
consoleLog: false,
csvEnclosure: '"',
csvSeparator: ',',
csvUseBOM: true,
displayTableName: false,
escape: false,
excelFileFormat: 'xlshtml',
excelRTL: false,
excelstyles: [],
exportHiddenCells: false,
fileName: 'tableExport', // 这里就是导出文件名字
htmlContent: false,
ignoreColumn: [],

改后的代码:

$.fn.tableExport = function (options,fileName) {  //这里添加参数,接受自定义名字
var defaults = {
consoleLog: false,
csvEnclosure: '"',
csvSeparator: ',',
csvUseBOM: true,
displayTableName: false,
escape: false,
excelFileFormat: 'xlshtml',
excelRTL: false,
excelstyles: [],
exportHiddenCells: false,
fileName: fileName == undefined?'tableExport':fileName, //这里判断文件名字是否存在,如果存在就是用自定义,不存在就默认 tableExport.xls htmlContent: false, ignoreColumn: [], ignoreRow: [],

前台引用更改为:

<script>
$(document).ready(function(){
$("#export").click(function(){
//导出
$("#tables").tableExport({type:"excel",escape:"false"},'自定义名字');
});
});
</script>

=====================***加更***=====================

1.导出文件的名字:

原来的js已经提供了自定义变量名的接口可以这样写的 (2楼 朱光轻吻
$("#tables").tableExport({type:"excel",escape:"false",fileName:"自定义名字"});
 
 

如有更好的请留言。。

jQuery tableExport导出 excel的更多相关文章

  1. jquery插件导出excel和pdf(解决中文乱码问题)

    参考文件:http://jackyrong.iteye.com/blog/2169683 https://my.oschina.net/aruan/blog/418980 https://segmen ...

  2. JQuery 导入导出 Excel

    正在做一个小项目, 从数据库中查询数据放在 HTML Table 中. 现在想要从这个 table 中导出数据来. 另外用户需要选择导出的列. 使用 jQuery 的导出插件可以完成这个需求. jQu ...

  3. Jquery.Datatables 导出excel

    按钮(Buttons) BUttons v1.1.2 下载地址:http://pan.baidu.com/s/1c0Jhckg JSZip v2.5.0-21-g4fd4fc1 下载地址:http:/ ...

  4. javascript 将 table 导出 Excel ,可跨行跨列

    <script language="JavaScript" type="text/javascript"> //jQuery HTML导出Excel ...

  5. jquery导出Excel表格

    1.引用js插件 <script src="tableExport.js"></script> <script src="jquery.ba ...

  6. 导出Excel/Pdf/txt/json/XML/PNG/CSV/SQL/MS-Word/ Ms-Powerpoint/等通过tableExport.js插件来实现

    首先去我的云盘下载需要的js: 链接:https://pan.baidu.com/s/13vC-u92ulpx3RbljsuadWw 提取码:mo8m 页面代码: <!DOCTYPE html& ...

  7. Jquery easyui datagrid 导出Excel

    From:http://www.cnblogs.com/weiqt/articles/4022399.html datagrid的扩展方法,用于将当前的数据生成excel需要的内容. 1 <sc ...

  8. C# 或 JQuery导出Excel

    首先要添加NPOI.dll文件 然后添加类:NPOIHelper.cs using System; using System.Data; using System.Configuration; usi ...

  9. [转]tableExport.js 导出excel 如果有负数或是空值 导出前面会自动加上单引号

    原文地址:https://blog.csdn.net/private66/article/details/88718285 tableExport.js  导出excel  如果有负数或是空值 导出前 ...

随机推荐

  1. Django 查询集的过滤内置条件

    条件选取querySet的时候,filter表示=,exclude表示!=.querySet.distinct() 去重复__exact 精确等于 like 'aaa' __iexact 精确等于 忽 ...

  2. CoreAnimation confusion: CATransaction vs CATransition vs CAAnimationGroup?

    http://stackoverflow.com/questions/14042755/coreanimation-confusion-catransaction-vs-catransition-vs ...

  3. js 实现分享功能

    分享功能初步测试,title为当前页面的title. 其他详见注释!!! <!doctype html> <html> <head> <meta http-e ...

  4. Intellij IDEA如何删除项目

    1.      删除某个项目 1)       选中项目,并关闭 2)       File-Open,再选中相应的项目,并delete即可,它会同时在硬盘上删除

  5. Git--将服务器代码更新到本地

    1. git status(查看本地分支文件信息,确保更新时不产生冲突) 2. git checkout -- [file name] (若文件有修改,可以还原到最初状态; 若文件需要更新到服务器上, ...

  6. Gradle Goodness: Set Java Compiler Encoding

    If we want to set an explicit encoding for the Java compiler in Gradle we can use the options.encodi ...

  7. python 输入一个整数,判断其是否既是3的倍数,又是5的倍数

    v = int(input('请输入一个整数:')) if v % 3 == 0 and v % 5 ==0: print(v,'即是3的倍数又是5的倍数') else: print('不是3或5的倍 ...

  8. module.exports与exports的联系与区别

    首先说明他们是啥? 在CommonJS规范中,exports和module.exports这两个对象是把某一模块化文件中的属性和方法暴露给外部模块的接口(说法可能不准确),外部模块通过require引 ...

  9. ABAP术语-Transaction

    Transaction 原文:http://www.cnblogs.com/qiangsheng/archive/2008/03/19/1112804.html Logical process in ...

  10. jar包导入本地maven库的操作

    pom文件配置格式: <dependency> <groupId>A</groupId> <artifactId>B</artifactId> ...