re-use styles so that Excel's 4k row limit isn't exceeded (FINERACT-930)

This commit is contained in:
Sidney Wasibani
2020-05-05 22:30:25 +02:00
committed by GitHub
parent b05162f60b
commit a855d3a9cc
@@ -27,6 +27,8 @@ import org.apache.fineract.infrastructure.core.exception.AbstractPlatformService
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.exception.UnsupportedParameterException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CellValue;
@@ -222,10 +224,26 @@ public class ImportHandlerUtils {
}
public static CellStyle getCellStyle(Workbook workbook, IndexedColors color) {
CellReference cellReference = new CellReference("A1");
Sheet predefined = workbook.getSheet(color.toString());
// if we have already defined this style, return it and don't create another one
if (predefined != null) {
Row row = predefined.getRow(cellReference.getRow());
Cell cell = row.getCell(cellReference.getCol());
return cell.getCellStyle();
}
CellStyle style = workbook.createCellStyle();
style.setFillForegroundColor(color.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
Sheet cache = workbook.createSheet(color.toString());
workbook.setSheetHidden(workbook.getSheetIndex(cache), HSSFWorkbook.SHEET_STATE_VERY_HIDDEN);
Row row = cache.createRow(cellReference.getRow());
Cell cell = row.createCell(cellReference.getCol());
cell.setCellStyle(style);
return style;
}
public static String getDefaultUserMessages(List<ApiParameterError> ApiParameterErrorList){