优化Excel自定义格式样式重复创建问题

pull/451/head
RuoYi 2 weeks ago
parent c5cd75fe17
commit 316117524d

@ -79,6 +79,11 @@ public class ExcelUtil<T>
public static final String[] FORMULA_STR = { "=", "-", "+", "@" };
/**
*
*/
private Map<String, CellStyle> cellStyleCache = new HashMap<String, CellStyle>();
/**
* Excel sheet65536
*/
@ -976,7 +981,7 @@ public class ExcelUtil<T>
*
*/
@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<T>
*/
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<T>
{
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);
}

Loading…
Cancel
Save