注意:
当前测试基于lombok和junit环境

新建Model

  1. import cn.zzhardy.annotation.Excel;
  2. import lombok.Setter;
  3. public class Example {
  4. @Setter
  5. @Excel(name = "表格标题一", sort = 1)
  6. private String titleOne;
  7. @Setter
  8. @Excel(name = "表格标题二", sort = 2)
  9. private String titleTwo;
  10. @Setter
  11. @Excel(name = "表格标题三", sort = 1)
  12. private String titleThree;
  13. }

新建测试类数据

  1. @Test
  2. public void excelTest() {
  3. List<Example> list = new ArrayList<>();
  4. for (int i = 0; i < 10; i++) {
  5. Example example = new Example();
  6. example.setTitleOne("标题一 - " + i);
  7. example.setTitleTwo("标题二 - " + i);
  8. example.setTitleThree("标题三 - " + i);
  9. list.add(example);
  10. }
  11. ExcelCenter<Example> util = new ExcelCenter<>(Example.class);
  12. util.exportExcel(list, "Excel生成案例");
  13. }

效果图

第一个测试用例.png