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:org.jboss.dashboard.displayer.table.ExportTool.java

License:Apache License

private Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style;/*from  w ww . java 2s . c  om*/

    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 12);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    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.setFont(titleFont);
    style.setWrapText(false);
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
    styles.put("header", style);

    Font cellFont = wb.createFont();
    cellFont.setFontHeightInPoints((short) 10);
    cellFont.setBoldweight(Font.BOLDWEIGHT_NORMAL);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(3)));
    styles.put("integer_number_cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(4)));
    styles.put("decimal_number_cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text"));
    styles.put("text_cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat()
            .getFormat(DateFormatConverter.convert(LocaleManager.currentLocale(), dateFormatPattern)));
    styles.put("date_cell", style);
    return styles;
}

From source file:org.joeffice.spreadsheet.TableStyleable.java

License:Apache License

/**
 * Add the attribute as defined in {@link AttributedString} to the {@link MutableAttributeSet} for the JTextPane.
 *
 * @see java.awt.font.TextAttribute//from   ww w.j  av a 2s  . c o m
 */
protected void addAttribute(AttributedCharacterIterator.Attribute attribute, Object attributeValue, Cell cell) {
    CellStyle oldStyle = cell.getCellStyle();
    Workbook workbook = cell.getSheet().getWorkbook();
    CellStyle style = cell.getSheet().getWorkbook().createCellStyle();
    style.cloneStyleFrom(oldStyle);
    Font newFont = copyFont(cell);
    if (attribute == FAMILY) {
        newFont.setFontName((String) attributeValue);
        CellUtil.setFont(cell, workbook, newFont);
    } else if (attribute == FOREGROUND) {
        Color color = (Color) attributeValue;
        if (cell instanceof XSSFCell) {
            ((XSSFCellStyle) style).setFillForegroundColor(new XSSFColor(color));
        } else {
            HSSFWorkbook xlsWorkbook = (HSSFWorkbook) workbook;
            HSSFColor xlsColor = xlsWorkbook.getCustomPalette().findColor((byte) color.getRed(),
                    (byte) color.getGreen(), (byte) color.getBlue());
            if (xlsColor == null) {
                xlsColor = xlsWorkbook.getCustomPalette().addColor((byte) color.getRed(),
                        (byte) color.getGreen(), (byte) color.getBlue());
            }
            style.setFillForegroundColor(xlsColor.getIndex());
        }
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    } else if (attribute == BACKGROUND) {
        Color color = (Color) attributeValue;
        if (cell instanceof XSSFCell) {
            ((XSSFCellStyle) style).setFillBackgroundColor(new XSSFColor(color));
        } else {
            HSSFWorkbook xlsWorkbook = (HSSFWorkbook) workbook;
            HSSFColor xlsColor = xlsWorkbook.getCustomPalette().findColor((byte) color.getRed(),
                    (byte) color.getGreen(), (byte) color.getBlue());
            if (xlsColor == null) {
                xlsColor = xlsWorkbook.getCustomPalette().addColor((byte) color.getRed(),
                        (byte) color.getGreen(), (byte) color.getBlue());
            }
            style.setFillBackgroundColor(xlsColor.getIndex());
        }
    } else if (attribute == WEIGHT) {
        short boldValue = Font.BOLDWEIGHT_BOLD;
        if (newFont.getBoldweight() == Font.BOLDWEIGHT_BOLD) {
            boldValue = Font.BOLDWEIGHT_NORMAL;
        }
        newFont.setBoldweight(boldValue);
        CellUtil.setFont(cell, workbook, newFont);
    } else if (attribute == UNDERLINE) {
        byte underlineValue = Font.U_SINGLE;
        if (newFont.getUnderline() == Font.U_SINGLE) {
            underlineValue = Font.U_NONE;
        }
        newFont.setUnderline(underlineValue);
        CellUtil.setFont(cell, workbook, newFont);
    } else if (attribute == SUPERSCRIPT) {
        short superscriptValue = Font.SS_NONE;
        if (SUPERSCRIPT_SUB.equals(attributeValue)) {
            superscriptValue = Font.SS_SUB;
        } else if (SUPERSCRIPT_SUPER.equals(attributeValue)) {
            superscriptValue = Font.SS_SUPER;
        }
        newFont.setTypeOffset(superscriptValue);
        CellUtil.setFont(cell, workbook, newFont);
    } else if (attribute == STRIKETHROUGH) {
        boolean strikeThrough = true;
        if (newFont.getStrikeout()) {
            strikeThrough = false;
        }
        newFont.setStrikeout(strikeThrough);
        CellUtil.setFont(cell, workbook, newFont);
    } else if (attribute == POSTURE) {
        boolean italic = true;
        if (newFont.getItalic()) {
            italic = false;
        }
        newFont.setItalic(italic);
        CellUtil.setFont(cell, workbook, newFont);
    } else if (attribute == SIZE) {
        newFont.setFontHeightInPoints(((Number) attributeValue).shortValue());
        CellUtil.setFont(cell, workbook, newFont);
    } else if (attribute == JUSTIFICATION) {
        CellUtil.setAlignment(cell, workbook, CellStyle.ALIGN_JUSTIFY);
    } else if (attribute == ALIGNMENT) {
        if (attributeValue.equals(StyleConstants.ALIGN_LEFT)) {
            CellUtil.setAlignment(cell, workbook, CellStyle.ALIGN_LEFT);
        } else if (attributeValue.equals(StyleConstants.ALIGN_RIGHT)) {
            CellUtil.setAlignment(cell, workbook, CellStyle.ALIGN_RIGHT);
        } else if (attributeValue.equals(StyleConstants.ALIGN_CENTER)) {
            CellUtil.setAlignment(cell, workbook, CellStyle.ALIGN_CENTER);
        }
    } else if (attribute == INDENTATION) {
        style.setIndention(((Number) attributeValue).shortValue());
    } else if (attribute == TEXT_TRANSFORM) {
        String text = CellUtils.getFormattedText(cell);
        String transformedText = ((TextTransformer) attributeValue).transformText(text);
        cell.setCellValue(transformedText);
    }
}

