POI 라이브러리를 사용하여 Excel 파일을 처리 중이므로 특정 셀의 ForGroundColor를 변경하려고합니다. IndexedColors 목록에 만족하지 않아서 이미 존재하는 (내 경우 HSSFColor.BLUE) 대체물로 내 자신을 만들고 싶습니다. 문제는 - 마지막 반복의 색상 만 저장합니다 (모든 셀은 동일 함). 색깔).Excel에서 셀 색상을 동적으로 변경합니다.
코드 (convData - 255 정규화이 개 희미한 이중 배열) :
HSSFPalette hssfPalette = excelFile.getCustomPalette();
CellStyle cellStyle = excelFile.createCellStyle();
hssfPalette = excelFile.getCustomPalette();
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
for (int i=0; i<convData.length; i++) {
Row row = excelSheet.createRow(i);
for (int j=0; j<convData[i].length; j++) {
Cell cell = row.createCell(j);
hssfPalette.setColorAtIndex(HSSFColor.BLUE.index, convData[i][j].byteValue(), convData[i][j].byteValue(), convData[i][j].byteValue());
cellStyle.setFillForegroundColor(hssfPalette.getColor(HSSFColor.BLUE.index).getIndex());
cell.setCellStyle(cellStyle);
}
}