List of usage examples for org.apache.poi.ss.usermodel Font setFontHeightInPoints
void setFontHeightInPoints(short height);
From source file:net.sourceforge.jaulp.export.excel.poi.ExportExcelUtils.java
License:Apache License
/** * Creates a new font from the given parameters. * * @param workbook/*from w w w. ja v a 2 s .c o m*/ * the workbook * @param fontName * the font name * @param boldweight * the boldweight * @param height * the height * @return the font */ public static Font newFont(Workbook workbook, String fontName, short boldweight, short height) { Font font = workbook.createFont(); font.setFontName(fontName); font.setBoldweight(boldweight); font.setFontHeightInPoints(height); return font; }
From source file:nl.meine.scouting.solparser.writer.ExcelWriter.java
License:Open Source License
private void createStyles() { headingStyle = workbook.createCellStyle(); Font f = workbook.createFont(); //set font 1 to 12 point type f.setFontHeightInPoints((short) 12); // make it bold //arial is the default font f.setBoldweight(Font.BOLDWEIGHT_BOLD); headingStyle.setFont(f);/*from w ww . j a v a 2 s . c om*/ //set a thin border headingStyle.setBorderBottom(CellStyle.BORDER_MEDIUM); headingStyle.setBorderLeft(CellStyle.BORDER_MEDIUM); headingStyle.setBorderTop(CellStyle.BORDER_MEDIUM); headingStyle.setBorderRight(CellStyle.BORDER_MEDIUM); normalStyle = workbook.createCellStyle(); normalStyle.setBorderBottom(CellStyle.BORDER_THIN); normalStyle.setBorderLeft(CellStyle.BORDER_THIN); normalStyle.setBorderTop(CellStyle.BORDER_THIN); normalStyle.setBorderRight(CellStyle.BORDER_THIN); Font f2 = workbook.createFont(); normalStyle.setFont(f2); }
From source file:nz.ac.auckland.abi.formatting.poi.ModelJSONToExcel.java
License:LGPL
/** * Create a library of cell styles//from w ww . ja va 2 s . c om */ 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:offishell.excel.Excel.java
License:MIT License
/** * <p>// w w w.java 2 s .com * Create {@link Excel} wrapper. * </p> * * @param path * @param book */ private Excel(Path path, XSSFWorkbook book) { this.path = path; this.book = book; this.excel = Locator.file(path); this.sheet = book.getSheetAt(0); this.baseStyle = book.createCellStyle(); this.dateStyle = book.createCellStyle(); CreationHelper helper = book.getCreationHelper(); DataFormat dateFormat = helper.createDataFormat(); Font font = book.createFont(); font.setFontName(" Medium"); font.setFontHeightInPoints((short) 10); baseStyle.setFont(font); baseStyle.setAlignment(HorizontalAlignment.CENTER); baseStyle.setVerticalAlignment(VerticalAlignment.CENTER); baseStyle.setShrinkToFit(true); baseStyle.setWrapText(true); dateStyle.cloneStyleFrom(baseStyle); dateStyle.setDataFormat(dateFormat.getFormat("yyyy/mm/dd")); }
From source file:om.edu.squ.squportal.portlet.tsurvey.dao.excel.TeachingSurveyExcelImpl.java
License:Open Source License
/** * //from www .j a va 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.endpoint.export.Exporter.java
License:Open Source License
protected void declareStyles() { dateStyle = book.createCellStyle();// w w w . ja v a 2 s . co m dateStyle.setDataFormat(creationHelper.createDataFormat().getFormat("m/d/yy")); coordStyle = book.createCellStyle(); coordStyle.setDataFormat(creationHelper.createDataFormat().getFormat("0.000000")); indicatorValueStyle = book.createCellStyle(); indicatorValueStyle.setDataFormat(creationHelper.createDataFormat().getFormat("#,##0")); Font headerFont = book.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); Font smallFont = book.createFont(); smallFont.setFontHeightInPoints((short) 8); headerStyle = book.createCellStyle(); headerStyle.setFont(headerFont); headerStyleCenter = book.createCellStyle(); headerStyleCenter.setFont(headerFont); headerStyleCenter.setAlignment(CellStyle.ALIGN_CENTER); headerStyleRight = book.createCellStyle(); headerStyleRight.setFont(headerFont); headerStyleRight.setAlignment(CellStyle.ALIGN_RIGHT); }
From source file:org.activityinfo.server.endpoint.export.SiteExporter.java
License:Open Source License
private void declareStyles() { dateStyle = book.createCellStyle();/*from w w w .ja v a2 s .co m*/ dateStyle.setDataFormat(creationHelper.createDataFormat().getFormat("m/d/yy")); dateTimeStyle = book.createCellStyle(); dateTimeStyle.setDataFormat(creationHelper.createDataFormat().getFormat("yyyy-mm-dd HH:MM:SS")); coordStyle = book.createCellStyle(); coordStyle.setDataFormat(creationHelper.createDataFormat().getFormat("0.000000")); indicatorValueStyle = book.createCellStyle(); indicatorValueStyle.setDataFormat(creationHelper.createDataFormat().getFormat("#,##0")); Font headerFont = book.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); Font smallFont = book.createFont(); smallFont.setFontHeightInPoints(FONT_SIZE); Font titleFont = book.createFont(); titleFont.setFontHeightInPoints(TITLE_FONT_SIZE); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); titleStyle = book.createCellStyle(); titleStyle.setFont(titleFont); headerStyle = book.createCellStyle(); headerStyle.setFont(headerFont); headerStyleCenter = book.createCellStyle(); headerStyleCenter.setFont(headerFont); headerStyleCenter.setAlignment(CellStyle.ALIGN_CENTER); headerStyleRight = book.createCellStyle(); headerStyleRight.setFont(headerFont); headerStyleRight.setAlignment(CellStyle.ALIGN_RIGHT); attribHeaderStyle = book.createCellStyle(); attribHeaderStyle.setFont(smallFont); attribHeaderStyle.setRotation(DIAGONAL); attribHeaderStyle.setWrapText(true); indicatorHeaderStyle = book.createCellStyle(); indicatorHeaderStyle.setFont(smallFont); indicatorHeaderStyle.setWrapText(true); indicatorHeaderStyle.setAlignment(CellStyle.ALIGN_RIGHT); attribValueStyle = book.createCellStyle(); attribValueStyle.setFont(smallFont); }
From source file:org.alanwilliamson.openbd.plugin.spreadsheet.SpreadSheetFormatOptions.java
License:Open Source License
public static Font createCommentFont(Workbook workbook, cfStructData _struct) throws Exception { Font font = workbook.createFont(); if (_struct.containsKey("bold")) { if (_struct.getData("bold").getBoolean()) font.setBoldweight(Font.BOLDWEIGHT_BOLD); else//from w w w . ja va2s.co m font.setBoldweight(Font.BOLDWEIGHT_NORMAL); } 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 font.setColor(s); } if (_struct.containsKey("font")) { font.setFontName(_struct.getData("font").getString()); } if (_struct.containsKey("italic")) { font.setItalic(_struct.getData("italic").getBoolean()); } if (_struct.containsKey("strikeout")) { font.setStrikeout(_struct.getData("strikeout").getBoolean()); } if (_struct.containsKey("underline")) { font.setUnderline((byte) _struct.getData("underline").getInt()); } if (_struct.containsKey("size")) { font.setFontHeightInPoints((short) _struct.getData("size").getInt()); } return font; }
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 ww. j av a2 s .com*/ 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.apache.ranger.biz.ServiceDBStore.java
License:Apache License
private void createHeaderRow(Sheet sheet) { CellStyle cellStyle = sheet.getWorkbook().createCellStyle(); Font font = sheet.getWorkbook().createFont(); font.setBold(true);/*from w w w .ja v a 2s . c o m*/ font.setFontHeightInPoints((short) 12); cellStyle.setFont(font); Row row = sheet.createRow(0); Cell cellID = row.createCell(0); cellID.setCellStyle(cellStyle); cellID.setCellValue("ID"); Cell cellNAME = row.createCell(1); cellNAME.setCellStyle(cellStyle); cellNAME.setCellValue("Name"); Cell cellResources = row.createCell(2); cellResources.setCellStyle(cellStyle); cellResources.setCellValue("Resources"); Cell cellGroups = row.createCell(3); cellGroups.setCellStyle(cellStyle); cellGroups.setCellValue("Groups"); Cell cellUsers = row.createCell(4); cellUsers.setCellStyle(cellStyle); cellUsers.setCellValue("Users"); Cell cellAccesses = row.createCell(5); cellAccesses.setCellStyle(cellStyle); cellAccesses.setCellValue("Accesses"); Cell cellServiceType = row.createCell(6); cellServiceType.setCellStyle(cellStyle); cellServiceType.setCellValue("Service Type"); Cell cellStatus = row.createCell(7); cellStatus.setCellStyle(cellStyle); cellStatus.setCellValue("Status"); }