Example usage for org.apache.poi.xssf.usermodel XSSFFont getFontHeightInPoints

List of usage examples for org.apache.poi.xssf.usermodel XSSFFont getFontHeightInPoints

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFFont getFontHeightInPoints.

Prototype

public short getFontHeightInPoints() 

Source Link

Document

Get the font height in points.

Usage

From source file:de.escnet.ExcelTable.java

License:Open Source License

private String styleFont(Map<String, String> styles, XSSFCell cell) {
    XSSFCellStyle cellStyle = cell.getCellStyle();
    if (cellStyle != null) {
        short fontIndex = cellStyle.getFontIndex();
        XSSFFont font = sheet.getWorkbook().getFontAt(fontIndex);

        if (font.getItalic()) {
            styles.put("font-style", "italic");
        }/*from ww w .  java2 s.  c om*/

        if (font.getBoldweight() == Font.BOLDWEIGHT_BOLD) {
            styles.put("font-weight", "bold");
        }

        styles.put("font", "" + font.getFontHeightInPoints() + "px " + font.getFontName());

        if (FONT_COLORS) {
            String color = getHtmlColor(font.getXSSFColor());
            if (color != null && !color.equals("#000000")) {
                return color;
            }
        }
    }

    return null;
}

From source file:org.apache.metamodel.excel.XlsxSheetToRowsHandler.java

License:Apache License

private void configureStyle(XSSFCellStyle style) {
    XSSFFont font = style.getFont();/*from   ww w . jav a 2  s  .co  m*/
    if (font.getBold()) {
        _style.bold();
    }
    if (font.getItalic()) {
        _style.italic();
    }
    if (font.getUnderline() != FontUnderline.NONE.getByteValue()) {
        _style.underline();
    }

    if (style.getFillPatternEnum() == FillPatternType.SOLID_FOREGROUND) {
        XSSFColor fillForegroundXSSFColor = style.getFillForegroundXSSFColor();
        String argb = fillForegroundXSSFColor.getARGBHex();
        if (argb != null) {
            _style.background(argb.substring(2));
        }
    }

    final XSSFFont stdFont = _stylesTable.getStyleAt(0).getFont();
    final short fontHeight = style.getFont().getFontHeightInPoints();
    if (stdFont.getFontHeightInPoints() != fontHeight) {
        _style.fontSize(fontHeight, SizeUnit.PT);
    }

    XSSFColor fontColor = style.getFont().getXSSFColor();
    if (fontColor != null) {
        String argbHex = fontColor.getARGBHex();
        if (argbHex != null) {
            _style.foreground(argbHex.substring(2));
        }
    }

    switch (style.getAlignmentEnum()) {
    case LEFT:
        _style.leftAligned();
        break;
    case RIGHT:
        _style.rightAligned();
        break;
    case CENTER:
        _style.centerAligned();
        break;
    case JUSTIFY:
        _style.justifyAligned();
        break;
    default:
        // do nothing
        break;
    }

}

From source file:org.sysmodb.xml.XSSFXMLStyleHelper.java

License:BSD License

@Override
public void writeFontProperties(XMLStreamWriter xmlWriter, CellStyle style) throws XMLStreamException {
    XSSFCellStyle newStyle = (XSSFCellStyle) style;
    XSSFFont font = newStyle.getFont();
    if (font.getBold()) {
        xmlWriter.writeStartElement("font-weight");
        xmlWriter.writeCharacters("bold");
        xmlWriter.writeEndElement();/*w w w .j  a v  a2s  .  co m*/
    }
    if (font.getItalic()) {
        xmlWriter.writeStartElement("font-style");
        xmlWriter.writeCharacters("italics");
        xmlWriter.writeEndElement();
    }
    if (font.getUnderline() != XSSFFont.U_NONE) {
        xmlWriter.writeStartElement("text-decoration");
        xmlWriter.writeCharacters("underline");
        xmlWriter.writeEndElement();
    }
    if (font.getFontHeight() != XSSFFont.DEFAULT_FONT_SIZE) {
        xmlWriter.writeStartElement("font-size");
        xmlWriter.writeCharacters(String.valueOf(font.getFontHeightInPoints()) + "pt");
        xmlWriter.writeEndElement();
    }

    if (!font.getFontName().equals(XSSFFont.DEFAULT_FONT_NAME)) {
        xmlWriter.writeStartElement("font-family");
        xmlWriter.writeCharacters(String.valueOf(font.getFontName()));
        xmlWriter.writeEndElement();
    }
    if (font.getColor() != XSSFFont.DEFAULT_FONT_COLOR) {
        String colorString = getRGBString(font.getXSSFColor());
        if (colorString != null) {
            xmlWriter.writeStartElement("color");
            xmlWriter.writeCharacters(colorString);
            xmlWriter.writeEndElement();
        }
    }

}