我正在尝试在导出时将一行添加到excel工作表,然后在下一行添加数据。我玩过sheet_add_json
和sheet_add_aoa
,但似乎无法正常工作。
有人看到我在做什么错吗?
function exportToExcel(type, fn, dl) {
var dateTable = document.getElementById('data-table');
var wb = {SheetNames:[], Sheets:{}};
//THIS IS THE DOM HTML TABLE DATA
//This works by itself
//var ws1 = XLSX.utils.table_to_book(dateTable, {type:"binary"}).Sheets.Sheet1;
// ADD ONE ROW AT THE BEGININT THAT GIVES A DATE RANGE FOR THE DATA (A1 - A2)
var ws1 = XLSX.utils.aoa_to_sheet([
["Report for Range"],
["{{ date_range }}"]
]);
// ADD THE DOM HTML TABLE TO THE SHEET STARTING AT B1
XLSX.utils.sheet_add_json(ws1, [
XLSX.utils.table_to_book(dateTable, {type:"binary"}).Sheets.Sheet1
], {header:ws1, origin:"B1"});
wb.SheetNames.push("{{report_name}}");
wb.Sheets["{{report_name}}"] = ws1;
return dl ?
XLSX.write(wb, {bookType:type, bookSST:true, type: 'base64'}) :
XLSX.writeFile(wb, fn || ('{{report_name}}.' + (type || 'xlsx')));
}