POI--各种样式的XSSFCellStyle的生成

时间:2023-03-09 13:43:04
POI--各种样式的XSSFCellStyle的生成
    //背景色、フォント色、枠線より各種XSSFCellStyleの作成して、cellStyleMapに保存する
private HashMap<String, XSSFCellStyle> createXssfCellStyle() {
HashMap<String, XSSFCellStyle> cellStyleMap = new HashMap<>(); XSSFCellStyle xssfCellStyle;
String mapKey = "";
XSSFColor[] xssfColorArr = new XSSFColor[bgColorArr.length];
XSSFFont[] xssfFontArr = new XSSFFont[fontColorArr.length];
for(int bgColorIndex=0; bgColorIndex<bgColorArr.length; bgColorIndex++) {
xssfColorArr[bgColorIndex] = createXssfColor(bgColorArr[bgColorIndex]);
}
for(int fontColorIndex=0; fontColorIndex<fontColorArr.length; fontColorIndex++) {
xssfFontArr[fontColorIndex] = createXssfFont(fontColorArr[fontColorIndex]);
} for (int bgColorIndex=0; bgColorIndex<bgColorArr.length; bgColorIndex++) {
for(int fontColorIndex=0; fontColorIndex<fontColorArr.length; fontColorIndex++) {
for(int rightBorderNameIndex=0; rightBorderNameIndex<borderNameArr.length; rightBorderNameIndex++ ) {
for (int bottomBorderNameIndex=0; bottomBorderNameIndex<borderNameArr.length; bottomBorderNameIndex++ ) {
for (int dataFormatIndex=0; dataFormatIndex<dataFormatArr.length; dataFormatIndex++) {
for (int wrapTextIndex=0; wrapTextIndex < wrapTextArr.length; wrapTextIndex++) {
xssfCellStyle = wb.createCellStyle();
xssfCellStyle.setFillForegroundColor(xssfColorArr[bgColorIndex]);
xssfCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
xssfCellStyle.setFont(xssfFontArr[fontColorIndex]);
xssfCellStyle.setBorderTop(BorderStyle.HAIR);
xssfCellStyle.setBorderLeft(BorderStyle.HAIR);
xssfCellStyle.setBorderRight(BorderStyle.valueOf(borderNameArr[rightBorderNameIndex]));
xssfCellStyle.setBorderBottom(BorderStyle.valueOf(borderNameArr[bottomBorderNameIndex]));
xssfCellStyle.setDataFormat(dataFormatArr[dataFormatIndex]);
xssfCellStyle.setWrapText(wrapTextArr[wrapTextIndex]); //right border name(MEDIUMやHAIR) + bottom border name(MEDIUMやHAIR) + font color(000000など) + background color (ffffffなど)
mapKey = borderNameArr[rightBorderNameIndex]
+ borderNameArr[bottomBorderNameIndex]
+ fontColorArr[fontColorIndex]
+ bgColorArr[bgColorIndex]
+ dataFormatArr[dataFormatIndex]
+ wrapTextKeyArr[wrapTextIndex];
cellStyleMap.put(mapKey, xssfCellStyle);
} } }
}
}
}
return cellStyleMap;
} //右枠線のNAME、下枠線のNAME、フォント色、背景色より、合っているXSSFCellStyleを取得
private XSSFCellStyle getXssfCellStyle(String rightBorderName, String bottomBorderName, String fontColor, String bgColor, int dataFormat, boolean isWrapped ) {
String wrapTextKey = WRAP_TEXT_KEY_FALSE;
if (isWrapped) {
wrapTextKey = WRAP_TEXT_KEY_TRUE;
}
String mapKey = rightBorderName + bottomBorderName + fontColor + bgColor + dataFormat + wrapTextKey;
if (!xssfCellStyleMap.containsKey(mapKey)) {
}
return xssfCellStyleMap.get(mapKey);
}