[alibaba/easyexcel]使用内部类导出excel表头会出现this$0(2.2.7版本)

2024-05-11 174 views
5

触发Bug的代码

@Test
public void test() {
    List<Student> list = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        Student student = new Student();
        student.setId(i);
        student.setName("KID " + i);
        student.setAge(20 + i);
        list.add(student);
    }
    EasyExcel.write(write_path, Student.class)
        .registerWriteHandler(new CustomCellWriteHandler())
        .sheet().doWrite(list);
}

提示的异常或者没有达到的效果 issue

回答

2

可以通过判断类的类型在写入时避免this$0的出现

9
    @Test
    public void test11() {
        String fileName = TestFileUtil.getPath() + "stud" + System.currentTimeMillis() + ".xlsx";

        List<Student> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Student student = new Student();
            student.setId(i);
            list.add(student);
        }
        EasyExcel.write(fileName, Student.class)
            .sheet().doWrite(list);
    }

    @Data
    public static class Student{
        private Integer id;

    }

实际测试未发现情况 是否版本过老?

6

这个是否已经解决?如果未解决则重新打开问题。