vue的XLSX.utils 怎么导出所有数据到excel里?

XLSX只导出页面上显示在table的数据,我想导出所有分页的数据

let xlsxParam = { raw: true };

let wb = XLSX.utils.table_to_book(

document.querySelector("#topThreeIncreaseMaterial"),

xlsxParam

);

let wbout = XLSX.write(wb, {bookType: "xlsx", bookSST: true, type: "array",});

try {

saveAs(new Blob([wbout], { type: "application/octet-stream" }), name + ".xlsx");

} catch (e) {

console.log(e, wbout);

}

return wbout;


回答:

import XLSX from 'xlsx';

let data = [

{ name: 'John', age: 30, city: 'New York' },

{ name: 'Jane', age: 40, city: 'Chicago' },

// ...其他数据

];

let worksheet = XLSX.utils.json_to_sheet(data);

let workbook = XLSX.utils.book_new();

XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');

// 导出工作簿

XLSX.writeFile(workbook, 'output.xlsx');


回答:

引入插件
import XLSX from 'xlsx'

导出方法

exportExcel(data) {

const temp = XLSX.utils.json_to_sheet(data);

const wb = XLSX.utils.book_new();

XLSX.utils.book_append_sheet(wb, temp, 'Sheet1');

XLSX.writeFile(wb,'xxx.xlsx'); // 文件的名字

}

获取所有数据导出

async onExportFn() {

// 请求获取所有的数据 this.total为总条数

const res = await getAllList({ page: 1, size: this.total })

// 此时list里面是所有数据

const list = res.data

this.exportExcel(list)

}

如果数据量比较大还是建议通过后端提供下载的接口去处理比较好

以上是 vue的XLSX.utils 怎么导出所有数据到excel里? 的全部内容, 来源链接: utcz.com/p/934629.html

回到顶部