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.betaconceptframework.astroboa.commons.excelbuilder.WorkbookBuilder.java

License:Open Source License

private void initializeDefaultCellStyles() {
    // create cell styles for property values and property names
    propertyNameCellStyle = workbook.createCellStyle();
    stringPropertyValueCellStyle = workbook.createCellStyle();
    integerPropertyValueCellStyle = workbook.createCellStyle();
    doublePropertyValueCellStyle = workbook.createCellStyle();
    datePropertyValueCellStyle = workbook.createCellStyle();
    dateTimePropertyValueCellStyle = workbook.createCellStyle();

    // create 2 fonts objects
    Font propertyNameFont = workbook.createFont();
    Font propertyValueFont = workbook.createFont();

    // Set propertyNameFont to 14 point type, blue and bold
    propertyNameFont.setFontHeightInPoints((short) 14);
    propertyNameFont.setColor(IndexedColors.BLUE.getIndex());
    propertyNameFont.setBoldweight(Font.BOLDWEIGHT_BOLD);

    // Set propertyValueFont to 10 point type, black
    propertyValueFont.setFontHeightInPoints((short) 10);
    propertyValueFont.setColor(IndexedColors.BLACK.getIndex());

    // Set cell style and formatting
    propertyNameCellStyle.setFont(propertyNameFont);
    propertyNameCellStyle.setDataFormat(dataFormat.getFormat("text"));

    stringPropertyValueCellStyle.setFont(propertyValueFont);
    stringPropertyValueCellStyle.setDataFormat(dataFormat.getFormat("text"));
    stringPropertyValueCellStyle.setWrapText(true);

    integerPropertyValueCellStyle.setFont(propertyValueFont);
    integerPropertyValueCellStyle.setWrapText(true);
    //integerPropertyValueCellStyle.setDataFormat(dataFormat.getFormat(""));

    doublePropertyValueCellStyle.setFont(propertyValueFont);
    doublePropertyValueCellStyle.setDataFormat(dataFormat.getFormat("#,##0.000"));
    doublePropertyValueCellStyle.setWrapText(true);

    datePropertyValueCellStyle.setFont(propertyValueFont);
    datePropertyValueCellStyle.setDataFormat(dataFormat.getFormat("dd/mm/yyyy"));
    datePropertyValueCellStyle.setWrapText(true);

    dateTimePropertyValueCellStyle.setFont(propertyValueFont);
    dateTimePropertyValueCellStyle.setDataFormat(dataFormat.getFormat("dd/mm/yyyy HH:mm"));
    dateTimePropertyValueCellStyle.setWrapText(true);

    // Set the other cell style and formatting
    //cs2.setBorderBottom(cs2.BORDER_THIN);

}

From source file:org.cgiar.ccafs.ap.summaries.projects.xlsx.BaseXLS.java

License:Open Source License

/**
 * This method writes the title box into the given sheet.
 * /*from  ww  w.j a  v a2 s  .  c  o  m*/
 * @param sheet is the sheet where you want to write the title box.
 * @param text is the title of the report.
 */
public void writeTitleBox(Sheet sheet, String text) {

    XSSFDrawing draw = (XSSFDrawing) sheet.createDrawingPatriarch();
    XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 1, 1, 1, 1, 3, 6);
    anchor.setAnchorType(2);
    XSSFTextBox textbox = draw.createTextbox(anchor);

    textbox.setFillColor(TEXTBOX_BACKGROUND_COLOR_RGB.getRed(), TEXTBOX_BACKGROUND_COLOR_RGB.getGreen(),
            TEXTBOX_BACKGROUND_COLOR_RGB.getBlue());
    textbox.setVerticalAlignment(VerticalAlignment.CENTER);

    XSSFRichTextString stringX = new XSSFRichTextString();
    Font font = workbook.createFont();
    font.setFontHeightInPoints((short) 20);
    font.setFontName("Tahoma");
    font.setColor(TEXTBOX_FONT_COLOR_INDEX);
    stringX.append(text);

    stringX.applyFont(font);
    textbox.setText(stringX);
}

