jQuery导出Excel格式

1、问题背景

     将一个表格的数据导出到Excel中,保证不出现中文乱码


2、实现源码

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>导出Excel格式</title>
		<script type="text/javascript" src="js/jquery-1.12.3.js" ></script>
		<script type="text/javascript" src="js/jquery.base64.js" ></script>
		<script type="text/javascript" src="js/tableExport.js" ></script>
		<script type="text/javascript" src="js/jspdf/libs/sprintf.js" ></script>
		<script type="text/javascript" src="js/jspdf/jspdf.js" ></script>
		<script type="text/javascript" src="js/jspdf/libs/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>
		<script>
			$(document).ready(function(){
				$("#exportData").click(function(){
					//导出
					$("#tables").tableExport({type:"excel",escape:"false"});
				});
			});
		</script>
	</head>
	<body>
		<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>
				<tr>
					<td>张三</td>
					<td>男</td>
					<td>34</td>
					<td>湖北省武汉市</td>
				</tr>
				<tr>
					<td>张三</td>
					<td>男</td>
					<td>34</td>
					<td>湖北省武汉市</td>
				</tr>
				<tr>
					<td>张三</td>
					<td>男</td>
					<td>34</td>
					<td>湖北省武汉市</td>
				</tr>
				<tr>
					<td>张三</td>
					<td>男</td>
					<td>34</td>
					<td>湖北省武汉市</td>
				</tr>
				<tr>
					<td>张三</td>
					<td>男</td>
					<td>34</td>
					<td>湖北省武汉市</td>
				</tr>
				<tr>
					<td>张三</td>
					<td>男</td>
					<td>34</td>
					<td>湖北省武汉市</td>
				</tr>
				<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="exportData" value="导出"/>
	</body>
</html>

3、实现结果

(1)初始化


(2)点击导出


(3)打开Excel


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/you23hai45/article/details/51483780
上一篇uncaught exception: INVALID_CHARACTER_ERR: DOM Exception 5
下一篇Caused by: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Tim
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