Backend Development 8 min read

FastExcel: High‑Performance Java Excel Read/Write Library – Features, Usage, and Comparison with EasyExcel

FastExcel is a high‑performance Java library that extends EasyExcel, offering streamlined APIs, streaming read/write, event listeners, and PDF conversion, enabling developers to efficiently handle large Excel files with low memory usage in enterprise applications.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
FastExcel: High‑Performance Java Excel Read/Write Library – Features, Usage, and Comparison with EasyExcel

FastExcel is an upgraded Java framework released by the original EasyExcel author after Alibaba stopped maintaining EasyExcel. It inherits all advantages of EasyExcel while delivering significant performance and feature enhancements.

Key Features

High‑performance read/write with low memory consumption.

Simple, intuitive API for quick integration.

Streaming operations that minimize memory usage for massive rows.

Full compatibility with EasyExcel APIs.

Continuous updates and bug fixes.

Usage Overview

Creating Entity Classes and Listeners

Define an entity class where each field maps to an Excel column using the @ExcelProperty annotation.

import cn.idev.excel.annotation.ExcelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Setter
@Getter
@ToString
public class User {
    @ExcelProperty("编号")
    private Integer id;
    @ExcelProperty("名字")
    private String name;
    @ExcelProperty("年龄")
    private Integer age;
}

Implement an event listener to process rows one‑by‑one, preventing memory overflow.

import cn.idev.excel.context.AnalysisContext;
import cn.idev.excel.event.AnalysisEventListener;
import java.util.ArrayList;
import java.util.List;

public class BaseExcelListener
extends AnalysisEventListener
{
    private List
dataList = new ArrayList<>();

    @Override
    public void invoke(T t, AnalysisContext analysisContext) {
        dataList.add(t);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("读取完成,共读取了 " + dataList.size() + " 条数据");
    }

    public List
getDataList() {
        return dataList;
    }
}

Excel Write Example

Use FastExcel.write to export data to an Excel file.

// Excel写入功能
@GetMapping("/download")
public void download(HttpServletResponse response) throws IOException {
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    response.setCharacterEncoding("utf-8");
    String fileName = URLEncoder.encode("test", "UTF-8");
    response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
    // 写入数据
    FastExcel.write(response.getOutputStream(), User.class)
        .sheet("模板")
        .doWrite(buildData());
}

private List
buildData() {
    User user1 = new User();
    user1.setId(1);
    user1.setName("张三");
    user1.setAge(18);
    User user2 = new User();
    user2.setId(2);
    user2.setName("李四");
    user2.setAge(19);
    return List.of(user1, user2);
}

Excel Read Example

Read an uploaded Excel file with FastExcel.read and the previously defined listener.

// Excel读取功能
@PostMapping("/upload")
public ResponseEntity
upload(@RequestParam("file") MultipartFile file) {
    if (file.isEmpty()) {
        return ResponseEntity.badRequest().body("请选择一个文件上传!");
    }
    try {
        BaseExcelListener
baseExcelListener = new BaseExcelListener<>();
        FastExcel.read(file.getInputStream(), User.class, baseExcelListener)
            .sheet()
            .doRead();
        List
dataList = baseExcelListener.getDataList();
        System.out.println(dataList);
        return ResponseEntity.ok("文件上传并处理成功!");
    } catch (IOException e) {
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("文件处理失败!");
    }
}

Excel to PDF Conversion

FastExcel can convert Excel files to PDF using Apache POI and iText‑pdf (license compliance required).

FastExcel.convertToPdf(new File("excelFile"), new File("pdfFile"), null, null);

Summary

FastExcel provides a lightweight yet powerful solution for high‑performance Excel processing in Java, supporting streaming reads, event‑driven handling, and PDF conversion while maintaining API compatibility with EasyExcel.

Differences from EasyExcel

Improved performance and stability.

Identical API for seamless migration.

New features in version 1.0.0: row‑limit reading and Excel‑to‑PDF conversion.

Conclusion

For projects that need to process large‑scale Excel data with low memory overhead, FastExcel is a compelling choice, offering efficient streaming, flexible APIs, and additional capabilities such as PDF export.

backendJavaPerformanceExcelDataProcessingFastExcel
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.