Official documentation:https://easyexcel.opensource.alibaba.com/docs/current/quickstart/write Official example:https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java Current version:
com.alibaba:easyexcel:4.0.3(Apache-2.0, repository archived, only bug fixes)
This skill focuses on the "programmatically generating Excel" scenario. When the user has no pre-made template and requires directly generating structured Excel (orders, users, finance, inventory, reports, statements, approval forms) using Java objects/Maps, this skill should be used.
Capability Boundaries
✅ Strengths
- Simplest writing (JDK8+ style, traditional style, Builder style)
- Complex headers (multi-level headers
@ExcelProperty({"主标题", "副标题"})) - Selective column export (
includeColumnFiledNames/excludeColumnFiledNames) - Annotation-defined formats (
@ColumnWidth@ContentRowHeight@DateTimeFormat@NumberFormat) - Custom styles (annotation method / interceptor method /
HorizontalCellStyleStrategy) - Merged cells (
@ContentLoopMerge/LoopMergeStrategy) - Image export (multiple sources: File/InputStream/URL/byte[])
- Hyperlinks/comments/formulas/rich text (
WriteCellDatasystem) - Dynamic headers (headers determined at runtime)
- Multiple writes/multiple Sheets/multiple Tables
- Web direct output to
HttpServletResponse
⚠️ Limitations
- A single Sheet is recommended to write < 5000 rows at once (use batching for large amounts of data)
- A maximum of 60K style objects can be created, otherwise Excel cannot be opened
- Images will reside in memory; for extremely large images, it is recommended to upload them to OSS
- Comments require
inMemory(true) - 03 version (
.xls) compatibility requiresexcelType(ExcelTypeEnum.XLS)
❌ Out of Scope (scenarios where this skill should not be used; please use another skill instead)
- Fill according to a pre-made template → Not applicableto this skill, use
easyexcel-fill - Read Excel data → Not applicableto this skill, use
easyexcel-read - CSV file processing → Not applicableto this skill, use commons-csv / OpenCSV on your own
- Word/PPT → Not applicableto this skill, use Apache POI / Apache POI-XML
Data Privacy
This skill does not collect, store, or transmit any user data. All code examples are for local development reference only.
When to use this skill
- The user says "export Excel", "generate Excel", "download Excel", "export orders/users/finance/inventory"
- There is no pre-made template, and structured Excel needs to be generated programmatically
- There are business requirements such as "split by Sheet (by month/status/type)" and "split by Table (multiple table blocks)"
- Need to export images, hyperlinks, formulas, rich text, merged cells
Quick Start
Typical invocation methods (3 ways):
// 写法 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);
}
Official original text: "It is recommended that the data volume be within 5000" (recommended upper limit for writing a single sheet at once).
Workflow
Step 1. Define the data model — Write DTO/VO, annotate with @ExcelProperty and other annotations
Step 2. Choose the write method — Single doWrite() / multiple excelWriter.write() / multiple doWrite() loops
Step 3. Configure Builder — Includes column selection, headers, styles, registered interceptors, etc.
Step 4. Construct data — Prepare List<DTO> / List<List<String>>
Step 5. Perform write — try-with-resources close ExcelWriter
Step 6. Validate output — open the generated .xlsx check header/style/format/merge
Critical: Annotation Quick Reference
| Annotation | Purpose | Key Attributes |
|---|---|---|
@ExcelProperty |
Specify column name/index/converter | value, index, order, converter |
@ExcelIgnore |
Ignore this field | —— |
@ExcelIgnoreUnannotated |
Class-level: unannotated fields do not participate in read/write | —— |
@DateTimeFormat |
Date format | value, use1904windowing |
@NumberFormat |
Number format | value, roundingMode |
@ColumnWidth |
Column width | value |
@HeadRowHeight |
Header row height | value |
@ContentRowHeight |
Content row height | value |
@HeadStyle |
Header style (POI style) | fillPatternType, fillForegroundColor, font, etc. |
@HeadFontStyle |
Header font | fontHeightInPoints, color, bold, etc. |
@ContentStyle |
Content style | Same as HeadStyle |
@ContentFontStyle |
Content font | Same as HeadFontStyle |
@ContentLoopMerge |
Loop merge | eachRow |
@OnceAbsoluteMerge |
One-time absolute merge | firstRowIndex lastRowIndex etc. |
Official original text:
orderdefaultInteger.MAX_VALUE; priority:index>order>value。 Official original text:"It is not recommended to use index and name at the same time; either use only index or use only name matching"
Reference Library (load on demand)
Detailed code and comments have been split into references/. Load by scenario:
API & Basic Patterns
- references/api/3-write-modes.md — 3 basic write modes (simplest / select columns / multiple writes)
- references/api/key-classes.md — Key Classes / Methods Quick Reference
Pattern-based (header / style / merge / image / rich text / Web / advanced / big data)
- references/patterns/header-format-style.md — complex header / custom style (annotations + interceptors)
- references/scenarios/merge-cell.md — merge cells
- references/scenarios/image-export.md — image export (multiple sources + multiple image embedding)
- references/scenarios/hyperlink-comment-formula-richtext.md — hyperlinks / comments / formulas / rich text
- references/scenarios/web-download.md — Web download (including failure returning JSON)
- references/scenarios/advanced.md — dynamic header / auto column width / custom interceptor / version 03 compatibility
- references/scenarios/million-row.md — million-level batch writing
Troubleshooting
- references/troubleshooting/gotchas.md — 12 common errors and correct practices
References
- Official documentation:https://easyexcel.opensource.alibaba.com/docs/current/quickstart/write
- Official examples:https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
- Project homepage:https://easyexcel.opensource.alibaba.com/
- GitHub:https://github.com/alibaba/easyexcel
- API reference:https://easyexcel.opensource.alibaba.com/docs/current/api/