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; }
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);
/** * This element is used to specify cell fill information for pattern and solid color cell fills. For solid cell fills (no pattern), * foreground color is used is used. For cell fills with patterns specified, then the cell fill color is specified by the background color element. * * @param ptrn the fill pattern to use * @see #setFillBackgroundColor(short) * @see #setFillForegroundColor(short) * @see org.apache.poi.ss.usermodel.FillPatternType */ public void setFillPattern(FillPatternType ptrn) { setFillPattern((short)ptrn.ordinal()); }
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);
XSSFCellStyle style1 = wb.createCellStyle(); style1.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128))); style1.setFillPattern(CellStyle.SOLID_FOREGROUND); cell.setCellStyle(style1);
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);
for(i=0;i<rowsize;i++){ // //I suppose that we have an instance named row to working on. // XSSFCell cell = row.getCell(i); XSSFCellStyle style1 = wb.createCellStyle(); //create a fresh instance cell.setCellValue("custom XSSF colors"); //Set the cell value //This two line will setup the style of your cell with your needs style1.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128))); style1.setFillPattern(CellStyle.SOLID_FOREGROUND); //Finally apply your style cell.setCellStyle(style1); }
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; }
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; }
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);
style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFillForegroundColor(buildXSSFColor(bgcolor));
public static XSSFCellStyle getHeadCellStyle(XSSFWorkbook wb, XSSFFont font) { XSSFCellStyle headCellStyle = wb.createCellStyle(); headCellStyle.setFont(font); headCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); headCellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); headCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); headCellStyle.setWrapText(false); headCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); return headCellStyle; }
SerialWriteWorkbook() { this.swb = new SXSSFWorkbook(100); this.sh = this.swb.createSheet(); this.rowIndex = 0; this.headerStyle = (XSSFCellStyle)swb.createCellStyle(); this.headerStyle.setFillBackgroundColor(IndexedColors.BLACK.getIndex()); //solid fill this.headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); Font headerFont = swb.createFont(); headerFont.setFontHeightInPoints((short)14); headerFont.setBold(true); headerFont.setColor(IndexedColors.WHITE.getIndex()); this.headerStyle.setFont(headerFont); }
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);