diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java index 71a0e2381..2d03cc835 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java @@ -79,6 +79,11 @@ public class ExcelUtil public static final String[] FORMULA_STR = { "=", "-", "+", "@" }; + /** + * 单元格样式缓存 + */ + private Map cellStyleCache = new HashMap(); + /** * Excel sheet最大行数,默认65536 */ @@ -976,7 +981,7 @@ public class ExcelUtil * 添加单元格 */ @SuppressWarnings("deprecation") - public Cell addCell(Excel attr, Row row, T vo, Field field, int column) + public Cell addCell(Excel attr, Row row, T vo, Field field, int column) { Cell cell = null; try @@ -1043,9 +1048,16 @@ public class ExcelUtil */ private CellStyle createCellStyle(CellStyle cellStyle, String format) { + String key = cellStyle.getIndex() + "|" + format; + CellStyle cached = cellStyleCache.get(key); + if (cached != null) + { + return cached; + } CellStyle style = wb.createCellStyle(); style.cloneStyleFrom(cellStyle); style.setDataFormat(wb.getCreationHelper().createDataFormat().getFormat(format)); + cellStyleCache.put(key, style); return style; } @@ -1241,7 +1253,7 @@ public class ExcelUtil { try { - Object instance = excel.handler().getDeclaredConstructor().newInstance(); + Object instance = excel.handler().newInstance(); Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class, Cell.class, Workbook.class }); value = formatMethod.invoke(instance, value, excel.args(), cell, this.wb); }