Use Light Excel Reader framework to read the step of Excel file
Use Light Excel Reader framework to read the step of Excel file
Light Excel Reader is a lightweight Java library for reading Excel files.Here are the steps to read the excel file with Light Excel Reader framework:
1. Import Light Excel Reader Library
First, use Maven or manually to import the Light Excel Reader library in the Java project.
Maven dependence code is as follows:
<dependency>
<groupId>com.github.liuganggang</groupId>
<artifactId>lightexcelreader</artifactId>
<version>1.2.0</version>
</dependency>
2. Create ExcelReader object
Create an ExcelReader object in the code and pass in the Excel file path as a parameter.
String filePath = "path/to/your/excel/file.xlsx";
ExcelReader excelReader = new ExcelReader(filePath);
3. Choose a worksheet
Use the `Selectsheet () method to select the worksheet to be read, and pass the worksheet name or index as a parameter.
ExcelReader.Selectsheet ("Sheet1"); // Select through the name of the workheet
// or
ExcelReader.Selectsheet (0); // Through the index selection, the index starts from 0
4. Read the header
Read the header information with the method of using the `Readheader ()" method.
List<String> header = excelReader.readHeader();
5. Traveling data
Use `HasnextRow () and` NextRow () `to traverse all rows of data.
while (excelReader.hasNextRow()) {
List<String> rowData = excelReader.nextRow();
// Process each line of data
for (String value : rowData) {
System.out.println(value);
}
}
The complete example code is shown below:
import com.github.liuganggang.lightexcelreader.ExcelReader;
public class ExcelReaderExample {
public static void main(String[] args) {
String filePath = "path/to/your/excel/file.xlsx";
ExcelReader excelReader = new ExcelReader(filePath);
excelReader.selectSheet("Sheet1");
List<String> header = excelReader.readHeader();
while (excelReader.hasNextRow()) {
List<String> rowData = excelReader.nextRow();
for (String value : rowData) {
System.out.println(value);
}
}
excelReader.close();
}
}
The above is the steps to read the excel file using the Light Excel Reader framework.Through this simple framework, you can easily read the data in the Excel file.