在Django中有一个html模板,用于显示数据,在显示完成后希望通过JavaScript命令将模板上的表格导出到excel文件中,已添加了xlsx.full.min.js包,数据显示也没问题,但是点击页面上button,没有任何相应,请各位指点。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h2>年度实践环节经费预算统计表</h2>
<hr>
<table align="center" border="1" id="TableToExport">
<tr>
<th>环节名称</th>
<th>周数</th>
<th>学分</th>
<th>专业</th>
<th>班级</th>
<th>人数</th>
<th>实习地点</th>
<th>实习形式</th>
<th>标准</th>
<th>经费预算</th>
<th>指导教师人数</th>
<th>备注</th>
</tr>
{% for budget in budgets %}
<tr>
<td>[{{ budget.classID }}]{{ budget.name }}</td>
<td>{{ budget.weeks }}</td>
<td>{{ budget.mark }}</td>
<td>{{ budget.get_major_display }}</td>
<td>{{ budget.banji }}</td>
<td>{{ budget.number }}</td>
<td>{{ budget.get_location_display }}</td>
<td>{{ budget.get_practiceType_display }}</td>
<td>{{ budget.budgetStandard }}</td>
<td>{{ budget.total_budget }}</td>
<td>{{ budget.teachers }}</td>
<td>{{ budget.get_semester_display }}</td>
</tr>
{% endfor %}
</table>
<button id="sheetjsexport"><b>Export as XLSX</b></button>
<script src="xlsx.full.min.js"></script>
<script>
document.getElementById("sheetjsexport").addEventListener('click', function() {
/* Create worksheet from HTML DOM TABLE */
let wb = XLSX.utils.table_to_book(document.getElementById("TableToExport"));
/* Export to file (start a download) */
XLSX.writeFile(wb, "SheetJSTable.xlsx");
});
</script>
</body>
</html>