请问js如何将html内的table导出为excel表格?
网友回复
jquery有个插件叫table2excel,使用示例代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery.table2excel.min.js"></script>
<style>
#score tr:first-child td {
font-weight: 600;
}
p {
margin: 0;
margin-top: 10px;
}
#export {
margin-top: 10px;
}
</style>
</head>
<body>
<table id="score" cellspacing="0" cellpadding="0" border="1" solid="#000000">
<tr>
<td class="td0">姓名</td>
<td class="td1">班级</td>
<td class="td2">数学成绩</td>
<td class="td3">历史成绩</td>
</tr>
<tr>
<td class="td0">张三</td>
<td class="td1">1</td>
<td class="td2">65</td>
<td class="td3">83</td>
</t...点击查看剩余70%
原生js的写法也简单,代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>BFW NEW PAGE</title>
<script type="text/javascript">
function tableToExcel(tableID, fileName) {
var table = document.getElementById(tableID);
var excelContent = table.innerHTML;
var head="head";
var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
excelFile += "<"+head+"><meta charset='UTF-8'><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head>";
excelFile += "<body><table>";
excelFile += excelContent;
excelFile += "</table></body>";
excelFile += "</html>";
console.log(excelFile)
var link = "data:application/vnd.ms-excel;base64," + base64(excelFile);
var a = document.createElement("a");...点击查看剩余70%
如何让ai帮我自动在小红书或抖音上自动根据需求截流与潜在客户聊天拉客?
如果用go编写一个在virtualbox中启动的简单操作系统?
go如何搭建一个零信任网络?
如何用python实现一个公网代理访问软件?
如何用go实现一个公网代理访问软件?
如何用python实现一个内网穿透打洞程序,实现内网的80端口暴露到公网上可以访问?
如何用go实现一个内网穿透打洞程序,实现内网的80端口暴露到公网上可以访问?
何为Shadowsocks 代理?
python如何实现类似php的opendir目录相互隔离的fastcgi多租户虚拟空间?
nodejs如何实现类似php的opendir目录相互隔离的fastcgi多租户虚拟空间?


