Example usage for org.apache.poi.ss.usermodel Workbook createFont

List of usage examples for org.apache.poi.ss.usermodel Workbook createFont

Introduction

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

Prototype

Font createFont();

Source Link

Document

Create a new Font and add it to the workbook's font table

Usage

From source file:uk.co.certait.htmlexporter.writer.excel.ExcelStyleGenerator.java

License:Apache License

public Font createFont(Workbook workbook, Style style) {
    Font font = workbook.createFont();

    if (style.isFontNameSet()) {
        font.setFontName(style.getProperty(CssStringProperty.FONT_FAMILY));
    }//from   w  ww  .j a va2 s  .  c  o  m

    if (style.isFontSizeSet()) {
        font.setFontHeightInPoints((short) style.getProperty(CssIntegerProperty.FONT_SIZE));
    }

    if (style.isColorSet()) {
        Color color = style.getProperty(CssColorProperty.COLOR);

        // if(! color.equals(Color.WHITE)) // POI Bug
        // {
        ((XSSFFont) font).setColor(new XSSFColor(color));
        // }
    }

    if (style.isFontBold()) {
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    }

    font.setItalic(style.isFontItalic());

    if (style.isTextUnderlined()) {
        font.setUnderline(Font.U_SINGLE);
    }

    return font;
}

From source file:vistas.reportes.procesos.rptVacacionesExcel.java

private Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style;/*from  www.  ja v  a  2s .com*/
    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);

    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);

    return styles;
}

From source file:workbench.db.exporter.ExcelDataFormat.java

License:Apache License

protected void setUpHeader(Workbook wb) {
    headerCellStyle = wb.createCellStyle();
    Font font = wb.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerCellStyle.setFont(font);/*from   w  w w  .jav  a  2s .c  o m*/
    headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER);
}