| | |
| | | for (Object[] os : fields) |
| | | { |
| | | Excel excel = (Excel) os[1]; |
| | | String key = StringUtils.format("data_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor()); |
| | | String key = StringUtils.format("data_{}_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor(), excel.cellType()); |
| | | if (!styles.containsKey(key)) |
| | | { |
| | | CellStyle style = wb.createCellStyle(); |
| | |
| | | style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
| | | style.setFillForegroundColor(excel.backgroundColor().getIndex()); |
| | | if (ColumnType.STRING == excel.cellType()) |
| | | { |
| | | style.setDataFormat(wb.createDataFormat().getFormat("@")); |
| | | } |
| | | Font dataFont = wb.createFont(); |
| | | dataFont.setFontName("Arial"); |
| | | dataFont.setFontHeightInPoints((short) 10); |
| | |
| | | cell.setCellValue(attr.name()); |
| | | setDataValidation(attr, row, column); |
| | | cell.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor()))); |
| | | sheet.setDefaultColumnStyle(column, styles.get(StringUtils.format("data_{}_{}_{}_{}", |
| | | attr.align(), attr.color(), attr.backgroundColor(), attr.cellType()))); |
| | | if (isSubList()) |
| | | { |
| | | // 填充默认样式,防止合并单元格样式失效 |
| | | sheet.setDefaultColumnStyle(column, styles.get(StringUtils.format("data_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor()))); |
| | | if (attr.needMerge()) |
| | | { |
| | | sheet.addMergedRegion(new CellRangeAddress(rownum - 1, rownum, column, column)); |
| | |
| | | CellRangeAddress cellAddress = new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column); |
| | | sheet.addMergedRegion(cellAddress); |
| | | } |
| | | cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor()))); |
| | | cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}_{}", |
| | | attr.align(), attr.color(), attr.backgroundColor(), attr.cellType()))); |
| | | |
| | | // 用于读取对象中的属性 |
| | | Object value = getTargetValue(vo, field, attr); |