From source file:org.kuali.test.runner.output.PoiHelper.java

License:Educational Community License

private void createPoiCellStyles(Workbook workbook) {

    // create bold cell style
    Font font = workbook.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontHeightInPoints((short) 10);
    cellStyleBold = workbook.createCellStyle();
    cellStyleBold.setFont(font);/* w  w w. j a  v a 2s  .c  o m*/

    // create standard cell style
    font = workbook.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
    font.setFontHeightInPoints((short) 10);
    cellStyleNormal = workbook.createCellStyle();
    cellStyleNormal.setFont(font);
    cellStyleNormal.setVerticalAlignment(CellStyle.VERTICAL_TOP);

    // create test header cell style
    font = workbook.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontHeightInPoints((short) 10);
    cellStyleTestHeader = workbook.createCellStyle();
    cellStyleTestHeader.setFont(font);
    cellStyleTestHeader.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.index);
    cellStyleTestHeader.setFillPattern(CellStyle.SOLID_FOREGROUND);

    // create timestamp cell style
    font = workbook.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
    font.setFontHeightInPoints((short) 10);
    cellStyleTimestamp = workbook.createCellStyle();
    cellStyleTimestamp.setFont(font);
    cellStyleTimestamp.setDataFormat(workbook.createDataFormat().getFormat("yyyy-mm-dd hh:mm:ss"));
    cellStyleTimestamp.setVerticalAlignment(CellStyle.VERTICAL_TOP);

    // create timestamp cell style
    font = workbook.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
    font.setFontHeightInPoints((short) 10);
    cellStyleTime = workbook.createCellStyle();
    cellStyleTime.setFont(font);
    cellStyleTime.setDataFormat(workbook.createDataFormat().getFormat("hh:mm:ss"));
    cellStyleTime.setVerticalAlignment(CellStyle.VERTICAL_TOP);

    // create success cell style
    font = workbook.createFont();
    font.setColor(IndexedColors.DARK_GREEN.index);
    font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
    font.setFontHeightInPoints((short) 10);
    cellStyleSuccess = workbook.createCellStyle();
    cellStyleSuccess.setFont(font);
    cellStyleSuccess.setVerticalAlignment(CellStyle.VERTICAL_TOP);

    // create ignore cell style
    font = workbook.createFont();
    font.setColor(IndexedColors.BROWN.index);
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontHeightInPoints((short) 10);
    cellStyleIgnore = workbook.createCellStyle();
    cellStyleIgnore.setFont(font);
    cellStyleIgnore.setVerticalAlignment(CellStyle.VERTICAL_TOP);

    // create warning cell style
    font = workbook.createFont();
    font.setColor(IndexedColors.DARK_YELLOW.index);
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontHeightInPoints((short) 10);
    cellStyleWarning = workbook.createCellStyle();
    cellStyleWarning.setFont(font);
    cellStyleWarning.setVerticalAlignment(CellStyle.VERTICAL_TOP);

    // create error cell style
    font = workbook.createFont();
    font.setColor(IndexedColors.DARK_RED.index);
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontHeightInPoints((short) 10);
    cellStyleError = workbook.createCellStyle();
    cellStyleError.setFont(font);
    cellStyleError.setVerticalAlignment(CellStyle.VERTICAL_TOP);

    // create header cell style
    font = workbook.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontHeightInPoints((short) 10);
    cellStyleHeader = (XSSFCellStyle) workbook.createCellStyle();
    cellStyleHeader.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.index);
    cellStyleHeader.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cellStyleHeader.setFont(font);
}

