execljs-exporter-pro
v1.0.4
Published
Excel export helper based on ExcelJS
Maintainers
Readme
exceljs-exporter-pro
一个基于 ExcelJS 封装的 Excel 导出工具,适用于 Node.js / 后端服务 场景。
用于快速生成结构清晰、格式可控的 Excel 报表,支持复杂排版与数据写入需求。
✨ 特性
- 支持多 Sheet 导出
- 支持标题行(自动合并)
- 表头行位置可配置
- 支持普通数据行写入
- 支持行级多段合并(精确到列)
- 支持不合并单元格独立写值(合计 / 备注 / 公式)
- 支持字体、背景色等样式
- 自动设置列宽
- 支持自定义输出目录
- 支持 CommonJS 和 ESM 双模块引入
📦 安装
npm install exceljs-exporter-pro示例
CommonJS
const exportExcel = require('exceljs-exporter-pro');
(async () => {
const result = await exportExcel({
fileName: '销售报表',
outputDir: 'reports', // 输出目录(相对或绝对路径)
sheets: [
{
title: '2025年12月销售数据', // 可选标题
sheetName: 'Sheet1', // 可选 sheet 名称
headerRowIndex: 2, // header 放到第 2 行
header: ['商品', '数量', '金额'], // 表头行
rows: [
['笔记本', 10, 5000],
['鼠标', 20, 800],
['键盘', 5, 400]
],
merges: [
{
row: 5,
cols: [
{ start: 1, end: 3, value: '合计', style: { font: { bold: true } } }
]
}
],
cells: [
{ row: 6, col: 'A', value: '备注', style: { font: { italic: true } } }
]
},
{
sheetName: 'Sheet2',
header: ['部门', '员工', '销售额'],
rows: [
['技术部', '张三', 12000],
['销售部', '李四', 15000]
]
}
]
});
console.log('文件生成成功:', result.filePath);
})();ESM / TypeScript
import exportExcel from 'exceljs-exporter-pro';
const result = await exportExcel({
fileName: '销售报表',
outputDir: 'reports',
sheets: [
{
title: '2025年12月销售数据',
headerRowIndex: 2, // header 放到第 2 行
sheetName: 'Sheet1',
header: ['商品', '数量', '金额'],
rows: [
['笔记本', 10, 5000],
['鼠标', 20, 800],
['键盘', 5, 400]
],
merges: [
{ row: 5, cols: [{ start: 1, end: 3, value: '合计' }] }
],
cells: [
{ row: 6, col: 'A', value: '备注' }
]
}
]
});
console.log('文件生成成功:', result.filePath);
