| @@ -41,13 +41,13 @@ import org.jeecgframework.poi.util.POIPublicUtil; | |||||
| */ | */ | ||||
| public abstract class ExcelExportBase extends ExportBase { | public abstract class ExcelExportBase extends ExportBase { | ||||
| private int currentIndex = 0; | |||||
| private int currentIndex = 0; | |||||
| protected String type = PoiBaseConstants.HSSF; | |||||
| protected String type = PoiBaseConstants.HSSF; | |||||
| private Map<Integer, Double> statistics = new HashMap<Integer, Double>(); | |||||
| private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("######0.00"); | |||||
| private Map<Integer, Double> statistics = new HashMap<Integer, Double>(); | |||||
| private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("######0.00"); | |||||
| private boolean checkIsEqualByCellContents(MergeEntity mergeEntity, String text, Cell cell, | private boolean checkIsEqualByCellContents(MergeEntity mergeEntity, String text, Cell cell, | ||||
| int[] delys, int rowNum) { | int[] delys, int rowNum) { | ||||
| @@ -273,13 +273,15 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
| * @param sheet | * @param sheet | ||||
| */ | */ | ||||
| public void addStatisticsRow(CellStyle styles, Sheet sheet) { | public void addStatisticsRow(CellStyle styles, Sheet sheet) { | ||||
| Row row = sheet.createRow(sheet.getLastRowNum() + 1); | |||||
| Set<Integer> keys = statistics.keySet(); | |||||
| createStringCell(row, 0, "合计", styles, null); | |||||
| for (Integer key : keys) { | |||||
| createStringCell(row, key, DOUBLE_FORMAT.format(statistics.get(key)), styles, null); | |||||
| if (statistics.size() > 0) { | |||||
| Row row = sheet.createRow(sheet.getLastRowNum() + 1); | |||||
| Set<Integer> keys = statistics.keySet(); | |||||
| createStringCell(row, 0, "合计", styles, null); | |||||
| for (Integer key : keys) { | |||||
| createStringCell(row, key, DOUBLE_FORMAT.format(statistics.get(key)), styles, null); | |||||
| } | |||||
| statistics.clear(); | |||||
| } | } | ||||
| statistics.clear(); | |||||
| } | } | ||||
| @@ -32,7 +32,7 @@ public class CourseEntity implements java.io.Serializable { | |||||
| //@ExcelEntity(id = "shuxue") | //@ExcelEntity(id = "shuxue") | ||||
| private TeacherEntity shuxueteacher; | private TeacherEntity shuxueteacher; | ||||
| //@ExcelCollection(name = "选课学生", orderNum = "4") | |||||
| @ExcelCollection(name = "选课学生", orderNum = "4") | |||||
| private List<StudentEntity> students; | private List<StudentEntity> students; | ||||
| /** | /** | ||||
| @@ -30,6 +30,9 @@ public class StudentEntity implements java.io.Serializable { | |||||
| @Excel(name = "出生日期", databaseFormat = "yyyyMMddHHmmss", exportFormat = "yyyy-MM-dd", mergeVertical = true) | @Excel(name = "出生日期", databaseFormat = "yyyyMMddHHmmss", exportFormat = "yyyy-MM-dd", mergeVertical = true) | ||||
| private Date birthday; | private Date birthday; | ||||
| @Excel(name = "进校日期", databaseFormat = "yyyyMMddHHmmss", exportFormat = "yyyy-MM-dd") | |||||
| private java.sql.Time registrationDate; | |||||
| /** | /** | ||||
| * 课程主键 | * 课程主键 | ||||
| */ | */ | ||||
| @@ -105,4 +108,12 @@ public class StudentEntity implements java.io.Serializable { | |||||
| this.birthday = birthday; | this.birthday = birthday; | ||||
| } | } | ||||
| public java.sql.Time getRegistrationDate() { | |||||
| return registrationDate; | |||||
| } | |||||
| public void setRegistrationDate(java.sql.Time registrationDate) { | |||||
| this.registrationDate = registrationDate; | |||||
| } | |||||
| } | } | ||||
| @@ -50,6 +50,7 @@ public class ExcelExportUtilIdTest { | |||||
| studentEntity.setId("11231"); | studentEntity.setId("11231"); | ||||
| studentEntity.setName("撒旦法司法局"); | studentEntity.setName("撒旦法司法局"); | ||||
| studentEntity.setBirthday(new Date()); | studentEntity.setBirthday(new Date()); | ||||
| studentEntity.setRegistrationDate(new java.sql.Time(new Date().getTime())); | |||||
| studentEntity.setSex(1); | studentEntity.setSex(1); | ||||
| List<StudentEntity> studentList = new ArrayList<StudentEntity>(); | List<StudentEntity> studentList = new ArrayList<StudentEntity>(); | ||||
| studentList.add(studentEntity); | studentList.add(studentEntity); | ||||
| @@ -70,7 +71,7 @@ public class ExcelExportUtilIdTest { | |||||
| public void testExportExcel() throws Exception { | public void testExportExcel() throws Exception { | ||||
| ExportParams params = new ExportParams("2412312", "测试", "测试"); | ExportParams params = new ExportParams("2412312", "测试", "测试"); | ||||
| params.setAddIndex(true); | params.setAddIndex(true); | ||||
| Workbook workbook = ExcelExportUtil.exportExcel(params, TeacherEntity.class, telist); | |||||
| Workbook workbook = ExcelExportUtil.exportExcel(params, CourseEntity.class, list); | |||||
| FileOutputStream fos = new FileOutputStream("d:/tt.xls"); | FileOutputStream fos = new FileOutputStream("d:/tt.xls"); | ||||
| workbook.write(fos); | workbook.write(fos); | ||||
| fos.close(); | fos.close(); | ||||