How to skip rows when writing files in EasyExcel for Java?
In EasyExcel, you can skip specified rows by using the @ExcelIgnore annotation. The specific steps are as follows:
- Do not pay attention to Excel
public class User {
@ExcelIgnore
private String name;
private int age;
// ...
}
- exclude the names of the columns
public void writeExcel(String fileName, List<User> userList) {
ExcelWriter excelWriter = EasyExcel.write(fileName, User.class)
.excludeColumnFiledNames("name")
.build();
WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").build();
excelWriter.write(userList, writeSheet);
excelWriter.finish();
}
In the above code, the parameter for the excludeColumnFieldNames method is “name”, indicating that it is skipping the row where the name property is located in the User entity class.
By following the above steps, you can skip specified rows when writing files using EasyExcel.