概述
需要給頁面的table做一個數據導出功能,發現一個好用sheetjs工具
只需要簡單的js語法如下,就可以將table的數據導出來
function load(){
var date = new Date();
date.setTime(date.getTime() + (8 * 60 * 60 * 1000));
var table = document.getElementById("tab");
var worksheet = XLSX.utils.table_to_sheet(table);
var workbook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
XLSX.writeFile(workbook, 'output.xlsx');
}