List of usage examples for org.apache.poi.ss.usermodel CellStyle setWrapText
void setWrapText(boolean wrapped);
From source file:net.ceos.project.poi.annotated.core.CellStyleHandler.java
License:Apache License
/** * Initialize default Header Cell Decorator. * /*w w w .j av a 2 s. co 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. * /*from w w w. ja v a 2s. c o 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 ww w . ja v a2 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 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 w w w . j a va2 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:nl.b3p.viewer.features.ExcelDownloader.java
License:Open Source License
/** * create a library of cell styles/*ww w . j av a 2s . 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:nz.ac.auckland.abi.formatting.poi.ModelJSONToExcel.java
License:LGPL
/** * Create a library of cell styles/*from ww w . j av a2 s . c o m*/ */ private static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 18); titleFont.setBoldweight(Font.BOLDWEIGHT_NORMAL); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(titleFont); styles.put("title", style); Font monthFont = wb.createFont(); monthFont.setFontHeightInPoints((short) 11); monthFont.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(monthFont); style.setWrapText(true); styles.put("header", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setWrapText(true); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); styles.put("cell", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("formula", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("formula_2", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.RED.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("MAX", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("MIN", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREEN.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("AVERAGE", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("STDEV", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("AVGSERIES", style); return styles; }
From source file:om.edu.squ.squportal.portlet.tsurvey.dao.excel.TeachingSurveyExcelImpl.java
License:Open Source License
/** * /*from www.j a v a 2 s . c o m*/ * method name : createStyles * @param wb * @return * TeachingSurveyExcelImpl * return type : Map<String,CellStyle> * * purpose : Creating Styles for Excell sheet cells * * Date : Mar 16, 2016 1:25:00 PM */ private static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style; /*** TITLE ***/ Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 18); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(titleFont); styles.put(TITLE, style); /*** SUB-HEADER ***/ Font subHeaderFont = wb.createFont(); subHeaderFont.setFontHeightInPoints((short) 9); subHeaderFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style = wb.createCellStyle(); style.setFont(subHeaderFont); style.setWrapText(true); styles.put(SUB_HEADER, style); /*** MAX. TWO DIGIT DECIMAL VALUE ***/ style = wb.createCellStyle(); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put(FORMULA_1, style); return styles; }
From source file:org.activityinfo.server.report.renderer.excel.ExcelPivotTableRenderer.java
License:Open Source License
@Override public void render(Workbook book, PivotTableReportElement element) { /* Generate the actual pivot table data */ final PivotTableData table = element.getContent().getData(); /* Generate the excel sheet */ new BaseExcelTableRenderer<PivotTableReportElement, PivotTableData.Axis>(book, element) { @Override// ww w. j a va 2 s. c o m public List<FilterDescription> generateFilterDescriptions() { return element.getContent().getFilterDescriptions(); } private CellStyle[] rowHeaderStyles; @Override public void generate() { /* Initialize Cell Styles */ initColHeaderStyles(table.getRootColumn()); initRowHeaderStyles(); /* Generate the column headers */ generateColumnHeaders(1, table.getRootColumn()); int headerHeight = rowIndex; /* Create the rows */ // row headers are in column 1 sheet.setColumnWidth(0, 40 * 256); generateRows(table.getRootRow().getChildList(), 0); /* Finalize the sheet */ sheet.setRowSumsBelow(false); sheet.createFreezePane(1, headerHeight); } protected void initRowHeaderStyles() { int depth = table.getRootRow().getDepth(); rowHeaderStyles = new CellStyle[depth]; for (int i = 0; i != depth; ++i) { CellStyle style = book.createCellStyle(); style.setIndention((short) i); style.setWrapText(true); Font font = createBaseFont(); if (i + 1 != depth) { /* Has sub headers */ font.setBoldweight(Font.BOLDWEIGHT_BOLD); } else { font.setBoldweight(Font.BOLDWEIGHT_NORMAL); } style.setFont(font); rowHeaderStyles[i] = style; } } protected void generateRows(List<PivotTableData.Axis> rows, int indent) { for (PivotTableData.Axis pivotRow : rows) { Row row = sheet.createRow(rowIndex++); Cell headerCell = row.createCell(0); headerCell.setCellValue(factory.createRichTextString(pivotRow.getLabel())); headerCell.setCellStyle(rowHeaderStyles[indent]); if (pivotRow.isLeaf()) { for (Entry<PivotTableData.Axis, Integer> entry : colIndexMap.entrySet()) { PivotTableData.Cell pivotCell = pivotRow.getCell(entry.getKey()); if (pivotCell != null) { Cell cell = row.createCell(entry.getValue()); cell.setCellValue(pivotCell.getValue()); } } } else { int groupStart = rowIndex; generateRows(pivotRow.getChildList(), indent + 1); int groupEnd = rowIndex; sheet.groupRow(groupStart, groupEnd); } } } }; }
From source file:org.alanwilliamson.openbd.plugin.spreadsheet.SpreadSheetFormatOptions.java
License:Open Source License
public static CellStyle createCellStyle(Workbook workbook, cfStructData _struct) throws Exception { CellStyle style = workbook.createCellStyle(); if (_struct.containsKey("alignment")) { String v = _struct.getData("alignment").getString(); Short s = lookup_alignment.get(v); if (s == null) { throw new Exception("invalid parameter for 'alignment' (" + v + ")"); } else/*from w w w . j av a 2 s.c o m*/ style.setAlignment(s); } if (_struct.containsKey("bottomborder")) { String v = _struct.getData("bottomborder").getString(); Short s = lookup_border.get(v); if (s == null) { throw new Exception("invalid parameter for 'bottomborder' (" + v + ")"); } else style.setBorderBottom(s); } if (_struct.containsKey("topborder")) { String v = _struct.getData("topborder").getString(); Short s = lookup_border.get(v); if (s == null) { throw new Exception("invalid parameter for 'topborder' (" + v + ")"); } else style.setBorderTop(s); } if (_struct.containsKey("leftborder")) { String v = _struct.getData("leftborder").getString(); Short s = lookup_border.get(v); if (s == null) { throw new Exception("invalid parameter for 'leftborder' (" + v + ")"); } else style.setBorderLeft(s); } if (_struct.containsKey("rightborder")) { String v = _struct.getData("rightborder").getString(); Short s = lookup_border.get(v); if (s == null) { throw new Exception("invalid parameter for 'rightborder' (" + v + ")"); } else style.setBorderRight(s); } if (_struct.containsKey("bottombordercolor")) { String v = _struct.getData("bottombordercolor").getString(); Short s = lookup_colors.get(v); if (s == null) { throw new Exception("invalid parameter for 'bottombordercolor' (" + v + ")"); } else style.setBottomBorderColor(s); } if (_struct.containsKey("topbordercolor")) { String v = _struct.getData("topbordercolor").getString(); Short s = lookup_colors.get(v); if (s == null) { throw new Exception("invalid parameter for 'topbordercolor' (" + v + ")"); } else style.setTopBorderColor(s); } if (_struct.containsKey("leftbordercolor")) { String v = _struct.getData("leftbordercolor").getString(); Short s = lookup_colors.get(v); if (s == null) { throw new Exception("invalid parameter for 'leftbordercolor' (" + v + ")"); } else style.setLeftBorderColor(s); } if (_struct.containsKey("rightbordercolor")) { String v = _struct.getData("rightbordercolor").getString(); Short s = lookup_colors.get(v); if (s == null) { throw new Exception("invalid parameter for 'rightbordercolor' (" + v + ")"); } else style.setRightBorderColor(s); } if (_struct.containsKey("fillpattern")) { String v = _struct.getData("fillpattern").getString(); Short s = lookup_fillpatten.get(v); if (s == null) { throw new Exception("invalid parameter for 'fillpattern' (" + v + ")"); } else style.setFillPattern(s); } if (_struct.containsKey("fgcolor")) { String v = _struct.getData("fgcolor").getString(); Short s = lookup_colors.get(v); if (s == null) { throw new Exception("invalid parameter for 'fgcolor' (" + v + ")"); } else style.setFillForegroundColor(s); } if (_struct.containsKey("bgcolor")) { String v = _struct.getData("bgcolor").getString(); Short s = lookup_colors.get(v); if (s == null) { throw new Exception("invalid parameter for 'bgcolor' (" + v + ")"); } else style.setFillBackgroundColor(s); } if (_struct.containsKey("textwrap")) { Boolean b = _struct.getData("textwrap").getBoolean(); style.setWrapText(b); } if (_struct.containsKey("hidden")) { Boolean b = _struct.getData("hidden").getBoolean(); style.setHidden(b); } if (_struct.containsKey("locked")) { Boolean b = _struct.getData("locked").getBoolean(); style.setLocked(b); } if (_struct.containsKey("indent")) { style.setIndention((short) _struct.getData("indent").getInt()); } if (_struct.containsKey("rotation")) { style.setRotation((short) _struct.getData("rotation").getInt()); } if (_struct.containsKey("dateformat")) { style.setDataFormat(workbook.createDataFormat().getFormat(_struct.getData("dateformat").getString())); } // Manage the fonts Font f = workbook.createFont(); if (_struct.containsKey("strikeout")) { f.setStrikeout(true); } if (_struct.containsKey("bold")) { Boolean b = _struct.getData("bold").getBoolean(); f.setBoldweight(b ? Font.BOLDWEIGHT_BOLD : Font.BOLDWEIGHT_NORMAL); } if (_struct.containsKey("underline")) { String v = _struct.getData("underline").getString(); Byte b = lookup_underline.get(v); if (b == null) { throw new Exception("invalid parameter for 'underline' (" + v + ")"); } else f.setUnderline(b); } if (_struct.containsKey("color")) { String v = _struct.getData("color").getString(); Short s = lookup_colors.get(v); if (s == null) { throw new Exception("invalid parameter for 'color' (" + v + ")"); } else f.setColor(s); } if (_struct.containsKey("fontsize")) { int s = _struct.getData("fontsize").getInt(); f.setFontHeightInPoints((short) s); } if (_struct.containsKey("font")) { f.setFontName(_struct.getData("font").getString()); } style.setFont(f); return style; }
From source file:org.alfresco.repo.web.scripts.datalist.DataListDownloadWebScript.java
License:Open Source License
@Override protected void populateBody(Object resource, Workbook workbook, Sheet sheet, List<QName> properties) throws IOException { NodeRef list = (NodeRef) resource;//from w ww.j a v a2 s. co m List<NodeRef> items = getItems(list); // Our various formats DataFormat formatter = workbook.createDataFormat(); CellStyle styleInt = workbook.createCellStyle(); styleInt.setDataFormat(formatter.getFormat("0")); CellStyle styleDate = workbook.createCellStyle(); styleDate.setDataFormat(formatter.getFormat("yyyy-mm-dd")); CellStyle styleDouble = workbook.createCellStyle(); styleDouble.setDataFormat(formatter.getFormat("General")); CellStyle styleNewLines = workbook.createCellStyle(); styleNewLines.setWrapText(true); // Export the items int rowNum = 1, colNum = 0; for (NodeRef item : items) { Row r = sheet.createRow(rowNum); colNum = 0; for (QName prop : properties) { Cell c = r.createCell(colNum); Serializable val = nodeService.getProperty(item, prop); if (val == null) { // Is it an association, or just missing? List<AssociationRef> assocs = nodeService.getTargetAssocs(item, prop); if (assocs.size() > 0) { StringBuffer text = new StringBuffer(); int lines = 1; for (AssociationRef ref : assocs) { NodeRef child = ref.getTargetRef(); QName type = nodeService.getType(child); if (ContentModel.TYPE_PERSON.equals(type)) { if (text.length() > 0) { text.append('\n'); lines++; } text.append(nodeService.getProperty(child, ContentModel.PROP_USERNAME)); } else if (ContentModel.TYPE_CONTENT.equals(type)) { // TODO Link to the content if (text.length() > 0) { text.append('\n'); lines++; } text.append(nodeService.getProperty(child, ContentModel.PROP_TITLE)); } else { System.err.println("TODO: handle " + type + " for " + child); } } String v = text.toString(); c.setCellValue(v); if (lines > 1) { c.setCellStyle(styleNewLines); r.setHeightInPoints(lines * sheet.getDefaultRowHeightInPoints()); } } else { // This property isn't set c.setCellType(Cell.CELL_TYPE_BLANK); } } else { // Regular property, set if (val instanceof String) { c.setCellValue((String) val); } else if (val instanceof Date) { c.setCellValue((Date) val); c.setCellStyle(styleDate); } else if (val instanceof Integer || val instanceof Long) { double v = 0.0; if (val instanceof Long) v = (double) (Long) val; if (val instanceof Integer) v = (double) (Integer) val; c.setCellValue(v); c.setCellStyle(styleInt); } else if (val instanceof Float || val instanceof Double) { double v = 0.0; if (val instanceof Float) v = (double) (Float) val; if (val instanceof Double) v = (double) (Double) val; c.setCellValue(v); c.setCellStyle(styleDouble); } else { // TODO System.err.println("TODO: handle " + val.getClass().getName() + " - " + val); } } colNum++; } rowNum++; } // Sensible column widths please! colNum = 0; for (QName prop : properties) { sheet.autoSizeColumn(colNum); colNum++; } }