From source file:org.dashbuilder.dataset.backend.DataSetBackendServicesImpl.java

License:Apache License

private Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style;/*ww  w  .  j  a  va2s  .c  o  m*/

    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(Locale.getDefault(), dateFormatPattern)));
    styles.put("date_cell", style);
    return styles;
}

From source file:org.dashbuilder.dataset.service.DataSetExportServicesImpl.java

License:Apache License

private Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<>();
    CellStyle style;//from   w  w w . j a va  2 s .  co m

    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 12);
    titleFont.setBold(true);
    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setFont(titleFont);
    style.setWrapText(false);
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
    styles.put("header", style);

    Font cellFont = wb.createFont();
    cellFont.setFontHeightInPoints((short) 10);
    cellFont.setBold(true);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setVerticalAlignment(VerticalAlignment.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(HorizontalAlignment.RIGHT);
    style.setVerticalAlignment(VerticalAlignment.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(HorizontalAlignment.LEFT);
    style.setVerticalAlignment(VerticalAlignment.BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text"));
    styles.put(TEXT_CELL, style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat()
            .getFormat(DateFormatConverter.convert(Locale.getDefault(), dateFormatPattern)));
    styles.put("date_cell", style);
    return styles;
}

From source file:org.eclipse.nebula.widgets.nattable.extension.poi.PoiExcelExporter.java

License:Open Source License

private CellStyle getExcelCellStyle(Color fg, Color bg, FontData fontData, String dataFormat, int hAlign,
        int vAlign, boolean vertical) {

    CellStyle xlCellStyle = xlCellStyles
            .get(new ExcelCellStyleAttributes(fg, bg, fontData, dataFormat, hAlign, vAlign, vertical));

    if (xlCellStyle == null) {
        xlCellStyle = xlWorkbook.createCellStyle();

        if (applyBackgroundColor) {
            // Note: xl fill foreground = background
            setFillForegroundColor(xlCellStyle, bg);
            xlCellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
        }//from   www. j  av a 2s. com

        Font xlFont = xlWorkbook.createFont();
        setFontColor(xlFont, fg);
        xlFont.setFontName(fontData.getName());
        xlFont.setFontHeightInPoints((short) fontData.getHeight());
        xlCellStyle.setFont(xlFont);

        if (vertical)
            xlCellStyle.setRotation((short) 90);

        switch (hAlign) {
        case SWT.CENTER:
            xlCellStyle.setAlignment(CellStyle.ALIGN_CENTER);
            break;
        case SWT.LEFT:
            xlCellStyle.setAlignment(CellStyle.ALIGN_LEFT);
            break;
        case SWT.RIGHT:
            xlCellStyle.setAlignment(CellStyle.ALIGN_RIGHT);
            break;
        }
        switch (vAlign) {
        case SWT.TOP:
            xlCellStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
            break;
        case SWT.CENTER:
            xlCellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
            break;
        case SWT.BOTTOM:
            xlCellStyle.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
            break;
        }

        if (dataFormat != null) {
            CreationHelper createHelper = xlWorkbook.getCreationHelper();
            xlCellStyle.setDataFormat(createHelper.createDataFormat().getFormat(dataFormat));
        }

        xlCellStyles.put(new ExcelCellStyleAttributes(fg, bg, fontData, dataFormat, hAlign, vAlign, vertical),
                xlCellStyle);
    }
    return xlCellStyle;
}

From source file:org.forzaframework.util.ExcelUtils.java

License:Apache License

static public void modelToExcelSheet(Workbook wb, String sheetName, List<Map<String, Object>> headers,
        List<Map<String, Object>> data, List<Map<String, Object>> footers, Integer freezePane,
        Boolean defaultFormat, Boolean createNewSheet, Integer indexSheet, Integer startInRow,
        Boolean printHeader, Boolean autoSizeColumns) {
    Sheet sheet = getSheet(wb, sheetName, createNewSheet, indexSheet);
    CellStyle headerCellStyle = getDefaultHeaderCellStyle(wb, defaultFormat);
    CellStyle titlesCellStyle = null;//from  w w  w  . j  a  v  a 2  s .c  om
    if (defaultFormat != null && defaultFormat) {
        titlesCellStyle = wb.createCellStyle();
        //Creamos el tipo de fuente
        Font titleFont = wb.createFont();
        //            headerFont.setFontName(HSSFFont.FONT_ARIAL);
        titleFont.setBold(Boolean.TRUE);
        titleFont.setColor(Font.COLOR_NORMAL);
        titleFont.setFontHeightInPoints((short) 8);
        titlesCellStyle.setFont(titleFont);
    }

    Integer col = 0;
    Integer row = 0;
    if (startInRow != null) {
        row = startInRow;
    }
    Map<Integer, Integer> columnWidthMap = new HashMap<Integer, Integer>();
    //Indice de la fila donde empieza los encabezados de titulo de cada columna
    Integer principalHeaderIndex = headers.size() - 1;
    if (printHeader != null && printHeader) {
        //Armamos el encabezado
        for (Map<String, Object> header : headers) {
            for (Map.Entry<String, Object> entry : header.entrySet()) {
                Cell cell = getCell(sheet, row, col);
                if (defaultFormat != null && defaultFormat) {
                    if (principalHeaderIndex.equals(row)) {
                        //Colocamos el formato de la celda
                        cell.setCellStyle(headerCellStyle);
                    } else {
                        cell.setCellStyle(titlesCellStyle);
                    }
                }
                setValue(cell, entry.getValue());
                //Especificamos el ancho que tendra la columna
                if (autoSizeColumns != null && autoSizeColumns) {
                    columnWidthMap.put(col, entry.getValue().toString().length());
                }
                col++;
            }
            row++;
            col = 0;
        }
        //Ponemos la altura del encabezado
        setRowHeight(sheet, row - 1, (short) 420);
    }

    CellStyle detailCellStyle = getDefaultDetailCellStyle(wb, defaultFormat);

    Map<String, Object> principalHeader = headers.get(principalHeaderIndex);
    // datos
    for (Map<String, Object> map : data) {
        for (Map.Entry<String, Object> entry : principalHeader.entrySet()) {
            Object value = map.get(entry.getKey());
            buildCellAndCalculateColumnWidth(sheet, value, col, row, detailCellStyle, columnWidthMap,
                    autoSizeColumns);
            col++;
        }
        col = 0;
        row++;
    }
    CellStyle totalCellStyle = null;
    if (defaultFormat != null && defaultFormat) {
        //Armamos el formato los totales
        totalCellStyle = wb.createCellStyle();
        Font totalFont = wb.createFont();
        totalFont.setBold(Boolean.TRUE);
        totalFont.setColor(Font.COLOR_NORMAL);
        totalFont.setFontHeightInPoints((short) 8);
        totalCellStyle.setFont(totalFont);
    }

    if (footers != null) {
        for (Map<String, Object> footer : footers) {
            for (Map.Entry<String, Object> entry : principalHeader.entrySet()) {
                Cell cell = getCell(sheet, row, col++);
                if (totalCellStyle != null) {
                    //Colocamos el formato de la celda
                    cell.setCellStyle(totalCellStyle);
                }

                Object object = footer.get(entry.getKey());
                if (object != null) {
                    setValue(cell, object);
                } else {
                    setText(cell, "");
                }
            }
        }
    }

    if (autoSizeColumns != null && autoSizeColumns) {
        setColumnsWidth(sheet, columnWidthMap, principalHeader.size());
    }

    if (freezePane != null && freezePane > 0) {
        //Colocamos la columna estatica y las filas del encabezado estaticas
        sheet.createFreezePane(freezePane, headers.size());
    }
}

From source file:org.forzaframework.util.ExcelUtils.java

License:Apache License

public static CellStyle getDefaultDetailCellStyle(Workbook wb, Boolean defaultFormat) {
    CellStyle detailCellStyle = null;//  ww  w  .  ja  va  2  s .c  o m
    if (defaultFormat != null && defaultFormat) {
        //Armamos el formato para los datos del detalle
        detailCellStyle = wb.createCellStyle();
        Font detailFont = wb.createFont();
        detailFont.setFontHeightInPoints((short) 8);
        detailCellStyle.setFont(detailFont);
    }
    return detailCellStyle;
}

From source file:org.forzaframework.util.ExcelUtils.java

License:Apache License

public static CellStyle getDefaultHeaderCellStyle(Workbook wb, Boolean defaultFormat) {
    CellStyle headerCellStyle = null;/*w  w  w . ja  va 2  s. c o  m*/
    if (defaultFormat != null && defaultFormat) {
        //Le damos formato a los encabezados
        headerCellStyle = wb.createCellStyle();
        headerCellStyle.setBorderBottom(BorderStyle.DOTTED);
        headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        //        headerCellStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
        headerCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        //Creamos el tipo de fuente
        Font headerFont = wb.createFont();
        //            headerFont.setFontName(HSSFFont.FONT_ARIAL);
        headerFont.setBold(Boolean.TRUE);
        headerFont.setColor(Font.COLOR_NORMAL);
        headerFont.setFontHeightInPoints((short) 8);
        headerCellStyle.setFont(headerFont);
    }
    return headerCellStyle;
}

From source file:org.gedantic.web.servlet.WorkbookCreator.java

License:Open Source License

/**
 * Setup styles./*from ww w  .ja v a 2s  .c o m*/
 */
private void setupStyles() {
    styleTitle = wb.createCellStyle();
    Font title_font = wb.createFont();
    title_font.setFontName("Helvetica");
    title_font.setColor(IndexedColors.BLACK.getIndex());
    title_font.setFontHeightInPoints((short) 24);
    styleTitle.setFont(title_font);

    styleSubtitle = wb.createCellStyle();
    Font subtitle_font = wb.createFont();
    subtitle_font.setFontName("Helvetica");
    subtitle_font.setColor(IndexedColors.GREY_50_PERCENT.getIndex());
    subtitle_font.setFontHeightInPoints((short) 18);
    styleSubtitle.setFont(subtitle_font);

    styleHyperlink = wb.createCellStyle();
    Font hlink_font = wb.createFont();
    hlink_font.setFontName("Helvetica");
    hlink_font.setUnderline(Font.U_SINGLE);
    hlink_font.setColor(IndexedColors.BLUE.getIndex());
    styleHyperlink.setFont(hlink_font);

    styleNormal = wb.createCellStyle();
    Font normal_font = wb.createFont();
    normal_font.setFontName("Helvetica");
    normal_font.setColor(IndexedColors.BLACK.getIndex());
    normal_font.setFontHeightInPoints((short) 12);
    styleNormal.setFont(normal_font);
    styleNormal.setWrapText(true);

    styleHeader = wb.createCellStyle();
    Font header_font = wb.createFont();
    header_font.setFontName("Helvetica");
    header_font.setColor(IndexedColors.WHITE.getIndex());
    header_font.setBold(true);
    header_font.setFontHeightInPoints((short) 12);
    XSSFColor bg = new XSSFColor(new java.awt.Color(0x28, 0x60, 0x90));
    ((XSSFCellStyle) styleHeader).setFillForegroundColor(bg);
    styleHeader.setFillPattern(CellStyle.SOLID_FOREGROUND);
    styleHeader.setFont(header_font);

}

From source file:org.haplo.jsinterface.generate.KGenerateXLS.java

License:Mozilla Public License

private void styleFont(SheetStyleInstruction i) {
    HashMap<String, Object> properties = new HashMap<String, Object>(1);
    Font font = this.workbook.createFont();
    if (i.colour instanceof CharSequence) {
        switch (i.colour.toString()) {
        case "BOLD":
            font.setBold(true);// ww w.  j a  v a2  s  .  co  m
            font.setBold(true);
            break;
        case "BOLD-ITALIC":
            font.setBold(true);
            font.setBold(true);
            font.setItalic(true);
            break;
        case "ITALIC":
            font.setItalic(true);
            break;
        }
    }
    if (i.option instanceof Number) {
        font.setFontHeightInPoints(((Number) i.option).shortValue());
    }
    properties.put(CellUtil.FONT, font.getIndex());
    styleApplyToRegion(i, properties);
}