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) + ")."); } }
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) + ")."); } }
XSSFColor bgcolor=cellStyle.getFillForegroundColorColor(); if(bgcolor!=null){ String hex=bgcolor.getARGBHex();