您的位置:首页 > 其它

table导出到excel的两种方法

2016-09-29 16:16 267 查看
1. 用table2excel 的js文件,这种方法没有IE兼容性

需要在文件中导入

<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.2.min.js"></script>
<script src="<%=request.getContextPath()%>/js/jquery.table2excel.js"></script>


然后再文件中写方法

function exportexcel(){
$("#tableServer").table2excel({
exclude: ".noExl",
name: "Excel Document Name",
filename: "myFileName",
exclude_img: true,
exclude_links: true,
exclude_inputs: true
});
}


2. js代码

function ExportToExcel() {
var elTable = document.getElementById("tableServer"); //你的tableID
var oRangeRef = document.body.createTextRange();
oRangeRef.moveToElementText(elTable);
oRangeRef.execCommand("Copy");
try {
var appExcel = new ActiveXObject("Excel.Application");
} catch (e) {
alert("If you change your mind, refresh your page  and select 'yes' to download excel.");
return;
}
appExcel.Visible = true;
appExcel.Workbooks.Add().Worksheets.Item(1).Paste();
appExcel = null;
}


jsp代码

<a href="javascript:void(0);" onclick="javascript:ExportToExcel()">
<img src="${pageContext.request.contextPath}/style/images/excel6.jpg"   width=20px height=20px style="padding-top:15px"/>
</a>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: