Skip to content

ExcelReader with AnalysisEventListener

ExcelReader paired with an AnalysisEventListener is the mechanism used by the EasyExcel library to read and process Excel data without a predefined domain model^[600-developer-java-3-party-easyexcel.md].

Core Implementation

The ExcelReader constructor typically takes an InputStream and an instance of AnalysisEventListener^[600-developer-java-3-party-easyexcel.md]. This listener is an abstract class that requires overriding the invoke method to handle the data row by row^[600-developer-java-3-party-easyexcel.md].

Data Processing Logic

Inside the overridden invoke method, the raw data is received as a List<String>, where each string represents a cell value^[600-developer-java-3-party-easyexcel.md]. Developers can access metadata about the current parsing position through the AnalysisContext parameter, which provides details such as the current sheet number and row number^[600-developer-java-3-party-easyexcel.md].

Additionally, the listener requires implementing the doAfterAllAnalysed method, which serves as a callback executed after the entire file or sheet has been successfully read^[600-developer-java-3-party-easyexcel.md].

Sources

^[600-developer-java-3-party-easyexcel.md]