List of usage examples for org.apache.poi.ss.usermodel CellStyle setFillPattern
void setFillPattern(FillPatternType fp);
From source file:net.algem.planning.export.PlanningExportService.java
License:Open Source License
/** * * @param wb workbook/* w w w .j a va 2s. c o m*/ * @return a map, each key-value composed of a style name and a cell style */ private Map<String, CellStyle> createStyles(HSSFWorkbook wb) { Map<String, CellStyle> styles = new HashMap<>(); HSSFFont nf = wb.createFont(); nf.setFontName("monospace"); HSSFFont bf = wb.createFont(); bf.setFontName("monospace"); bf.setBold(true); HSSFFont sf = wb.createFont(); sf.setFontHeightInPoints((short) 8); sf.setFontName("monospace"); CellStyle style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setWrapText(true); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); styles.put("header", style); //LEFT HEADER style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); style.setWrapText(true); style.setFont(bf); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_THIN); style.setBorderBottom(CellStyle.BORDER_DOTTED); styles.put("hour", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); style.setWrapText(false); style.setFont(sf); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_DOTTED); style.setBorderBottom(CellStyle.BORDER_THIN); styles.put("hour-quarter", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); style.setWrapText(false); style.setFont(sf); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_DASHED); style.setBorderBottom(CellStyle.BORDER_THIN); styles.put("hour-half", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); style.setWrapText(true); style.setFont(nf); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_THIN); style.setBorderBottom(CellStyle.BORDER_THIN); styles.put("hour-last", style); return styles; }
From source file:net.algem.planning.export.PlanningExportService.java
License:Open Source License
/** * * @param wb workbook/* w w w .j a va2 s . c o m*/ * @param schedule current schedule * @param cache styles cache * @return a cell style */ private CellStyle getCourseStyle(HSSFWorkbook wb, ScheduleObject schedule, Map<java.awt.Color, CellStyle> cache) { java.awt.Color color = colorizer.getScheduleColor(schedule); CellStyle cachedStyle = cache.get(color); if (cachedStyle != null) { return cachedStyle; } else { CellStyle style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); style.setWrapText(true); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_THIN); style.setBorderBottom(CellStyle.BORDER_THIN); style.setFillPattern(CellStyle.SOLID_FOREGROUND); //the cell is painted with a pattern that consists of foreground and background pixels. //If you use SOLID_FOREGROUND, just the foreground pixel are visible. //This color is different from the color used to render text, which is set with the font style.setFillForegroundColor(getColorIndex(wb, color)); // Unused because font is applied as richTextString property /*java.awt.Color textColor = colorizer.getTextColor(schedule); HSSFFont font = wb.createFont(); font.setColor(getColorIndex(wb, textColor)); style.setFont(font); cache.put(color, style);*/ return style; } }
From source file:net.ceos.project.poi.annotated.core.CellStyleHandler.java
License:Apache License
/** * Initialize default Header Cell Decorator. * //ww w .jav a 2 s .c o m * @param wb * the {@link Workbook} in use * @return the {@link CellStyle} header decorator */ protected static CellStyle initializeHeaderCellDecorator(final Workbook wb) { CellStyle cs = cellStyleFactory.newInstance(wb); /* add the alignment to the cell */ CellStyleHandler.applyAlignment(cs, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER); /* add the border to the cell */ CellStyleHandler.applyBorderDefault(cs); /* add the background to the cell */ cs.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); /* add the wrap mode to the cell */ cs.setWrapText(true); /* add the font style to the cell */ CellStyleHandler.applyFontDefault(wb, cs); return cs; }
From source file:net.ceos.project.poi.annotated.core.CellStyleHandler.java
License:Apache License
/** * Initialize {@link CellStyle} by Cell Decorator. * /* ww w . j a v a 2 s . co m*/ * @param wb * the {@link Workbook} in use * @param decorator * the {@link CellDecorator} to use * @return the {@link CellStyle} decorator * @throws ConfigurationException * given when {@link CellStyle} is missing */ protected static CellStyle initializeCellStyleByCellDecorator(final Workbook wb, final CellDecorator decorator) throws ConfigurationException { CellStyle cs = cellStyleFactory.newInstance(wb); try { /* add the alignment to the cell */ CellStyleHandler.applyAlignment(cs, decorator.getAlignment(), decorator.getVerticalAlignment()); /* add the border to the cell */ borderPropagationManagement(decorator); CellStyleHandler.applyBorder(cs, decorator.getBorderLeft(), decorator.getBorderRight(), decorator.getBorderTop(), decorator.getBorderBottom()); /* add the background to the cell */ cs.setFillForegroundColor(decorator.getForegroundColor()); cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); /* add the wrap mode to the cell */ cs.setWrapText(decorator.isWrapText()); /* add the font style to the cell */ CellStyleHandler.applyFont(wb, cs, decorator.getFontName(), decorator.getFontSize(), decorator.getFontColor(), decorator.isFontBold(), decorator.isFontItalic(), decorator.getFontUnderline()); } catch (Exception e) { throw new ConfigurationException(ExceptionMessage.CONFIGURATION_CELLSTYLE_MISSING.getMessage(), e); } return cs; }
From source file:net.ceos.project.poi.annotated.core.CellStyleHandler.java
License:Apache License
/** * Initialize {@link CellStyle} by XlsDecorator. * //from w ww .ja v a 2s. c om * @param wb * the {@link Workbook} in use * @param decorator * the {@link CellDecorator} to use * @return the {@link CellStyle} decorator * @throws ConfigurationException * given when {@link CellStyle} is missing */ protected static CellStyle initializeCellStyleByXlsDecorator(final Workbook wb, final XlsDecorator decorator) throws ConfigurationException { CellStyle cs = cellStyleFactory.newInstance(wb); try { /* add the alignment to the cell */ CellStyleHandler.applyAlignment(cs, decorator.alignment(), decorator.verticalAlignment()); /* add the border to the cell */ if (decorator.border() != 0 && isBorderPropagationValid(decorator)) { CellStyleHandler.applyBorder(cs, decorator.border(), decorator.border(), decorator.border(), decorator.border()); CellStyleHandler.applyBorderColor(cs, decorator.borderColor(), decorator.borderColor(), decorator.borderColor(), decorator.borderColor()); } else { CellStyleHandler.applyBorder(cs, decorator.borderLeft(), decorator.borderRight(), decorator.borderTop(), decorator.borderBottom()); CellStyleHandler.applyBorderColor(cs, decorator.borderLeftColor(), decorator.borderRightColor(), decorator.borderTopColor(), decorator.borderBottomColor()); } /* add the background to the cell */ cs.setFillForegroundColor(decorator.foregroundColor()); cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); /* add the wrap mode to the cell */ cs.setWrapText(decorator.wrapText()); /* add the font style to the cell */ CellStyleHandler.applyFont(wb, cs, decorator.fontName(), decorator.fontSize(), decorator.fontColor(), decorator.fontBold(), decorator.fontItalic(), decorator.fontUnderline()); } catch (Exception e) { throw new ConfigurationException(ExceptionMessage.CONFIGURATION_CELLSTYLE_MISSING.getMessage(), e); } return cs; }
From source file:net.ceos.project.poi.annotated.core.CellStyleHandler.java
License:Apache License
/** * Clone a cell style passed as parameter. * //from www . ja v a2 s . c o m * @param wb * the {@link Workbook} in use * @param csBase * the {@link CellStyle} base * @return the new cell style */ private static CellStyle cloneCellStyle(final Workbook wb, final CellStyle csBase) { CellStyle cs = cellStyleFactory.newInstance(wb); cs.setAlignment(csBase.getAlignment()); cs.setVerticalAlignment(csBase.getVerticalAlignment()); cs.setBorderTop(csBase.getBorderTop()); cs.setBorderBottom(csBase.getBorderBottom()); cs.setBorderLeft(csBase.getBorderLeft()); cs.setBorderRight(csBase.getBorderRight()); cs.setFillForegroundColor(csBase.getFillForegroundColor()); cs.setFillPattern(csBase.getFillPattern()); cs.setWrapText(csBase.getWrapText()); cs.setFont(wb.getFontAt(csBase.getFontIndex())); return cs; }
From source file:net.sourceforge.fenixedu.domain.phd.reports.PhdReport.java
License:Open Source License
protected CellStyle headerBackgroundStyle() { CellStyle style = workbook.createCellStyle(); style.setFillBackgroundColor(IndexedColors.AQUA.getIndex()); style.setFillPattern(CellStyle.BIG_SPOTS); return style; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.administrativeOffice.scholarship.utl.report.ReportStudentsUTLCandidates.java
License:Open Source License
private CellStyle headerBackgroundStyle(final HSSFWorkbook wb) { CellStyle style = wb.createCellStyle(); style.setFillBackgroundColor(IndexedColors.AQUA.getIndex()); style.setFillPattern(CellStyle.BIG_SPOTS); return style; }
From source file:nl.b3p.viewer.features.ExcelDownloader.java
License:Open Source License
/** * create a library of cell styles//ww w .j ava 2 s. c o m */ private static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); DataFormat df = wb.createDataFormat(); CellStyle style; Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); styles.put("header", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setWrapText(true); styles.put("cell_normal", style); return styles; }
From source file:nl.meine.scouting.solparser.writer.ExcelWriter.java
License:Open Source License
private void updateCellColor(Cell cell, short color) { CellStyle style = workbook.createCellStyle(); ;/*from www . j a v a2 s.co m*/ style.cloneStyleFrom(cell.getCellStyle()); style.setFillForegroundColor(color); style.setFillPattern(PatternFormatting.SOLID_FOREGROUND); cell.setCellStyle(style); }