/** * @see HSSFColor#getIndex() */ public short getIndex() { return color.getIndex(); }
HSSFColor lightGray = setColor(workbook,(byte) 0xE0, (byte)0xE0,(byte) 0xE0); style2.setFillForegroundColor(lightGray.getIndex()); style2.setFillPattern(CellStyle.SOLID_FOREGROUND);
HSSFWorkbook hwb = new HSSFWorkbook(); HSSFPalette palette = hwb.getCustomPalette(); // get the color which most closely matches the color you want to use HSSFColor myColor = palette.findSimilarColor(255, 0, 0); // get the palette index of that color short palIndex = myColor.getIndex(); // code to get the style for the cell goes here style.setFillForegroundColor(palIndex);
public void setFontColor(Color color) { HSSFColor hcolor = HSSFColor.toHSSFColor(color); if (hcolor == null) { fontFormatting.setFontColorIndex((short)0); } else { fontFormatting.setFontColorIndex(hcolor.getIndex()); } }
@Override public void setTopBorderColor(Color color) { HSSFColor hcolor = HSSFColor.toHSSFColor(color); if (hcolor == null) { setTopBorderColor((short) 0); } else { setTopBorderColor(hcolor.getIndex()); } }
public void setBottomBorderColor(Color color) { HSSFColor hcolor = HSSFColor.toHSSFColor(color); if (hcolor == null) { setBottomBorderColor((short) 0); } else { setBottomBorderColor(hcolor.getIndex()); } }
public void setFillForegroundColor(Color fg) { HSSFColor hcolor = HSSFColor.toHSSFColor(fg); if (hcolor == null) { setFillForegroundColor((short)0); } else { setFillForegroundColor(hcolor.getIndex()); } }
@Override public void setLeftBorderColor(Color color) { HSSFColor hcolor = HSSFColor.toHSSFColor(color); if (hcolor == null) { setLeftBorderColor((short) 0); } else { setLeftBorderColor(hcolor.getIndex()); } }
@Override public void setRightBorderColor(Color color) { HSSFColor hcolor = HSSFColor.toHSSFColor(color); if (hcolor == null) { setRightBorderColor((short) 0); } else { setRightBorderColor(hcolor.getIndex()); } }
public void setFillBackgroundColor(Color bg) { HSSFColor hcolor = HSSFColor.toHSSFColor(bg); if (hcolor == null) { setFillBackgroundColor((short)0); } else { setFillBackgroundColor(hcolor.getIndex()); } }
@Override public void setDiagonalBorderColor(Color color) { HSSFColor hcolor = HSSFColor.toHSSFColor(color); if (hcolor == null) { setDiagonalBorderColor((short) 0); } else { setDiagonalBorderColor(hcolor.getIndex()); } }
private HSSFFont matchFont( Font matchFont ) { HSSFColor hssfColor = workbook.getCustomPalette() .findColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue()); if (hssfColor == null) hssfColor = workbook.getCustomPalette().findSimilarColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue()); boolean bold = (matchFont.getStyle() & Font.BOLD) != 0; boolean italic = (matchFont.getStyle() & Font.ITALIC) != 0; HSSFFont hssfFont = workbook.findFont(bold, hssfColor.getIndex(), (short)(matchFont.getSize() * 20), matchFont.getName(), italic, false, (short)0, (byte)0); if (hssfFont == null) { hssfFont = workbook.createFont(); hssfFont.setBold(bold); hssfFont.setColor(hssfColor.getIndex()); hssfFont.setFontHeight((short)(matchFont.getSize() * 20)); hssfFont.setFontName(matchFont.getName()); hssfFont.setItalic(italic); hssfFont.setStrikeout(false); hssfFont.setTypeOffset((short) 0); hssfFont.setUnderline((byte) 0); } return hssfFont; }
color = Color.decode(facetBackground); HSSFColor backgroundColor = palette.findSimilarColor(color.getRed(), color.getGreen(), color.getBlue()); ((HSSFCellStyle) facetStyle).setFillForegroundColor(backgroundColor.getIndex()); facetStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); color = Color.decode(facetFontColor); HSSFColor facetColor = palette.findSimilarColor(color.getRed(), color.getGreen(), color.getBlue()); ((HSSFFont) facetFont).setColor(facetColor.getIndex());
Color color = Color.decode(cellFontColor); HSSFColor cellColor = palette.findSimilarColor(color.getRed(), color.getGreen(), color.getBlue()); ((HSSFFont) cellFont).setColor(cellColor.getIndex());
public HSSFColor newCustomColor(HSSFColor replaceColor, Color newColor) { HSSFColor hssfColor = new CustomColor(replaceColor.getIndex(), newColor); colorsReplaceMap.put(replaceColor, hssfColor); return hssfColor; }
style.setFillPattern(FillPatternType.SOLID_FOREGROUND); HSSFColor hssfColor=buildHSSFColor(wb,bgcolor); style.setFillForegroundColor(hssfColor.getIndex()); BorderStyle borderStyle=getBorderStyle(topBorder); HSSFColor borderColor=buildHSSFColor(wb,topBorder.getColor()); style.setTopBorderColor(borderColor.getIndex()); style.setBorderTop(borderStyle); BorderStyle borderStyle=getBorderStyle(bottomBorder); HSSFColor borderColor=buildHSSFColor(wb,bottomBorder.getColor()); style.setBottomBorderColor(borderColor.getIndex()); style.setBorderBottom(borderStyle); BorderStyle borderStyle=getBorderStyle(leftBorder); HSSFColor borderColor=buildHSSFColor(wb,leftBorder.getColor()); style.setLeftBorderColor(borderColor.getIndex()); style.setBorderLeft(borderStyle); BorderStyle borderStyle=getBorderStyle(rightBorder); HSSFColor borderColor=buildHSSFColor(wb,rightBorder.getColor()); style.setRightBorderColor(borderColor.getIndex()); style.setBorderRight(borderStyle); font.setColor(fontColor.getIndex()); String fontFamily=cellStyle.getFontFamily(); if(customStyle!=null && customStyle.getFontFamily()!=null){
public void setFontColor(Color color) { HSSFColor hcolor = HSSFColor.toHSSFColor(color); if (hcolor == null) { fontFormatting.setFontColorIndex((short)0); } else { fontFormatting.setFontColorIndex(hcolor.getIndex()); } }
public BoxStyle(int side, JRPen pen) { borderStyle[side] = getBorderStyle(pen); borderColour[side] = getNearestColor(pen.getLineColor()).getIndex(); hash = computeHash(); }
public void setBox(JRLineBox box) { borderStyle[TOP] = getBorderStyle(box.getTopPen()); borderColour[TOP] = getNearestColor(box.getTopPen().getLineColor()).getIndex(); borderStyle[BOTTOM] = getBorderStyle(box.getBottomPen()); borderColour[BOTTOM] = getNearestColor(box.getBottomPen().getLineColor()).getIndex(); borderStyle[LEFT] = getBorderStyle(box.getLeftPen()); borderColour[LEFT] = getNearestColor(box.getLeftPen().getLineColor()).getIndex(); borderStyle[RIGHT] = getBorderStyle(box.getRightPen()); borderColour[RIGHT] = getNearestColor(box.getRightPen().getLineColor()).getIndex(); hash = computeHash(); }