SuperAPI AI Directory

easyexcel-write

Office & productivity

View repository

Updated 10-15 21:48

About this skill

EasyExcel Data Writing (Write)

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

  1. Simplest writing (JDK8+ style, traditional style, Builder style)
  2. Complex headers (multi-level headers @ExcelProperty({"主标题", "副标题"}))
  3. Selective column export (includeColumnFiledNames / excludeColumnFiledNames)
  4. Annotation-defined formats (@ColumnWidth @ContentRowHeight @DateTimeFormat @NumberFormat)
  5. Custom styles (annotation method / interceptor method / HorizontalCellStyleStrategy)
  6. Merged cells (@ContentLoopMerge / LoopMergeStrategy)
  7. Image export (multiple sources: File/InputStream/URL/byte[])
  8. Hyperlinks/comments/formulas/rich text (WriteCellData system)
  9. Dynamic headers (headers determined at runtime)
  10. Multiple writes/multiple Sheets/multiple Tables
  11. Web direct output to HttpServletResponse

⚠️ Limitations

  1. A single Sheet is recommended to write < 5000 rows at once (use batching for large amounts of data)
  2. A maximum of 60K style objects can be created, otherwise Excel cannot be opened
  3. Images will reside in memory; for extremely large images, it is recommended to upload them to OSS
  4. Comments require inMemory(true)
  5. 03 version (.xls) compatibility requires excelType(ExcelTypeEnum.XLS)

❌ Out of Scope (scenarios where this skill should not be used; please use another skill instead)

  1. Fill according to a pre-made template → Not applicableto this skill, use easyexcel-fill
  2. Read Excel data → Not applicableto this skill, use easyexcel-read
  3. CSV file processing → Not applicableto this skill, use commons-csv / OpenCSV on your own
  4. 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:order default Integer.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

Pattern-based (header / style / merge / image / rich text / Web / advanced / big data)

Troubleshooting

References