Example usage for org.apache.poi.xssf.usermodel XSSFCellStyle getFont

List of usage examples for org.apache.poi.xssf.usermodel XSSFCellStyle getFont

Introduction

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

Prototype

public XSSFFont getFont() 

Source Link

Document

Gets the font for this style

Usage

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

License:BSD License

public boolean areFontsEmpty(CellStyle style) {
    XSSFCellStyle newStyle = (XSSFCellStyle) style;
    XSSFFont font = newStyle.getFont();
    if (font.getBold())
        return false;
    if (font.getItalic())
        return false;
    if (font.getUnderline() != XSSFFont.U_NONE)
        return false;
    if (font.getFontHeight() != XSSFFont.DEFAULT_FONT_SIZE)
        return false;
    if (!font.getFontName().equals(XSSFFont.DEFAULT_FONT_NAME))
        return false;
    if (font.getColor() != XSSFFont.DEFAULT_FONT_COLOR) {
        String colorString = getRGBString(font.getXSSFColor());
        if (colorString != null) {
            return false;
        }//from   w w  w .ja v  a2s .c  o m
    }
    return true;
}

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();//from ww w.  ja  v  a  2 s.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();
        }
    }

}

From source file:ru.icc.cells.ssdc.DataLoader.java

License:Apache License

private boolean hasSuperscriptText(Cell excelCell) {
    if (excelCell.getCellType() != Cell.CELL_TYPE_STRING)
        return false;

    RichTextString richTextString = excelCell.getRichStringCellValue();
    if (null == richTextString)
        return false;

    int index = 0;
    int length = 0;
    XSSFFont font = null;//from ww  w  .  ja  va  2  s . c om

    XSSFRichTextString rts = (XSSFRichTextString) richTextString;
    XSSFWorkbook wb = (XSSFWorkbook) workbook;

    XSSFCellStyle style = ((XSSFCell) excelCell).getCellStyle();
    font = style.getFont();

    String richText = rts.getString();
    if (rts.numFormattingRuns() > 1) {
        for (int i = 0; i < rts.numFormattingRuns(); i++) {
            index = rts.getIndexOfFormattingRun(i);
            length = rts.getLengthOfFormattingRun(i);

            try {
                font = rts.getFontOfFormattingRun(i);
            } catch (NullPointerException e) {
                font = wb.getFontAt(XSSFFont.DEFAULT_CHARSET);
                font.setTypeOffset(XSSFFont.SS_NONE);
            }

            String s = richText.substring(index, index + length);

            if (font.getTypeOffset() == XSSFFont.SS_SUPER)
                return true;
        }
    } else {
        if (font.getTypeOffset() == XSSFFont.SS_SUPER)
            return true;
    }
    return false;
}

From source file:ru.icc.cells.ssdc.DataLoader.java

License:Apache License

private String getNotSuperscriptText(Cell excelCell) {
    if (excelCell.getCellType() != Cell.CELL_TYPE_STRING)
        return null;
    RichTextString richTextString = excelCell.getRichStringCellValue();
    if (null == richTextString)
        return null;

    int index;/*from  w w w . j  ava 2s  . c o  m*/
    int length;
    String text;

    XSSFRichTextString rts = (XSSFRichTextString) richTextString;
    XSSFWorkbook wb = (XSSFWorkbook) workbook;

    XSSFCellStyle style = ((XSSFCell) excelCell).getCellStyle();
    XSSFFont font = style.getFont();

    String richText = rts.getString();
    StringBuilder notSuperscriptRuns = new StringBuilder();
    if (rts.numFormattingRuns() > 1) {
        boolean wasNotSuperscriptRun = false;
        for (int i = 0; i < rts.numFormattingRuns(); i++) {
            index = rts.getIndexOfFormattingRun(i);
            length = rts.getLengthOfFormattingRun(i);

            try {
                font = rts.getFontOfFormattingRun(i);
            } catch (NullPointerException e) {
                font = wb.getFontAt(XSSFFont.DEFAULT_CHARSET);
                font.setTypeOffset(XSSFFont.SS_NONE);
            }

            String s = richText.substring(index, index + length);

            if (font.getTypeOffset() == XSSFFont.SS_SUPER) {
                if (wasNotSuperscriptRun)
                    notSuperscriptRuns.append(" ");
                wasNotSuperscriptRun = false;
            } else {
                notSuperscriptRuns.append(s);
                wasNotSuperscriptRun = true;
            }
        }
        text = notSuperscriptRuns.toString();
    } else {
        if (font.getTypeOffset() == XSSFFont.SS_SUPER)
            text = null;
        else
            text = richText;
    }
    return text;
}

From source file:ru.spb.nicetu.tableviewer.server.XSSFHtmlHelper.java

License:Apache License

public void colorStyles(CellStyle style, Formatter out, boolean isBuiltIn) {
    XSSFCellStyle cs = (XSSFCellStyle) style;
    styleColor(out, "background-color", cs.getFillForegroundXSSFColor(), isBuiltIn);
    styleColor(out, "text-color", cs.getFont().getXSSFColor(), isBuiltIn);
}