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:com.b510.excel.client.LoanCalculator.java

License:Apache License

/**
 * cell styles used for formatting calendar sheets
 *//*from   w  w  w.  j  av a2  s.  co m*/
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) 14);
    titleFont.setFontName("Trebuchet MS");
    style = wb.createCellStyle();
    style.setFont(titleFont);
    style.setBorderBottom(CellStyle.BORDER_DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    styles.put("title", style);

    Font itemFont = wb.createFont();
    itemFont.setFontHeightInPoints((short) 9);
    itemFont.setFontName("Trebuchet MS");
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setFont(itemFont);
    styles.put("item_left", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setFont(itemFont);
    styles.put("item_right", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(CellStyle.BORDER_DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(CellStyle.BORDER_DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(CellStyle.BORDER_DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(CellStyle.BORDER_DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(
            wb.createDataFormat().getFormat("_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)"));
    styles.put("input_$", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(CellStyle.BORDER_DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(CellStyle.BORDER_DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(CellStyle.BORDER_DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(CellStyle.BORDER_DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(wb.createDataFormat().getFormat("0.000%"));
    styles.put("input_%", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(CellStyle.BORDER_DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(CellStyle.BORDER_DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(CellStyle.BORDER_DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(CellStyle.BORDER_DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(wb.createDataFormat().getFormat("0"));
    styles.put("input_i", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setFont(itemFont);
    style.setDataFormat(wb.createDataFormat().getFormat("m/d/yy"));
    styles.put("input_d", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(CellStyle.BORDER_DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(CellStyle.BORDER_DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(CellStyle.BORDER_DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(CellStyle.BORDER_DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(wb.createDataFormat().getFormat("$##,##0.00"));
    style.setBorderBottom(CellStyle.BORDER_DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    styles.put("formula_$", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(CellStyle.BORDER_DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(CellStyle.BORDER_DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(CellStyle.BORDER_DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(CellStyle.BORDER_DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(wb.createDataFormat().getFormat("0"));
    style.setBorderBottom(CellStyle.BORDER_DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    styles.put("formula_i", style);

    return styles;
}

From source file:com.b510.excel.client.TimesheetDemo.java

License:Apache License

/**
 * Create a library of cell styles/*from  w w w  .j a v  a 2s.  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_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:com.catexpress.util.FormatosPOI.java

public CellStyle estiloProveedor(Workbook wb) {
    CellStyle estiloCelda = wb.createCellStyle();
    Font fuente = wb.createFont();
    fuente.setFontName("Calibri");
    fuente.setBold(true);/*from  w  w  w. ja v a 2  s.c o  m*/
    fuente.setFontHeightInPoints((short) 32);
    fuente.setColor(IndexedColors.ROYAL_BLUE.getIndex());
    estiloCelda.setFont(fuente);
    estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER);
    estiloCelda.setAlignment(HorizontalAlignment.CENTER);

    return estiloCelda;
}

From source file:com.catexpress.util.FormatosPOI.java

public CellStyle estiloColumnas(Workbook wb, int tipo) {
    CellStyle estiloCelda = wb.createCellStyle();
    Font fuente = wb.createFont();
    if (tipo == COLUMNA) {
        estiloCelda.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND);
        fuente.setBold(true);/*w w w.  jav a2 s  . co m*/
    }
    if (tipo == SURTIDO) {
        fuente.setColor(IndexedColors.WHITE.getIndex());
        estiloCelda.setFillForegroundColor(IndexedColors.ROYAL_BLUE.getIndex());
        estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND);
    }
    fuente.setFontName("Calibri");
    fuente.setFontHeightInPoints((short) 11);
    estiloCelda.setFont(fuente);
    estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER);
    estiloCelda.setAlignment(HorizontalAlignment.CENTER);
    if (tipo == COLUMNA) {
        estiloCelda.setBorderBottom(BorderStyle.MEDIUM);
        estiloCelda.setBorderTop(BorderStyle.MEDIUM);
        estiloCelda.setBorderLeft(BorderStyle.MEDIUM);
        estiloCelda.setBorderRight(BorderStyle.MEDIUM);
    } else {
        estiloCelda.setBorderBottom(BorderStyle.THIN);
        estiloCelda.setBorderTop(BorderStyle.THIN);
        estiloCelda.setBorderLeft(BorderStyle.THIN);
        estiloCelda.setBorderRight(BorderStyle.THIN);
    }
    return estiloCelda;
}

From source file:com.catexpress.util.FormatosPOI.java

public CellStyle estiloTotales(Workbook wb) {
    CellStyle estiloCelda = wb.createCellStyle();
    Font fuente = wb.createFont();
    estiloCelda.setFillForegroundColor(IndexedColors.ROYAL_BLUE.getIndex());
    estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND);
    fuente.setFontName("Calibri");
    fuente.setBold(true);//from  w  ww  . jav  a2 s .com
    fuente.setFontHeightInPoints((short) 14);
    fuente.setColor(IndexedColors.WHITE.getIndex());
    estiloCelda.setFont(fuente);
    estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER);
    estiloCelda.setAlignment(HorizontalAlignment.CENTER);
    estiloCelda.setBorderBottom(BorderStyle.MEDIUM);
    estiloCelda.setBorderTop(BorderStyle.MEDIUM);
    estiloCelda.setBorderLeft(BorderStyle.MEDIUM);
    estiloCelda.setBorderRight(BorderStyle.MEDIUM);

    return estiloCelda;
}

From source file:com.catexpress.util.FormatosPOI.java

public CellStyle estiloCuadro(Workbook wb, int tipo) {
    CellStyle estiloCelda = wb.createCellStyle();
    Font fuente = wb.createFont();
    if (tipo == AMARILLO) {
        estiloCelda.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
        estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND);
    }//from   w w  w .j  a  v  a  2  s .com
    fuente.setFontName("Calibri");
    fuente.setBold(true);
    fuente.setFontHeightInPoints((short) 12);
    estiloCelda.setFont(fuente);
    estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER);
    estiloCelda.setAlignment(HorizontalAlignment.CENTER);
    estiloCelda.setBorderBottom(BorderStyle.THIN);
    estiloCelda.setBorderTop(BorderStyle.THIN);
    estiloCelda.setBorderLeft(BorderStyle.THIN);
    estiloCelda.setBorderRight(BorderStyle.THIN);

    return estiloCelda;
}

From source file:com.catexpress.util.FormatosPOI.java

public CellStyle estiloHeader(Workbook wb, int tipo) {
    Font fuente = wb.createFont();
    CreationHelper createHelper = wb.getCreationHelper();
    fuente.setFontName("Calibri");
    fuente.setBold(true);//  ww w  .  j  a v a 2s . c o m

    if (tipo == TITULO || tipo == SUCURSAL || tipo == LABEL || tipo == FECHA) {
        fuente.setFontHeightInPoints((short) 16);
    } else if (tipo == USUARIO) {
        fuente.setFontHeightInPoints((short) 20);
    }

    CellStyle estiloCelda = wb.createCellStyle();
    estiloCelda.setFont(fuente);

    if (tipo == TITULO || tipo == USUARIO || tipo == LABEL || tipo == FECHA) {
        estiloCelda.setFillForegroundColor(IndexedColors.WHITE.getIndex());
    } else if (tipo == SUCURSAL) {
        estiloCelda.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    }
    estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND);

    if (tipo == LABEL || tipo == FECHA) {
        estiloCelda.setWrapText(false);
    } else if (tipo == TITULO || tipo == SUCURSAL || tipo == USUARIO) {
        estiloCelda.setWrapText(true);
    }

    estiloCelda.setAlignment(HorizontalAlignment.CENTER);

    if (tipo == LABEL || tipo == FECHA) {
        estiloCelda.setVerticalAlignment(VerticalAlignment.BOTTOM);
    } else if (tipo == TITULO || tipo == SUCURSAL || tipo == USUARIO) {
        estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER);
    }

    if (tipo == SUCURSAL) {
        estiloCelda.setBorderBottom(BorderStyle.MEDIUM);
        estiloCelda.setBorderTop(BorderStyle.MEDIUM);
        estiloCelda.setBorderLeft(BorderStyle.MEDIUM);
        estiloCelda.setBorderRight(BorderStyle.MEDIUM);
    }

    if (tipo == FECHA) {
        estiloCelda.setDataFormat(createHelper.createDataFormat().getFormat("dd \"de\" mmmm \"de\" yyyy"));
    }

    return estiloCelda;
}

From source file:com.cms.utils.ExportExcell.java

private Comment getcellComment(FormatExcell item, Cell cell) {
    ExcellHeaderComment headerCommand = item.getHeaderCommand();
    Drawing sSFPatriarch = sh.createDrawingPatriarch();
    CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper();
    ClientAnchor anchor = factory.createClientAnchor();
    Comment comment1 = sSFPatriarch.createCellComment(anchor);

    anchor.setCol1(headerCommand.getRow1());
    anchor.setCol2(headerCommand.getRow2());
    anchor.setRow1(headerCommand.getColumn1());
    anchor.setRow2(headerCommand.getColumn2());
    anchor.setDx1(headerCommand.getDx1());
    anchor.setDx2(headerCommand.getDx2());
    anchor.setDy1(headerCommand.getDy1());
    anchor.setDy2(headerCommand.getDy2());

    RichTextString rtf1 = factory.createRichTextString(headerCommand.getValue());
    Font font = wb.createFont();
    font.setFontName("Arial");
    font.setFontHeightInPoints((short) 10);
    font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
    font.setColor(IndexedColors.RED.getIndex());
    rtf1.applyFont(font);/*from   w  w  w  .  j av a 2s. c om*/
    comment1.setString(rtf1);
    comment1.setAuthor("Logistics");
    //        comment1.setColumn(cell.getColumnIndex());
    //        comment1.setRow(cell.getRowIndex());
    return comment1;
}

From source file:com.cms.utils.ExportExcell.java

private Comment getcellComment(Sheet sh, FormatExcell item, Cell cell) {
    ExcellHeaderComment headerCommand = item.getHeaderCommand();
    Drawing sSFPatriarch = sh.createDrawingPatriarch();
    CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper();
    ClientAnchor anchor = factory.createClientAnchor();
    Comment comment1 = sSFPatriarch.createCellComment(anchor);

    anchor.setCol1(headerCommand.getRow1());
    anchor.setCol2(headerCommand.getRow2());
    anchor.setRow1(headerCommand.getColumn1());
    anchor.setRow2(headerCommand.getColumn2());
    anchor.setDx1(headerCommand.getDx1());
    anchor.setDx2(headerCommand.getDx2());
    anchor.setDy1(headerCommand.getDy1());
    anchor.setDy2(headerCommand.getDy2());

    RichTextString rtf1 = factory.createRichTextString(headerCommand.getValue());
    Font font = wb.createFont();
    font.setFontName("Arial");
    font.setFontHeightInPoints((short) 10);
    font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
    font.setColor(IndexedColors.RED.getIndex());
    rtf1.applyFont(font);/*  w  ww .jav a 2s. c om*/
    comment1.setString(rtf1);
    comment1.setAuthor("Logistics");
    //        comment1.setColumn(cell.getColumnIndex());
    //        comment1.setRow(cell.getRowIndex());
    return comment1;
}

From source file:com.crm.webapp.util.ExcelCustomExporter.java

License:Apache License

protected void createCustomFonts() {

    Font facetFont = wb.createFont();
    Font cellFont = wb.createFont();

    if (cellFontColor != null) {
        XSSFColor cellColor = new XSSFColor(cellFontColor);
        ((XSSFFont) cellFont).setColor(cellColor);
    }/* w ww  . j  a v  a 2 s . c o  m*/
    if (cellFontSize != null) {
        cellFont.setFontHeightInPoints((short) cellFontSize);
    }

    if (cellFontStyle.equalsIgnoreCase("BOLD")) {
        cellFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    }
    if (cellFontStyle.equalsIgnoreCase("ITALIC")) {
        cellFont.setItalic(true);
    }

    if (facetFontStyle.equalsIgnoreCase("BOLD")) {
        facetFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    }
    if (facetFontStyle.equalsIgnoreCase("ITALIC")) {
        facetFont.setItalic(true);
    }

    if (fontName != null) {
        cellFont.setFontName(fontName);
        facetFont.setFontName(fontName);
    }

    cellStyle.setFont(cellFont);

    if (facetBackground != null) {
        XSSFColor backgroundColor = new XSSFColor(facetBackground);
        ((XSSFCellStyle) facetStyle).setFillForegroundColor(backgroundColor);
        facetStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);

    }

    if (facetFontColor != null) {
        XSSFColor facetColor = new XSSFColor(facetFontColor);
        ((XSSFFont) facetFont).setColor(facetColor);

    }
    if (facetFontSize != null) {
        facetFont.setFontHeightInPoints((short) facetFontSize);
    }

    facetStyle.setFont(facetFont);
    facetStyle.setAlignment(CellStyle.ALIGN_CENTER);

}