mcpField
E
easyexcel-write

easyexcel-write

github.com/full-stack-skillsDocuments772 installsUpdated 4w ago
Repository

About easyexcel-write

easyexcel-write is an EasyExcel skill for Java developers who need to generate Excel files from objects or Maps without a prebuilt template. It covers headers, styling, merged cells, images, and multi-sheet output.

Key features

  1. 01Generate Excel from objects or Maps
  2. 02Configure complex or dynamic headers
  3. 03Select export columns and formats
  4. 04Customize styles and merge cells
  5. 05Write images, formulas, and rich text
  6. 06Support multiple sheets and web output

Use cases

  1. 01Export order, user, or financial data
  2. 02Generate headers from runtime data
  3. 03Create sheets containing images or formulas
  4. 04Serve Excel downloads through a web response

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/full-stack-skills/java-skills --skill easyexcel-write

After installing, type/easyexcel-writein Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

agents/
openai.yaml
examples/advanced/
15-hyperlink.md
16-comment.md
17-formula.md
18-rich-text.md
examples/annotation/
04-complex-head.md
05-converter.md
06-width-height.md
07-index-data.md
examples/async/
25-async-task.md
examples/bigdata/
24-page-write.md
examples/business/
29-user-export.md
30-finance-stock.md
examples/conversion/
27-custom-converter.md
examples/dynamic/
26-dynamic-head.md
examples/error-handling/
28-validator.md
examples/image/
13-image-demo.md
14-multi-image.md
examples/merge/
11-annotation.md
12-strategy.md
examples/multi-sheet/
21-repeated-same.md
22-different-classes.md
23-table.md
examples/simple/
01-demo-data.md
02-three-ways.md
03-exclude-include.md
examples/style/
08-annotation-style.md
09-strategy.md
10-auto-width.md
examples/web/
19-controller.md

Details

From the project README

EasyExcel 数据写入(Write)

官方文档:https://easyexcel.opensource.alibaba.com/docs/current/quickstart/write 官方示例:https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java 当前版本:com.alibaba:easyexcel:4.0.3(Apache-2.0,仓库已归档,仅做 Bug 修复)

本技能专注于 "程序化生成 Excel" 场景。当用户没有预制模板、要求用 Java 对象/Map 直接生成结构化 Excel(订单、用户、财务、库存、报表、对账单、审批单)时,应当使用本技能。

Capability Boundaries

✅ 强项
  1. 最简写入(JDK8+ 写法、传统写法、Builder 写法)
  2. 复杂表头(多级表头 @ExcelProperty({"主标题", "副标题"}))
  3. 选择性导出列(includeColumnFiledNames / excludeColumnFiledNames)
  4. 注解定义格式(@ColumnWidth @ContentRowHeight @DateTimeFormat @NumberFormat)
  5. 自定义样式(注解方式 / 拦截器方式 / HorizontalCellStyleStrategy)
  6. 合并单元格(@ContentLoopMerge / LoopMergeStrategy)
  7. 图片导出(File/InputStream/URL/byte[] 多种来源)
  8. 超链接/批注/公式/富文本(WriteCellData 体系)
  9. 动态表头(运行时决定表头)
  10. 多次写入/多 Sheet/多 Table
  11. Web 直接输出到 HttpServletResponse
⚠️ 限制
  1. 单 Sheet 建议 < 5000 行一次性写入(数据量大用分批)
  2. 样式对象最多创建 6W 个,否则 Excel 打不开
  3. 图片会驻内存,超大图建议上传到 OSS
  4. 批注需要 inMemory(true)
  5. 03 版(.xls)兼容性需用 excelType(ExcelTypeEnum.XLS)
❌ Out of Scope(不该用本技能的场景,请改用其它技能)
  1. 按预制模板填充 → 不适用本技能,使用 easyexcel-fill
  2. 读取 Excel 数据 → 不适用本技能,使用 easyexcel-read
  3. CSV 文件处理 → 不适用本技能,自行使用 commons-csv / OpenCSV
  4. Word/PPT → 不适用本技能,使用 Apache POI / Apache POI-XML

Data Privacy

本技能不收集、存储或传输任何用户数据。所有代码示例仅用于本地开发参考。

When to use this skill

  • 用户说"导出 Excel"、"生成 Excel"、"下载 Excel"、"导出订单/用户/财务/库存"
  • 没有预制模板,需要程序化生成结构化 Excel
  • 业务上有"分 Sheet(按月份/状态/类型)"、"分 Table(多个表块)"等需求
  • 需要导出图片、超链接、公式、富文本、合并单元格

Quick Start

典型调用方式(3 种写法):

// 写法 1:JDK8+ 用 Supplier(since 3.0.0-beta1,最简洁)
EasyExcel.write(fileName, DemoData.class)
    .sheet("模板")
    .doWrite(() -> data());

// 写法 2:传统 + 已有 List
List<DemoData> data = data();
EasyExcel.write(fileName, DemoData.class)
    .sheet("模板")
    .doWrite(data);

// 写法 3:Builder(多次写入 / 复杂配置)
try (ExcelWriter excelWriter = EasyExcel.write(fileName, DemoData.class).build()) {
    WriteSheet writeSheet = EasyExcel.writerSheet("模板").build();
    excelWriter.write(data(), writeSheet);
}

官方原文:"数据量建议 5000 以内"(单 sheet 一次性写入推荐上限)。

Workflow

Step 1. 定义数据模型 — 编写 DTO/VO,标注 @ExcelProperty 等注解 Step 2. 选择写入方式 — 单次 doWrite() / 多次 excelWriter.write() / 多次 doWrite() 循环 Step 3. 配置 Builder — 包含列选择、表头、样式、注册拦截器等 Step 4. 构造数据 — 准备 List<DTO> / List<List<String>> Step 5. 执行写入 — try-with-resources 关闭 ExcelWriter Step 6. 验证输出 — 打开生成的 .xlsx 检查表头/样式/格式/合并

Critical: 注解速查

注解用途关键属性
@ExcelProperty指定列名/索引/转换器value, index, order, converter
@ExcelIgnore忽略该字段——
@ExcelIgnoreUnannotated类级:未标注字段不参与读写——
@DateTimeFormat日期格式value, use1904windowing
@NumberFormat数字格式value, roundingMode
@ColumnWidth列宽value
@HeadRowHeight表头行高value
@ContentRowHeight内容行高value
@HeadStyle表头样式(POI 风格)fillPatternType, fillForegroundColor, font 等
@HeadFontStyle表头字体fontHeightInPoints, color, bold 等
@ContentStyle内容样式同 HeadStyle
@ContentFontStyle内容字体同 HeadFontStyle
@ContentLoopMerge循环合并eachRow
@OnceAbsoluteMerge一次性绝对合并firstRowIndex lastRowIndex 等

官方原文:order 默认 Integer.MAX_VALUE;优先级:index > order > value。 官方原文:"不建议 index 和 name 同时用,要么只用index,要么只用name匹配"

Reference Library(按需加载)

详细代码与注释已拆分到 references/。按场景加载:

API & 基础模式
模式化(表头 / 样式 / 合并 / 图片 / 富文本 / Web / 高级 / 大数据)
故障排查

References

Comments

Markdown supported