ExcelJS導出多級表頭excel
时间: 2024-01-01 15:22:39 浏览: 20
以下是使用ExcelJS导出多级表头excel的步骤:
1. 首先,将代码文件exportExcel.js复制到工程https://github.com/EnthuDai/export-excel-in-one-line中。
2. 然后,在引入excel.js后,调用Excel.export(columns, dataSource, '导出文件名')来导出多级表头excel。
```javascript
// 导入ExcelJS库
const Excel = require('exceljs');
// 定义多级表头的columns和dataSource
const columns = [
{ header: 'A', key: 'A', width: 10 },
{ header: 'B', key: 'B', width: 10 },
{ header: 'C', key: 'C', width: 10, children: [
{ header: 'C1', key: 'C1', width: 10 },
{ header: 'C2', key: 'C2', width: 10 }
]}
];
const dataSource = [
{ A: 1, B: 2, C: { C1: 3, C2: 4 } },
{ A: 5, B: 6, C: { C1: 7, C2: 8 } }
];
// 调用Excel.export导出多级表头excel
Excel.export(columns, dataSource, '导出文件名');
```