XSSFCellStyle style = (XSSFCellStyle)cell.getCellStyle(); XSSFColor myColor = new XSSFColor(Color.RED); style.setFillForegroundColor(myColor);
errorOccured = true; XSSFCellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.RED.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); row.getCell(0).setCellStyle(style);
protected XSSFCellStyle createStyle(XSSFColor color) { XSSFCellStyle style = workbook.createCellStyle(); if (color != null) { style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFillForegroundColor(color); } style.setWrapText(true); style.setVerticalAlignment(VerticalAlignment.CENTER); return style; }
/** * Set the foreground fill color as a indexed color value * <br> * <i>Note: Ensure Foreground color is set prior to background color.</i> * @param fg the color to use * @see org.apache.poi.ss.usermodel.IndexedColors */ @Override public void setFillForegroundColor(short fg) { XSSFColor clr = XSSFColor.from(CTColor.Factory.newInstance(), _stylesSource.getIndexedColors()); clr.setIndexed(fg); setFillForegroundColor(clr); }
if (facetBackground != null) { XSSFColor backgroundColor = new XSSFColor(Color.decode(facetBackground)); ((XSSFCellStyle) facetStyle).setFillForegroundColor(backgroundColor); facetStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); XSSFRow row = sheet.createRow(0); XSSFCell cell = row.createCell( 0); cell.setCellValue("custom XSSF colors"); XSSFCellStyle style1 = wb.createCellStyle(); style1.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128))); style1.setFillPattern(CellStyle.SOLID_FOREGROUND);
XSSFCellStyle style = workbook.createCellStyle(); XSSFColor myColor = new XSSFColor(Color.RED); style.setFillForegroundColor(myColor); style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
XSSFCellStyle style1 = workbook.createCellStyle(); style1.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128))); style1.setFillPattern(CellStyle.SOLID_FOREGROUND); cell.setCellStyle(style1);
// get cell style XSSFCellStyle style = cell.getCellStyle(); // get default workbook style XSSFCellStyle defaultStyle = workbook.getCellStyleAt((short) 0) // if both are equals create new style in workbook if(style.equals(defaultStyle)) { style = workbook.createCellStyle(); } // assign color style.setFillForegroundColor(new XSSFColor(myColor)); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); // set style cell.setCellStyle(style);
/** * Set the foreground fill color as a indexed color value * <br/> * <i>Note: Ensure Foreground color is set prior to background color.</i> * @param fg the color to use * @see org.apache.poi.ss.usermodel.IndexedColors */ public void setFillForegroundColor(short fg) { XSSFColor clr = new XSSFColor(); clr.setIndexed(fg); setFillForegroundColor(clr); }
XSSFWorkbook wb = new XSSFWorkbook(); XSSFCellStyle cellStyle = wb.createCellStyle(); byte[] rgb = new byte[3]; rgb[0] = (byte) 242; // red rgb[1] = (byte) 220; // green rgb[2] = (byte) 219; // blue XSSFColor myColor = new XSSFColor(rgb); // #f2dcdb cellStyle.setFillForegroundColor(myColor); cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
cell.setCellValue("Header Text"); XSSFCellStyle headerStyle = wb.createCellStyle(); Font headerFont = wb.createFont(); headerStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex()); headerFont.setColor(IndexedColors.WHITE.getIndex()); headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); headerStyle.setFont(headerFont); cell.setCellStyle(headerStyle);
CellStyle createHeaderStyle(Workbook wb){ XSSFCellStyle xstyle = (XSSFCellStyle)wb.createCellStyle(); XSSFColor header = new XSSFColor(new Color(79, 129, 189)); xstyle.setFillForegroundColor(header); xstyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); XSSFFont font = (XSSFFont)wb.createFont(); font.setColor(IndexedColors.WHITE.index); xstyle.setFont(font); return xstyle; }
SXSSFWorkbook workbook = new SXSSFWorkbook(50); Sheet sheet = workbook.createSheet("Image Data"); .... Cell cell = row.createCell(j); cell.setCellValue(j); XSSFCellStyle cs1 = (XSSFCellStyle) workbook.createCellStyle(); cs1.setFillForegroundColor(new XSSFColor(new java.awt.Color(red,green,blue))); cs1.setFillPattern(CellStyle.SOLID_FOREGROUND); cell.setCellStyle(cs1);
CellStyle createHeaderStyle(Workbook wb) { XSSFCellStyle xstyle = (XSSFCellStyle) wb.createCellStyle(); XSSFColor header = new XSSFColor(new Color(79, 129, 189)); xstyle.setFillForegroundColor(header); xstyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); XSSFFont font = (XSSFFont) wb.createFont(); font.setColor(IndexedColors.WHITE.index); xstyle.setFont(font); return xstyle; }
XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); XSSFRow row = sheet.createRow(0); XSSFCell cell = row.createCell( 0); cell.setCellValue("custom XSSF colors"); XSSFCellStyle style1 = wb.createCellStyle(); style1.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128))); style1.setFillPattern(CellStyle.SOLID_FOREGROUND);
protected XSSFCellStyle createStyle(XSSFColor color) { XSSFCellStyle style = workbook.createCellStyle(); if (color != null) { style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFillForegroundColor(color); } style.setWrapText(true); style.setVerticalAlignment(VerticalAlignment.CENTER); return style; }
/** * Set the foreground fill color as a indexed color value * <br> * <i>Note: Ensure Foreground color is set prior to background color.</i> * @param fg the color to use * @see org.apache.poi.ss.usermodel.IndexedColors */ @Override public void setFillForegroundColor(short fg) { XSSFColor clr = XSSFColor.from(CTColor.Factory.newInstance(), _stylesSource.getIndexedColors()); clr.setIndexed(fg); setFillForegroundColor(clr); }
style.setFillForegroundColor(buildXSSFColor(bgcolor));
XSSFCellStyle styleSubHeader = (XSSFCellStyle) wb.createCellStyle(); styleSubHeader.setFont(fontBold); styleSubHeader.setVerticalAlignment(CellStyle.VERTICAL_CENTER); styleSubHeader.setAlignment(CellStyle.ALIGN_CENTER); styleSubHeader.setFillForegroundColor(COLOR_ORANGE); styleSubHeader.setFillPattern(CellStyle.SOLID_FOREGROUND); styleSubHeader.setBorderBottom(CellStyle.BORDER_THIN); styleSubHeader.setBottomBorderColor(COLOR_GREY); styleSubHeader.setBorderLeft(CellStyle.BORDER_THIN); styleSubHeader.setLeftBorderColor(COLOR_GREY); styleSubHeader.setBorderRight(CellStyle.BORDER_THIN); styleSubHeader.setRightBorderColor(COLOR_GREY); styleSubHeader.setBorderTop(CellStyle.BORDER_THIN); styleSubHeader.setTopBorderColor(COLOR_GREY);