# easy-export **Repository Path**: sumcourage/easy-export ## Basic Information - **Project Name**: easy-export - **Description**: 最好用的excel导出工具 - **Primary Language**: TypeScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-21 - **Last Updated**: 2025-08-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # easy-xlsx-export #### 介绍 最好用的excel导出工具 ## 特性 - 跨平台支持:同时兼容浏览器和Node.js环境 - 高度可定制:支持自定义单元格样式、字体、颜色和对齐方式 - 高级功能:支持合并单元格、多级表头和复杂数据结构 - 性能优化:针对大数据量导出进行了特别优化 - 多工作表:支持一次性导出多个工作表到单个Excel文件 - 灵活配置:支持自定义表头、表尾和数据格式 ## 安装 ```bash npm install easy-xlsx-export ``` ## 使用方法 ### 基本用法(浏览器环境) ```html ``` ### 使用easy-export-app Web组件 除了JavaScript API外,我们还提供了一个便捷的Web组件``,可以快速集成到您的HTML页面中: ```html ``` #### Web组件方法 - `doExport()`: 手动触发导出操作 ### 高级用法(自定义样式和合并单元格) ```javascript // 导入库 import { doExport } from 'easy-xlsx-export'; // 定义带有样式的复杂表头 const exportConfig = { fileName: '销售报表.xlsx', sheets: [{ name: '2023年销售额', columns: [ { caption: '产品类别', field: 'category', width: 15 }, { caption: '季度销售额', columns: [ { caption: 'Q1', field: 'q1', width: 10 }, { caption: 'Q2', field: 'q2', width: 10 }, { caption: 'Q3', field: 'q3', width: 10 }, { caption: 'Q4', field: 'q4', width: 10 } ]} ], preHeaders: [ [ { content: '2023年度销售汇总表', style: { font: { bold: true, sz: 16, color: { rgb: 'FF000000' } }, alignment: { horizontal: 'center' } }, colSpan: 5 } ] ], records: [ { category: '电子产品', q1: 15000, q2: 18000, q3: 22000, q4: 28000 }, { category: '服装', q1: 8000, q2: 9500, q3: 12000, q4: 15000 }, // ...更多数据 ], footers: [ [ { content: '数据生成时间: 2024-01-15', colSpan: 5, style: { font: { italic: true } } } ] ] }] }; // 执行导出 doExport(exportConfig); ``` ## Node.js环境使用 ```javascript const { doExport } = require('easy-xlsx-export'); const fs = require('fs'); // 定义导出配置(与浏览器环境类似) const exportConfig = { fileName: 'node-export-example.xlsx', // ...其他配置与浏览器环境相同 }; // 执行导出 doExport(exportConfig); ``` ## API文档 ### `doExport(config: ExportConfig, platform?: string)` - **描述**: 执行Excel导出的主函数 - **参数**: - `config`: 导出配置对象 - `platform`: 可选,指定运行平台,可选值: 'web' | 'node' ### ExportConfig接口 ```typescript interface ExportConfig { fileName: string; // 导出文件名 sheets: SheetConfig[]; // 工作表配置数组 } ``` ### SheetConfig接口 ```typescript interface SheetConfig { name: string; // 工作表名称 columns: ColumnConfig[]; // 列配置 records: any[]; // 数据源 preHeaders?: Cell[][]; // 表头前的标题行 headers?: Cell[][]; // 表头行 footers?: Cell[][]; // 表尾行 // ...其他高级配置 } ``` ## 许可证 本项目基于MIT许可证开源 - 详见LICENSE文件