请问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%
Cloudflared 和WARP Connector有啥不同?
有没有让本地开源大模型越狱的方法或插件啥的?
如何使用Zero Trust的Tunnels技术将局域网电脑web服务可以公网访问呢?
编程领域ai大模型的排名是怎么样的?
如何修改别人发给我的微信笔记内容?
fbx、obj、glb三维格式模型如何在浏览器中通过three相互转换格式?
python如何实现基于http隧道加密的正向代理服务?
有没有有专门针对 UI 界面截图进行智能标记(Set-of-Mark, SoM) 的开源库和工具?
如何用python实现Set-of-Mark (SoM) 技术?
python如何截取windows指定应用的窗口截图,不用管窗口是不是在最前面?


