vue中使用xlsx 导出表格
<t-table v-show="false" id="exportTab" row-key="index" :data="allData" :columns="allColumns">
<template #createTime="{ row }">
{{ getDateDiff(row.createTime) }}
</template>
</t-table>
import XLSX from 'xlsx';
const exportExcel = () => {
const table = document.getElementById('exportTab');
const worksheet = XLSX.utils.table_to_sheet(table, { raw: true });
const workbook = XLSX.utils.book_new();
const wscols = [
// 每列不同宽度px
{ wch: 22 },
{ wch: 22 },
{ wch: 30 },
{ wch: 22 },
{ wch: 13 },
{ wch: 22 },
{ wch: 15 },
{ wch: 15 },
{ wch: 22 },
{ wch: 22 },
];
worksheet['!cols'] = wscols;
XLSX.utils.book_append_sheet(workbook, worksheet, 'sheet');
try {
XLSX.writeFile(workbook, `ip-infos-${route.query.id}.xlsx`);
} catch (e) {
console.log(e, workbook);
}
};