jQuery tableExport导出 excel
上篇写的是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.导出文件的名字:
$("#tables").tableExport({type:"excel",escape:"false",fileName:"自定义名字"});
如有更好的请留言。。
jQuery tableExport导出 excel的更多相关文章
- jquery插件导出excel和pdf(解决中文乱码问题)
参考文件:http://jackyrong.iteye.com/blog/2169683 https://my.oschina.net/aruan/blog/418980 https://segmen ...
- JQuery 导入导出 Excel
正在做一个小项目, 从数据库中查询数据放在 HTML Table 中. 现在想要从这个 table 中导出数据来. 另外用户需要选择导出的列. 使用 jQuery 的导出插件可以完成这个需求. jQu ...
- Jquery.Datatables 导出excel
按钮(Buttons) BUttons v1.1.2 下载地址:http://pan.baidu.com/s/1c0Jhckg JSZip v2.5.0-21-g4fd4fc1 下载地址:http:/ ...
- javascript 将 table 导出 Excel ,可跨行跨列
<script language="JavaScript" type="text/javascript"> //jQuery HTML导出Excel ...
- jquery导出Excel表格
1.引用js插件 <script src="tableExport.js"></script> <script src="jquery.ba ...
- 导出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& ...
- Jquery easyui datagrid 导出Excel
From:http://www.cnblogs.com/weiqt/articles/4022399.html datagrid的扩展方法,用于将当前的数据生成excel需要的内容. 1 <sc ...
- C# 或 JQuery导出Excel
首先要添加NPOI.dll文件 然后添加类:NPOIHelper.cs using System; using System.Data; using System.Configuration; usi ...
- [转]tableExport.js 导出excel 如果有负数或是空值 导出前面会自动加上单引号
原文地址:https://blog.csdn.net/private66/article/details/88718285 tableExport.js 导出excel 如果有负数或是空值 导出前 ...
随机推荐
- 51nod 1019 逆序数(逆序数+离散化)
在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序.一个排列中逆序的总数就称为这个排列的逆序数. 如2 4 3 1中,2 1,4 3,4 1,3 1是 ...
- BZOJ1614:[USACO]Telephone Lines架设电话线(二分,最短路)
Description FarmerJohn打算将电话线引到自己的农场,但电信公司并不打算为他提供免费服务.于是,FJ必须为此向电信公司 支付一定的费用.FJ的农场周围分布着N(1<=N< ...
- js算法排序
一.选择算法排序(算法时间复杂度为O(n²)级别) 选择排序就是选择数组中的最小的树,依次排序.第一次选择最小的数放在第一位,第二次从剩余的元素中寻找最小的元素放在第二位,第三次在剩余的数中选择最小的 ...
- uiwebview与objective-c
利用oc调用js很简单, 系统直接提供了方法stringByEvaluatingJavaScriptFromString [webView stringByEvaluatingJavaScriptFr ...
- UE4 Navmesh 室内导航设置
我用的UE版本是4.14.1 系统:win10 64 前不久给样板房里面做了一个扫地机器人,导航设置让我头大了很久,度娘也没有用,最后在谷哥上有所感悟,现在给出本人的设置过程和解决方案. 一开始拖 ...
- mysql 使用order by
1.mysql 使用order by field() 自定义排序 order by field(value,str1,str2,str3,str4......strn) 例如:select * fro ...
- Cannot set HTTP gem source: “source https://rubygems.org not present in cache”
My ruby version in Windows 10: > ruby -v ruby 2.3.1p112 (2016-04-26 revision 54768) [i386-mingw32 ...
- JavaScript字符串的处理方法
1.字符方法charAt()和charCodeAt();这两个方法都接收一个参数 var stringValue = "hello world"; stringValue.char ...
- js实现点击按钮可实现编辑
<script type="text/javascript">//修改密码//抓取到的数据 function edit() { document.getElementB ...
- C++分享笔记:扑克牌的洗牌发牌游戏设计
笔者在大学二年级期间,做过的一次C++程序设计:扑克牌的洗牌发牌游戏.具体内容是:除去大王和小王,将52张扑克牌洗牌,并发出5张牌.然后判断这5张牌中有几张相同大小的牌,是否是一条链,有几个同花等. ...