网页表格导出excel表格第二种方法
需要引入jquery.table2excel组件,jquery.table2excel下载地址:https://github.com/rainabba/jquery-table2excel/blob/master/src/jquery.table2excel.js
DEMO代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div>
<script type="text/javascript" src="ui/jquery.js"></script>
<script type="text/javascript" src="jquery.table2excel.js"></script>
<table class="table2excel">
<tr>
<th>生产厂家</th>
<th>产品名称</th>
<th>...</th>
<th> class="noExl">操作</th>
</tr>
<tr>
<td>厂家1<td>
<td>产品1<td>
<td>...<td>
<td class="noExl"><button>删除</button><button>修改</button><td>
</tr>
<tr>
<td>厂家2<td>
<td>产品2<td>
<td>...<td>
<td class="noExl"><button>删除</button><button>修改</button><td>
</tr>
</table>
<table>
<tr>
<td>
<input type="button" value="导出到excel中" class="btn btn-primary" onclick="table2Excel('出库信息明细.xls')"/>
</td>
</tr>
</table>
</div>
<script>
//filename 导出的excel文件名
//方法可带filename参数,亦可不带参数直接定义
function table2Excel(filename){
$(".table2excel").table2excel({
exclude: ".noExl",//class="noExl"的列不导出
name: "Excel Document Name",
filename: filename,//文件名称
fileext: ".xls",//文件后缀名
exclude_img: true,//导出图片
exclude_links: true,//导出超链接
exclude_inputs: true//导出输入框内容
});
}
</script>
</body>
</html>
浙公网安备 33010602011771号