// Font color
final short colorIndex = font.getColor();
if (font instanceof HSSFFont) {
if (colorIndex != HSSFFont.COLOR_NORMAL) {
final HSSFWorkbook wb = (HSSFWorkbook) workbook;
HSSFColor color = wb.getCustomPalette().getColor(colorIndex);
if (color != null) {
short[] triplet = color.getTriplet();
styleBuilder.foreground(triplet);
}
}
} else if (font instanceof XSSFFont) {
XSSFFont xssfFont = (XSSFFont) font;
XSSFColor color = xssfFont.getXSSFColor();
if (color != null) {
String argbHex = color.getARGBHex();
if (argbHex != null) {
styleBuilder.foreground(argbHex.substring(2));
}
}
} else {
throw new IllegalStateException("Unexpected font type: " + (font == null ? "null" : font.getClass()) + ")");
}
// Background color
if (cellStyle.getFillPattern() == 1) {
Color color = cellStyle.getFillForegroundColorColor();
if (color instanceof HSSFColor) {
short[] triplet = ((HSSFColor) color).getTriplet();
if (triplet != null) {
styleBuilder.background(triplet);
}
} else if (color instanceof XSSFColor) {
String argb = ((XSSFColor) color).getARGBHex();
if (argb != null) {
styleBuilder.background(argb.substring(2));
}
} else {
throw new IllegalStateException("Unexpected color type: " + (color == null ? "null" : color.getClass()) + ")");
}
}
// alignment
switch (cellStyle.getAlignment()) {