上篇写的是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. UVa 658 - It's not a Bug, it's a Feature!(Dijkstra + 隐式图搜索)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. cv2.resize

    import cv2 img = cv2.imread('0_116_99_355_0.jpg') # 方法一: # res = cv2.resize(img,None,fx=2,fy=2,inter ...

  3. 【[HNOI2004]L语言】

    \(Trie\)树+\(DP\) 我们只需要做一个存在性dp就好了 对于每一个字符串,我们设\(f[i]\)表示从\(1\)到\(i\)位是否能被完全匹配 首先\(f[0]=1\),之后我们对于每一个 ...

  4. mac 系统安装selenium注意事项

    mac最新系统:OS X EI Captian python: 本机自带的python2.7. (本来想升级3.5,觉得太复杂,放弃了) pip: https://pypi.python.org/py ...

  5. 使用Redis存取数据+数据库存取(spring+java)

    RoleMapper接口: package com.wbg.springRedis.dao; import com.wbg.springRedis.entity.Role; import org.sp ...

  6. HDU 2082 找单词 (普通型 数量有限 母函数)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2082 找单词 Time Limit: 1000/1000 MS (Java/Others)    Me ...

  7. Xcode7解决VVDocumenter 不能使用的方案

    Xcode7解决VVDocumenter 不能使用的方案 VVDocumenter-Xcode是Xcode上一款快速添加标准注释,并可以自动生成文档的插件.有了VVDocumenter-Xcode,规 ...

  8. LeetCode22.括号生成 JavaScript

    给出 n 代表生成括号的对数,请你写出一个函数,使其能够生成所有可能的并且有效的括号组合. 例如,给出 n = 3,生成结果为: [ "((()))", "(()())& ...

  9. REST解惑

    本文是「架构风格:你真的懂REST吗?」的补充! REST全称是Representational State Transfer,目前普遍接受的中文翻译为「表述性状态转移」! 即使翻译过来了,你依然有一 ...

  10. 使用PLSQL客户端登录ORACLE时报ORA-12502和ORA-12545错误的解决方案

    当使用plsqldev客户端登录oracle数据库时,如果对应的tnsnames.ora中是直接使用IP地址来连接,并且未在系统的hosts文件中绑定主机名时,极易出现ORA-12502及ORA-12 ...