protected XSSFColor extractColor(XSSFCell cell, XSSFColor... acceptableColors) { XSSFCellStyle cellStyle = cell.getCellStyle(); FillPatternType fillPattern = cellStyle.getFillPatternEnum(); if (fillPattern == null || fillPattern == FillPatternType.NO_FILL) { return null; } if (fillPattern != FillPatternType.SOLID_FOREGROUND) { throw new IllegalStateException(currentPosition() + ": The fill pattern (" + fillPattern + ") should be either " + FillPatternType.NO_FILL + " or " + FillPatternType.SOLID_FOREGROUND + "."); } XSSFColor color = cellStyle.getFillForegroundColorColor(); for (XSSFColor acceptableColor : acceptableColors) { if (acceptableColor.equals(color)) { return acceptableColor; } } throw new IllegalStateException(currentPosition() + ": The fill color (" + color + ") is not one of the acceptableColors (" + Arrays.toString(acceptableColors) + ")."); } }
/** * Finds a font that matches the one with the supplied attributes, * where color is the actual Color-value, not the indexed color */ public XSSFFont findFont(boolean bold, Color color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) { for (XSSFFont font : fonts) { if ( (font.getBold() == bold) && font.getXSSFColor().equals(color) && font.getFontHeight() == fontHeight && font.getFontName().equals(name) && font.getItalic() == italic && font.getStrikeout() == strikeout && font.getTypeOffset() == typeOffset && font.getUnderline() == underline) { return font; } } return null; }
protected XSSFColor extractColor(XSSFCell cell, XSSFColor... acceptableColors) { XSSFCellStyle cellStyle = cell.getCellStyle(); FillPatternType fillPattern = cellStyle.getFillPatternEnum(); if (fillPattern == null || fillPattern == FillPatternType.NO_FILL) { return null; } if (fillPattern != FillPatternType.SOLID_FOREGROUND) { throw new IllegalStateException(currentPosition() + ": The fill pattern (" + fillPattern + ") should be either " + FillPatternType.NO_FILL + " or " + FillPatternType.SOLID_FOREGROUND + "."); } XSSFColor color = cellStyle.getFillForegroundColorColor(); for (XSSFColor acceptableColor : acceptableColors) { if (acceptableColor.equals(color)) { return acceptableColor; } } throw new IllegalStateException(currentPosition() + ": The fill color (" + color + ") is not one of the acceptableColors (" + Arrays.toString(acceptableColors) + ")."); } }
/** * Finds a font that matches the one with the supplied attributes, * where color is the actual Color-value, not the indexed color */ public XSSFFont findFont(boolean bold, Color color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) { for (XSSFFont font : fonts) { if ( (font.getBold() == bold) && font.getXSSFColor().equals(color) && font.getFontHeight() == fontHeight && font.getFontName().equals(name) && font.getItalic() == italic && font.getStrikeout() == strikeout && font.getTypeOffset() == typeOffset && font.getUnderline() == underline) { return font; } } return null; }
if (font == null || color != null && !font.getXSSFColor().equals(color) || color == null && font.getXSSFColor().getIndexed() != indexedColor) { font = workbook.createFont();
if (font == null || color != null && !font.getXSSFColor().equals(color) || color == null && font.getXSSFColor().getIndexed() != indexedColor) { font = workbook.createFont();