Example usage for org.apache.poi.ss.usermodel Font setFontHeightInPoints

List of usage examples for org.apache.poi.ss.usermodel Font setFontHeightInPoints

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Font setFontHeightInPoints.

Prototype


void setFontHeightInPoints(short height);

Source Link

Document

set the font height

Usage

From source file:de.alpharogroup.export.excel.poi.ExcelPoiFactory.java

License:Open Source License

/**
 * Creates a new font from the given parameters.
 *
 * @param workbook/*from   w  ww  .j  av 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(final Workbook workbook, final String fontName, final short boldweight,
        final short height) {
    final Font font = workbook.createFont();
    font.setFontName(fontName);
    font.setBoldweight(boldweight);
    font.setFontHeightInPoints(height);
    return font;
}

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 om

    return style;
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.legacyExcel.exporter.ExportWorkbook.java

License:Open Source License

/**
 * initializes all styles used in the workbook
 *//*from  w w  w. j  av  a  2 s  .c  o  m*/
private void initStyles() {

    titleStyle = getWb().createCellStyle();
    headerStyle = getWb().createCellStyle();
    headerTableStyle = getWb().createCellStyle();
    dateStyle = getWb().createCellStyle();
    wrappedStyle = getWb().createCellStyle();
    defaultStyle = getWb().createCellStyle();
    hyperlinkStyle = getWb().createCellStyle();

    DataFormat df = getWb().createDataFormat();

    Font font = getWb().createFont();
    font.setFontHeightInPoints((short) 12);
    font.setFontName(ExcelWorkbook.EXCEL_DEFAULT_FONT);
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    titleStyle.setFont(font);

    font = getWb().createFont();
    font.setFontHeightInPoints((short) 11);
    font.setFontName(ExcelWorkbook.EXCEL_DEFAULT_FONT);
    headerStyle.setFont(font);

    font = getWb().createFont();
    font.setFontHeightInPoints((short) 11);
    font.setFontName(ExcelWorkbook.EXCEL_DEFAULT_FONT);
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerTableStyle.setFont(font);

    dateStyle.setDataFormat(df.getFormat("m/d/yy"));
    setAlignementTopLeft(dateStyle);

    wrappedStyle.setWrapText(true);
    setAlignementTopLeft(wrappedStyle);

    setAlignementTopLeft(defaultStyle);

    Font hlinkFont = getWb().createFont();
    hlinkFont.setUnderline(Font.U_SINGLE);
    hlinkFont.setColor(IndexedColors.BLUE.getIndex());
    setAlignementTopLeft(hyperlinkStyle);
    hyperlinkStyle.setFont(hlinkFont);
}

From source file:de.jlo.talendcomp.excel.SpreadsheetFile.java

License:Apache License

/**
 * adds a font to the workbook//  w ww  . ja  v a  2s  .com
 * @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.ks.idnadrev.expimp.xls.XlsxExporter.java

License:Apache License

private CellStyle getTitleStyle() {
    CellStyle cellStyle = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setFontHeightInPoints((short) 12);
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    cellStyle.setFont(font);// w ww  . j a va2 s  .  com
    return cellStyle;
}

From source file:de.maklerpoint.office.Schnittstellen.Excel.ExportExcelXLSX.java

License:Open Source License

/**
 * create a library of cell styles//from   ww  w .ja v  a2 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_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 void configureCellStyles(Workbook wb) {
    commonStyle = wb.createCellStyle();/* w  w w .j a  va 2  s.c  o m*/
    headerStyle = wb.createCellStyle();
    questionStyle = wb.createCellStyle();
    positiveStyle = wb.createCellStyle();
    positiveHeaderStyle = wb.createCellStyle();
    negativeStyle = wb.createCellStyle();
    negativeHeaderStyle = wb.createCellStyle();
    improvementStyle = wb.createCellStyle();
    improvementHeaderStyle = wb.createCellStyle();
    furtherStyle = wb.createCellStyle();
    furtherHeaderStyle = wb.createCellStyle();

    Font headerFont = wb.createFont();
    headerFont.setBold(true);

    Font smallFont = wb.createFont();
    smallFont.setFontHeightInPoints((short) 8);

    commonStyle.setBorderBottom(CellStyle.BORDER_HAIR);
    commonStyle.setBorderTop(CellStyle.BORDER_HAIR);
    commonStyle.setBorderLeft(CellStyle.BORDER_HAIR);
    commonStyle.setBorderRight(CellStyle.BORDER_HAIR);
    commonStyle.setAlignment(CellStyle.ALIGN_CENTER);
    questionStyle.cloneStyleFrom(commonStyle);
    questionStyle.setFont(smallFont);
    questionStyle.setAlignment(CellStyle.ALIGN_LEFT);
    headerStyle.cloneStyleFrom(commonStyle);
    headerStyle.setFont(headerFont);

    positiveStyle.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index);
    positiveStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    //        positiveStyle.setWrapText(true);

    negativeStyle.setFillForegroundColor(HSSFColor.ROSE.index);
    negativeStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    //        negativeStyle.setWrapText(true);

    improvementStyle.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
    improvementStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    //        improvementStyle.setWrapText(true);

    furtherStyle.setFillForegroundColor(HSSFColor.LIGHT_TURQUOISE.index);
    furtherStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    //        furtherStyle.setWrapText(true);

    positiveHeaderStyle.cloneStyleFrom(positiveStyle);
    positiveHeaderStyle.setFont(headerFont);

    negativeHeaderStyle.cloneStyleFrom(negativeStyle);
    negativeHeaderStyle.setFont(headerFont);

    improvementHeaderStyle.cloneStyleFrom(improvementStyle);
    improvementHeaderStyle.setFont(headerFont);

    furtherHeaderStyle.cloneStyleFrom(furtherStyle);
    furtherHeaderStyle.setFont(headerFont);
}

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/* w  ww. ja v  a  2 s  .c o 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   w w w . ja va  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.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: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
 * //  w w  w . ja  v  a  2 s  .  c  o m
 * @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;
}