List of usage examples for org.apache.poi.ss.usermodel CellStyle setFillPattern
void setFillPattern(FillPatternType fp);
From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.export.template.ExcelStylesCreator.java
License:Open Source License
private static CellStyle getHeaderStyle(Workbook workbook) { CellStyle style = workbook.createCellStyle(); style.setFillPattern(CellStyle.SOLID_FOREGROUND); setCustomVioletForegroundColor(workbook, style); Font font = workbook.createFont(); font.setColor(IndexedColors.WHITE.getIndex()); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setFontHeightInPoints(EXCEL_HEADER_FONT_HEIGHT); font.setFontName(EXCEL_HEADER_FONT_NAME); style.setFont(font);/*from ww w . j a v a2 s .c o m*/ return style; }
From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.export.template.ExcelStylesCreator.java
License:Open Source License
private static CellStyle getDataHiddenStyle(Workbook workbook, CellStyle dataStyle) { CellStyle style = workbook.createCellStyle(); style.cloneStyleFrom(dataStyle);//from w ww .j a v a2s. co m style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); return style; }
From source file:de.jlo.talendcomp.excel.SpreadsheetFile.java
License:Apache License
/** * adds a font to the workbook/*from www . java 2s . co m*/ * @param family like Arial * @param height like 8,9,10,12,14... * @param bui with "b"=bold, "u"=underlined, "i"=italic and all combinations as String * @param color color index */ public void addStyle(String styleName, String fontFamily, String fontHeight, String fontDecoration, String fontColor, String bgColor, String textAlign, boolean buttomBorder) { if (styleName != null && styleName.isEmpty() == false) { Font f = workbook.createFont(); if (fontFamily != null && fontFamily.isEmpty() == false) { f.setFontName(fontFamily); } if (fontHeight != null && fontHeight.isEmpty() == false) { short height = Short.parseShort(fontHeight); if (height > 0) { f.setFontHeightInPoints(height); } } if (fontDecoration != null && fontDecoration.isEmpty() == false) { if (fontDecoration.contains("b")) { f.setBold(true); } if (fontDecoration.contains("i")) { f.setItalic(true); } if (fontDecoration.contains("u")) { f.setUnderline(Font.U_SINGLE); } } if (fontColor != null && fontColor.isEmpty() == false) { short color = Short.parseShort(fontColor); f.setColor(color); } CellStyle style = workbook.createCellStyle(); style.setFont(f); if (bgColor != null && bgColor.isEmpty() == false) { short color = Short.parseShort(bgColor); style.setFillForegroundColor(color); //style.setFillBackgroundColor(color); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); } if (textAlign != null && textAlign.isEmpty() == false) { if ("center".equalsIgnoreCase(textAlign)) { style.setAlignment(HorizontalAlignment.CENTER); } else if ("left".equalsIgnoreCase(textAlign)) { style.setAlignment(HorizontalAlignment.LEFT); } else if ("right".equals(textAlign)) { style.setAlignment(HorizontalAlignment.RIGHT); } } if (buttomBorder) { style.setBorderBottom(BorderStyle.MEDIUM); style.setBottomBorderColor((short) 9); } namedStyles.put(styleName, style); } }
From source file:de.maklerpoint.office.Schnittstellen.Excel.ExportExcelXLSX.java
License:Open Source License
/** * create a library of cell styles//from w w w . j ava 2 s . c om */ 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_CENTER); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); style.setDataFormat(df.getFormat("dd.MM.yyyy")); styles.put("header_date", style); Font font1 = wb.createFont(); font1.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font1); styles.put("cell_b", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFont(font1); styles.put("cell_b_centered", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setDataFormat(df.getFormat("dd.MM.yyyy")); styles.put("cell_b_date", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(df.getFormat("dd.MM.yyyy")); styles.put("cell_g", style); Font font2 = wb.createFont(); font2.setColor(IndexedColors.BLUE.getIndex()); font2.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font2); styles.put("cell_bb", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(df.getFormat("dd.MM.yyyy")); styles.put("cell_bg", style); Font font3 = wb.createFont(); font3.setFontHeightInPoints((short) 14); font3.setColor(IndexedColors.DARK_BLUE.getIndex()); font3.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font3); style.setWrapText(true); styles.put("cell_h", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setWrapText(true); styles.put("cell_normal", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setWrapText(true); styles.put("cell_normal_centered", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setWrapText(true); style.setDataFormat(df.getFormat("dd.MM.yyyy")); styles.put("cell_normal_date", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setIndention((short) 1); style.setWrapText(true); styles.put("cell_indented", style); style = createBorderedStyle(wb); style.setFillForegroundColor(IndexedColors.BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); styles.put("cell_blue", style); return styles; }
From source file:de.thb.ue.backend.util.EvaluationExcelFileGenerator.java
License:Apache License
private Cell colorizeCell(Cell cell, Workbook wb, float grade) { CellStyle style = wb.createCellStyle(); style.cloneStyleFrom(commonStyle);//ww w . j a v a 2 s .com if (grade >= 1.0 && grade < 2.0f) { style.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell.setCellStyle(style); } else if ((grade >= 3.0 && grade <= 4.0) || (grade <= -3.0 && grade >= -4.0)) { style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell.setCellStyle(style); } else if (grade > 4.0 || grade < -4.0) { style.setFillForegroundColor(HSSFColor.MAROON.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); cell.setCellStyle(style); } else { cell.setCellStyle(style); } return cell; }
From source file:de.unioninvestment.eai.portal.portlet.crud.export.streaming.ExcelExporter.java
License:Apache License
/** * Returns the default header style. Obtained from: * http://svn.apache.org/repos/asf/poi/*from w w w. ja v a 2s .co m*/ * /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java * * @param wb * the wb * * @return the cell style */ private CellStyle defaultHeaderCellStyle(final Workbook wb) { CellStyle style; final Font headerFont = wb.createFont(); if (!Strings.isNullOrEmpty(fontName)) { headerFont.setFontName(fontName); } headerFont.setFontHeightInPoints((short) 11); headerFont.setColor(IndexedColors.WHITE.getIndex()); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); style.setWrapText(true); return style; }
From source file:demo.poi.BusinessPlan.java
License:Apache License
/** * create a library of cell styles/*from ww w .j a v a 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.setFillBackgroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); styles.put("header", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); style.setDataFormat(df.getFormat("d-mmm")); styles.put("header_date", style); Font font1 = wb.createFont(); font1.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font1); styles.put("cell_b", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFont(font1); styles.put("cell_b_centered", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setDataFormat(df.getFormat("d-mmm")); styles.put("cell_b_date", style); style.setBottomBorderColor(IndexedColors.AQUA.index); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(df.getFormat("d-mmm")); styles.put("cell_g", style); Font font2 = wb.createFont(); font2.setColor(IndexedColors.BLUE.getIndex()); font2.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font2); styles.put("cell_bb", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(df.getFormat("d-mmm")); styles.put("cell_bg", style); Font font3 = wb.createFont(); font3.setFontHeightInPoints((short) 14); font3.setColor(IndexedColors.DARK_BLUE.getIndex()); font3.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font3); style.setWrapText(true); styles.put("cell_h", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setWrapText(true); styles.put("cell_normal", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setWrapText(true); styles.put("cell_normal_centered", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setWrapText(true); style.setDataFormat(df.getFormat("d-mmm")); styles.put("cell_normal_date", style); // ??? style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setIndention((short) 1); style.setWrapText(true); styles.put("cell_indented", style); style = createBorderedStyle(wb); style.setFillForegroundColor(IndexedColors.BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); styles.put("cell_blue", style); return styles; }
From source file:Documentos.ClaseAlmacenGeneral.java
private static void createCell(Workbook wb, Row row, int column, short halign, short valign, String strContenido, boolean booBorde, boolean booCabecera) { CreationHelper ch = wb.getCreationHelper(); Cell cell = row.createCell(column);//from w w w . ja v a 2s . c om cell.setCellValue(ch.createRichTextString(strContenido)); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(halign); cellStyle.setVerticalAlignment(valign); if (booBorde) { cellStyle.setBorderBottom(HSSFCellStyle.BORDER_DOTTED); cellStyle.setBottomBorderColor((short) 8); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_DOTTED); cellStyle.setLeftBorderColor((short) 8); cellStyle.setBorderRight(HSSFCellStyle.BORDER_DOTTED); cellStyle.setRightBorderColor((short) 8); cellStyle.setBorderTop(HSSFCellStyle.BORDER_DOTTED); cellStyle.setTopBorderColor((short) 8); } if (booCabecera) { cellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setBottomBorderColor((short) 8); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setLeftBorderColor((short) 8); cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setRightBorderColor((short) 8); cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setTopBorderColor((short) 8); cellStyle.setFillForegroundColor(HSSFColor.ROYAL_BLUE.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); } cell.setCellStyle(cellStyle); }
From source file:ec.sirec.web.impuestos.GestionImpuestoPredialControlador.java
public void postProcessXLS(Object document) throws IOException { XSSFWorkbook wb = (XSSFWorkbook) document; XSSFSheet hoja = wb.getSheetAt(0);/*from w ww. java 2 s . c o m*/ CellStyle style = wb.createCellStyle(); style.setFillPattern(CellStyle.NO_FILL); org.apache.poi.ss.usermodel.Font font = wb.createFont(); font.setFontName("Times Roman"); font.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); font.setColor(IndexedColors.BLACK.getIndex()); style.setFont(font); /** * ** Configuracin del estilo de la celda header de la tabla. ***** */ CellStyle styleHeaderTable = wb.createCellStyle(); styleHeaderTable.setFillPattern(CellStyle.NO_FILL); org.apache.poi.ss.usermodel.Font fontHeaderTable = wb.createFont(); fontHeaderTable.setFontName("Times Roman"); fontHeaderTable.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); fontHeaderTable.setColor(IndexedColors.BLACK.getIndex()); styleHeaderTable.setFont(fontHeaderTable); Sheet sheet = wb.getSheetAt(0); sheet.autoSizeColumn((short) 0); //ajusta el ancho de la primera columna sheet.autoSizeColumn((short) 1); sheet.autoSizeColumn((short) 2); for (int i = 0; i < 20; i++) { hoja.autoSizeColumn((short) i); } }
From source file:edu.vt.vbi.patric.common.ExcelHelper.java
License:Apache License
/** * This method creates a map of Cellstyle objects for page building. Note: this method used for HSSF pages * /*from ww w . ja v a 2 s .c om*/ * @return hashmap of styles */ private Map<String, CellStyle> createStyles() { // create custom colors HSSFPalette palette = ((HSSFWorkbook) wb).getCustomPalette(); // This replaces various shades of grey with custom colors palette.setColorAtIndex(HSSFColor.GREY_25_PERCENT.index, (byte) 0, // RGB red (0-255) (byte) 52, // RGB green (byte) 94 // RGB blue ); palette.setColorAtIndex(HSSFColor.GREY_40_PERCENT.index, (byte) 230, (byte) 240, (byte) 248); palette.setColorAtIndex(HSSFColor.GREY_50_PERCENT.index, (byte) 255, (byte) 193, (byte) 193); // Create header style CellStyle style = createBorderStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setColor(IndexedColors.WHITE.getIndex()); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setWrapText(true); style.setFont(headerFont); styles.put("header", style); // Create alternating-color body styles Font bodyFont = wb.createFont(); bodyFont.setFontHeightInPoints((short) 8); style = createBorderStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(bodyFont); style.setWrapText(true); styles.put("bg1", style); style = createBorderStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setWrapText(true); style.setFont(bodyFont); styles.put("bg2", style); // create style for empty cell style = createBorderStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(HSSFColor.GREY_50_PERCENT.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(bodyFont); style.setWrapText(true); styles.put("empty", style); return styles; }