4f45f743e9dd5337a3f5d6bbc97ce1c13fd6f905.svn-base 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.sinosoft.em.evaluate.excel;
  2. import java.util.List;
  3. import org.junit.Test;
  4. import com.quiteJee.poi.excel.utils.ExcelUtils;
  5. import com.sinosoft.em.evaluate.dto.NormDto;
  6. import com.sinosoft.em.evaluate.dto.RectificationDto;
  7. import com.sinosoft.em.evaluate.dto.SpecialDto;
  8. public class Module2Excel {
  9. @Test
  10. public void testObject2Excel() throws Exception {
  11. String tempPath = "D:/Workspaces/wanggongsi/nwyj/src/应急准备评估标准.xlsx";
  12. String path = "D:/Workspaces/wanggongsi/nwyj/src/附录A:应急准备评估标准(2017试行版)V2.xlsx";
  13. // sheet0 导入
  14. List<NormDto> nlist = ExcelUtils.getInstance().readExcel2Objects(path, 1, 2, NormDto.class, 0);
  15. // sheet1 导入
  16. List<SpecialDto> slist = ExcelUtils.getInstance().readExcel2Objects(path, 1, 2, SpecialDto.class, 1);
  17. // sheet0 导入
  18. List<RectificationDto> rlist = ExcelUtils.getInstance().readExcel2Objects(path, 1, 2, RectificationDto.class, 2);
  19. // 基于模板导出Excel result.xlsx为最终导出excel
  20. // 模板中变量说明 $serial_number 生成序列号
  21. // $data_index 数据起始位置
  22. // $default_style 数据行样式
  23. com.quiteJee.poi.excel.utils.ExcelUtils.getInstance().exportObjects2Excel(tempPath, 0, nlist, null, NormDto.class, false, "d:/excel/temp0.xlsx");
  24. com.quiteJee.poi.excel.utils.ExcelUtils.getInstance().exportObjects2Excel("d:/excel/temp0.xlsx", 1, slist, null,SpecialDto.class, false, "d:/excel/temp1.xlsx");
  25. com.quiteJee.poi.excel.utils.ExcelUtils.getInstance().exportObjects2Excel("d:/excel/temp1.xlsx", 2, rlist, null,RectificationDto.class, false, "d:/excel/result.xlsx");
  26. }
  27. public static void main(String[] args) {
  28. try {
  29. new Module2Excel().testObject2Excel();
  30. } catch (Exception e) {
  31. // TODO Auto-generated catch block
  32. e.printStackTrace();
  33. }
  34. }
  35. }