Example usage for org.apache.poi.ss.usermodel Font getIndex

List of usage examples for org.apache.poi.ss.usermodel Font getIndex

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Font getIndex.

Prototype

@Removal(version = "4.2")
public short getIndex();

Source Link

Document

Get the index within the XSSFWorkbook (sequence within the collection of Font objects)

Usage

From source file:com.helger.poi.excel.style.ExcelStyle.java

License:Apache License

/**
 * Set the index of the font to use. The font must have been previously
 * created via Workbook.createFont()!/*from ww w .  j  a v  a  2s  .c om*/
 *
 * @param aFont
 *        The font to use. May not be <code>null</code>.
 * @return this
 */
@Nonnull
public ExcelStyle setFont(@Nonnull final Font aFont) {
    ValueEnforcer.notNull(aFont, "Font");
    return setFontIndex(aFont.getIndex());
}

From source file:com.vaadin.addon.spreadsheet.SpreadsheetStyleFactory.java

License:Open Source License

private void fontStyle(StringBuilder sb, CellStyle cellStyle) {
    try {/*from   w w  w . ja va  2s  . co m*/
        Font font = spreadsheet.getWorkbook().getFontAt(cellStyle.getFontIndex());
        if (font.getIndex() == defaultFont.getIndex()) {
            // uses default font, no need to add styles
            return;
        }
        String fontFamily = styleFontFamily(font);
        if (!fontFamily.equals(defaultFontFamily)) {
            sb.append(fontFamily);
        }
        if (font.getBoldweight() != Font.BOLDWEIGHT_NORMAL) {
            sb.append("font-weight:");
            sb.append(font.getBoldweight());
            sb.append(";");
        }
        if (font.getItalic()) {
            sb.append("font-style:italic;");
        }
        final int fontheight = font.getFontHeightInPoints();
        if (fontheight != defaultFontHeightInPoints) {
            sb.append("font-size:");
            sb.append(fontheight);
            sb.append("pt;");
        }
        if (font.getUnderline() != Font.U_NONE) {
            sb.append("text-decoration:underline;");
        } else if (font.getStrikeout()) {
            sb.append("text-decoration:overline;");
        }
    } catch (IndexOutOfBoundsException ioobe) {
        // somehow workbook doesn't have all the fonts the cells have???
        LOGGER.log(Level.WARNING, "Font missing, " + cellStyle.getFontIndex() + " / " + cellStyle.getClass()
                + ", " + ioobe.getMessage(), ioobe);
    }
}

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);/*w  w w  .  j a  va  2  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);
}