From source file:org.nuxeo.ecm.platform.groups.audit.service.acl.excel.ExcelBuilder.java

License:Open Source License

@Override
public Font newFont(int size) {
    Font newFont = workbook.createFont();
    // newFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    newFont.setFontHeightInPoints((short) size);
    return newFont;
}

From source file:org.openepics.discs.ccdb.gui.export.ExcelExportTable.java

License:Open Source License

private void initHeaderStyle() {
    headerStyle = wb.createCellStyle();/*from w w  w. j a  v a  2 s .  co  m*/
    headerStyle.setAlignment(CellStyle.ALIGN_CENTER);
    headerStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
    headerStyle.setBottomBorderColor(IndexedColors.PALE_BLUE.getIndex());

    final Font headerFont = wb.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setFontHeightInPoints((short) 11);
    headerFont.setColor(IndexedColors.DARK_TEAL.getIndex());

    headerStyle.setFont(headerFont);
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.xls.helper.ExcelFontFactory.java

License:Open Source License

/**
 * Returns the excel font stored in this wrapper.
 *
 * @param wrapper/* ww  w  . ja v a  2s .c o  m*/
 *          the font wrapper that holds all font information from the repagination.
 * @return the created font.
 */
private Font createFont(final HSSFFontWrapper wrapper) {
    final Font font = workbook.createFont();
    font.setBold(wrapper.isBold());
    font.setColor(wrapper.getColorIndex());
    font.setFontName(wrapper.getFontName());
    font.setFontHeightInPoints((short) wrapper.getFontHeight());
    font.setItalic(wrapper.isItalic());
    font.setStrikeout(wrapper.isStrikethrough());
    if (wrapper.isUnderline()) {
        font.setUnderline(Font.U_SINGLE);
    } else {
        font.setUnderline(Font.U_NONE);
    }
    return font;
}

From source file:org.phenotips.export.internal.Styler.java

License:Open Source License

public void style(DataCell dataCell, Cell cell, Workbook wBook) {
    Set<StyleOption> styles = dataCell.getStyles();
    CellStyle cellStyle = wBook.createCellStyle();
    /* For \n to work properly set to true */
    cellStyle.setWrapText(true);/*from w w  w  . j  av  a2  s. com*/
    if (this.defaultFont == null) {
        this.defaultFont = createDefaultFont(wBook);
    }
    cellStyle.setFont(this.defaultFont);
    if (styles == null) {
        if (this.styleCache.containsKey(Collections.<StyleOption>emptySet())) {
            cell.setCellStyle(this.styleCache.get(Collections.<StyleOption>emptySet()));
            return;
        }
        cell.setCellStyle(cellStyle);
        this.styleCache.put(Collections.<StyleOption>emptySet(), cellStyle);
        return;
    }

    if (this.styleCache.containsKey(styles)) {
        cell.setCellStyle(this.styleCache.get(styles));
        return;
    }

    /* Priority can be coded in by placing the if statement lower, for higher priority */
    /** Font styles */
    Font headerFont = null;
    if (styles.contains(StyleOption.HEADER)) {
        headerFont = wBook.createFont();
        headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        cellStyle.setFont(headerFont);
        cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
        cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
        cell.setCellStyle(cellStyle);
    }
    if (styles.contains(StyleOption.LARGE_HEADER)) {
        if (headerFont == null) {
            headerFont = wBook.createFont();
            headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        }
        headerFont.setFontHeightInPoints((short) 12);
        cellStyle.setFont(headerFont);
        cell.setCellStyle(cellStyle);
    }
    if (styles.contains(StyleOption.YES)) {
        Font font = createDefaultFont(wBook);
        font.setColor(HSSFColor.GREEN.index);
        cellStyle.setFont(font);
        cell.setCellStyle(cellStyle);
    }
    if (styles.contains(StyleOption.NO)) {
        Font font = createDefaultFont(wBook);
        font.setColor(HSSFColor.DARK_RED.index);
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);
        cellStyle.setFont(font);
        cell.setCellStyle(cellStyle);
    }

    /** Border styles */
    if (styles.contains(StyleOption.HEADER_BOTTOM)) {
        cellStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
        cell.setCellStyle(cellStyle);
    }
    if (styles.contains(StyleOption.SECTION_BORDER_LEFT)) {
        cellStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
        cell.setCellStyle(cellStyle);
    }
    if (styles.contains(StyleOption.SECTION_BORDER_RIGHT)) {
        cellStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
        cell.setCellStyle(cellStyle);
    }
    if (styles.contains(StyleOption.PATIENT_BORDER)) {
        cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
        cell.setCellStyle(cellStyle);
    }
    if (styles.contains(StyleOption.FEATURE_SEPARATOR)) {
        cellStyle.setBorderTop(CellStyle.BORDER_THIN);
        cellStyle.setTopBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
        cell.setCellStyle(cellStyle);
    }
    if (styles.contains(StyleOption.YES_NO_SEPARATOR)) {
        cellStyle.setBorderTop(CellStyle.BORDER_DASHED);
        cellStyle.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        cell.setCellStyle(cellStyle);
    }

    /* Keep this as the last statement. */
    this.styleCache.put(styles, cellStyle);
}

From source file:org.phenotips.export.internal.Styler.java

License:Open Source License

private Font createDefaultFont(Workbook wBook) {
    Font font = wBook.createFont();
    font.setFontHeightInPoints((short) 9);
    font.setFontName(XSSFFont.DEFAULT_FONT_NAME);
    return font;/*from   w  w  w. j a v a2  s. com*/
}

From source file:org.primefaces.component.export.ExcelExporter.java

License:Open Source License

protected void applyFacetOptions(Workbook wb, ExporterOptions options, CellStyle facetStyle) {
    Font facetFont = wb.createFont();

    if (options != null) {
        String facetFontStyle = options.getFacetFontStyle();
        if (facetFontStyle != null) {
            if (facetFontStyle.equalsIgnoreCase("BOLD")) {
                facetFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
            }//from  w ww .j av a2 s. c  o  m
            if (facetFontStyle.equalsIgnoreCase("ITALIC")) {
                facetFont.setItalic(true);
            }
        }

        HSSFPalette palette = ((HSSFWorkbook) wb).getCustomPalette();
        Color color = null;

        String facetBackground = options.getFacetBgColor();
        if (facetBackground != null) {
            color = Color.decode(facetBackground);
            HSSFColor backgroundColor = palette.findSimilarColor(color.getRed(), color.getGreen(),
                    color.getBlue());
            ((HSSFCellStyle) facetStyle).setFillForegroundColor(backgroundColor.getIndex());
            facetStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        }

        String facetFontColor = options.getFacetFontColor();
        if (facetFontColor != null) {
            color = Color.decode(facetFontColor);
            HSSFColor facetColor = palette.findSimilarColor(color.getRed(), color.getGreen(), color.getBlue());
            ((HSSFFont) facetFont).setColor(facetColor.getIndex());
        }

        String facetFontSize = options.getFacetFontSize();
        if (facetFontSize != null) {
            facetFont.setFontHeightInPoints(Short.valueOf(facetFontSize));
        }
    }

    facetStyle.setFont(facetFont);
}

From source file:org.primefaces.component.export.ExcelExporter.java

License:Open Source License

protected void applyCellOptions(Workbook wb, ExporterOptions options, CellStyle cellStyle) {
    Font cellFont = wb.createFont();

    if (options != null) {
        String cellFontColor = options.getCellFontColor();
        if (cellFontColor != null) {
            HSSFPalette palette = ((HSSFWorkbook) wb).getCustomPalette();
            Color color = Color.decode(cellFontColor);
            HSSFColor cellColor = palette.findSimilarColor(color.getRed(), color.getGreen(), color.getBlue());
            ((HSSFFont) cellFont).setColor(cellColor.getIndex());
        }/*from ww w  .ja v  a2s . c om*/

        String cellFontSize = options.getCellFontSize();
        if (cellFontSize != null) {
            cellFont.setFontHeightInPoints(Short.valueOf(cellFontSize));
        }

        String cellFontStyle = options.getCellFontStyle();
        if (cellFontStyle != null) {
            if (cellFontStyle.equalsIgnoreCase("BOLD")) {
                cellFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
            }
            if (cellFontStyle.equalsIgnoreCase("ITALIC")) {
                cellFont.setItalic(true);
            }
        }
    }

    cellStyle.setFont(cellFont);
}