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

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

Introduction

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

Prototype


boolean getItalic();

Source Link

Document

get whether to use italics or not

Usage

From source file:cn.edu.zucc.chenxg.preview.ToHtml.java

License:Apache License

private void fontStyle(CellStyle style) {
    Font font = wb.getFontAt(style.getFontIndex());

    if (font.getBoldweight() >= HSSFFont.BOLDWEIGHT_BOLD)
        out.format("  font-weight: bold;%n");
    if (font.getItalic())
        out.format("  font-style: italic;%n");

    int fontheight = font.getFontHeightInPoints();
    if (fontheight == 9) {
        //fix for stupid ol Windows
        fontheight = 10;//from  w w w.  j a va 2 s.  com
    }
    out.format("  font-size: %dpt;%n", fontheight);

    // Font color is handled with the other colors
}

From source file:com.canoo.webtest.plugins.exceltest.ExcelVerifyCellStyle.java

License:Open Source License

private static String getFontStyle(final Font font) {
    final StringBuffer sb = new StringBuffer();
    if (font.getBoldweight() == Font.BOLDWEIGHT_BOLD) {
        sb.append("bold ");
    }/*w  w w  .  j  a  v  a  2  s. c  om*/
    if (font.getItalic()) {
        sb.append("italic ");
    }
    if (font.getStrikeout()) {
        sb.append("strikethrough ");
    }
    if (font.getTypeOffset() == Font.SS_SUB) {
        sb.append("subscript ");
    } else if (font.getTypeOffset() == Font.SS_SUPER) {
        sb.append("superscript ");
    }
    switch (font.getUnderline()) {
    case Font.U_NONE:
        break;
    case Font.U_SINGLE:
        sb.append("underline ");
        break;
    case Font.U_SINGLE_ACCOUNTING:
        sb.append("underline-accounting ");
        break;
    case Font.U_DOUBLE:
        sb.append("underline-double ");
        break;
    case Font.U_DOUBLE_ACCOUNTING:
        sb.append("underline-double-accounting ");
        break;
    default:
        sb.append("underline-unknown ");
        break;
    }
    if (sb.length() == 0) {
        return "normal";
    }
    return sb.substring(0, sb.length() - 1);
}

From source file:com.common.report.util.html.ToHtml.java

License:Apache License

private void fontStyle(CellStyle style) {
    Font font = wb.getFontAt(style.getFontIndex());

    if (font.getBoldweight() >= HSSFFont.BOLDWEIGHT_NORMAL)
        out.format("  font-weight: bold;%n");
    if (font.getItalic())
        out.format("  font-style: italic;%n");

    int fontheight = font.getFontHeightInPoints();
    if (fontheight == 9) {
        //fix for stupid ol Windows
        fontheight = 10;/*from  w w w  .  j av  a2s .  com*/
    }
    out.format("  font-size: %dpt;%n", fontheight);

    // Font color is handled with the other colors
}

From source file:com.dua3.meja.model.poi.PoiWorkbook.java

License:Apache License

PoiFont getPoiFont(com.dua3.meja.model.Font font, Style style) {
    Map<String, String> properties = style.properties();

    if (properties.isEmpty() && font instanceof PoiFont && ((PoiFont) font).workbook == this) {
        return (PoiFont) font;
    }//from   ww w . ja  v  a2s  .co  m

    // FIXME JDK 8 
    // String name = properties.getOrDefault(Style.FONT_FAMILY, font.getFamily());
    String name = properties.get(Style.FONT_FAMILY);
    if (name == null) {
        name = font.getFamily();
    }

    String sSize = properties.get(Style.FONT_SIZE);
    short height = (short) Math
            .round(sSize == null ? font.getSizeInPoints() : MejaHelper.decodeFontSize(sSize));

    final String sStyle = properties.get(Style.FONT_STYLE);
    boolean italic = sStyle == null ? font.isItalic() : "italic".equals(sStyle);

    final String sWeight = properties.get(Style.FONT_WEIGHT);
    boolean bold = sWeight == null ? font.isBold() : "bold".equals(sWeight);

    String sDecoration = properties.get(Style.TEXT_DECORATION);
    boolean underline = sDecoration == null ? font.isUnderlined() : "underline".equals(sDecoration);
    boolean strikethrough = sDecoration == null ? font.isStrikeThrough() : "line-through".equals(sDecoration);

    String sColor = properties.get(Style.COLOR);
    Color color = sColor == null ? font.getColor() : Color.valueOf(sColor);

    // try to find existing font
    for (short i = 0; i < poiWorkbook.getNumberOfFonts(); i++) {
        Font poiFont = poiWorkbook.getFontAt(i);

        if (poiFont.getFontName().equalsIgnoreCase(name) && poiFont.getFontHeightInPoints() == height
                && poiFont.getBold() == bold && poiFont.getItalic() == italic
                && (poiFont.getUnderline() != Font.U_NONE) == underline
                && poiFont.getStrikeout() == strikethrough && getColor(poiFont, Color.BLACK).equals(color)
                && poiFont.getTypeOffset() == Font.SS_NONE) {
            return new PoiFont(this, poiFont);
        }
    }

    // if not found, create it
    return createFont(name, height, font.getColor(), bold, italic, underline, strikethrough);
}

From source file:com.googlecode.testcase.annotation.handle.toexcel.strategy.ToHtmlWithExcel.java

License:Apache License

private void fontStyle(CellStyle style) {
    Font font = wb.getFontAt(style.getFontIndex());

    if (font.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL)
        out.format("  font-weight: bold;%n");
    if (font.getItalic())
        out.format("  font-style: italic;%n");

    int fontheight = font.getFontHeightInPoints();
    if (fontheight == 9) {
        //fix for stupid ol Windows
        fontheight = 10;/*  w ww.  ja v a  2s . c o  m*/
    }
    out.format("  font-size: %dpt;%n", fontheight);

    // Font color is handled with the other colors
}

From source file:com.hurry.excel.html.Excel2Html.java

License:Apache License

private void fontStyle(CellStyle style) {
    Font font = wb.getFontAt(style.getFontIndex());

    if (font.getBoldweight() >= HSSFFont.BOLDWEIGHT_NORMAL)
        out.format("  font-weight: bold;%n");
    if (font.getItalic())
        out.format("  font-style: italic;%n");

    int fontheight = font.getFontHeightInPoints();
    if (fontheight == 9) {
        // fix for stupid ol Windows
        fontheight = 10;/*ww  w .  ja  va  2 s . c o m*/
    }
    out.format("  font-size: %dpt;%n", fontheight);

    // Font color is handled with the other colors
}

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

License:Open Source License

private void fontStyle(StringBuilder sb, CellStyle cellStyle) {
    try {//from  ww w  . j a va 2s .c om
        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:guru.qas.martini.report.DefaultState.java

License:Apache License

protected void colorCompromisedThemes() {
    Collection<Cell> failed = statii.get("FAILED");

    if (!failed.isEmpty()) {
        List<Row> rows = Lists.newArrayListWithExpectedSize(failed.size());
        for (Cell cell : failed) {
            Row row = cell.getRow();/*  w ww .  ja v a  2  s  . c o m*/
            rows.add(row);
        }

        Set<Cell> compromisedThemeCells = Sets.newHashSet();

        Map<String, Collection<Cell>> themeMap = themes.asMap();
        for (Map.Entry<String, Collection<Cell>> mapEntry : themeMap.entrySet()) {
            Collection<Cell> themeCells = mapEntry.getValue();

            boolean compromised = false;
            for (Iterator<Cell> iterator = themeCells.iterator(); !compromised && iterator.hasNext();) {
                Cell themeCell = iterator.next();
                Row row = themeCell.getRow();
                compromised = rows.contains(row);
            }

            if (compromised) {
                compromisedThemeCells.addAll(themeCells);
            }
        }

        Set<String> compromisedThemes = Sets.newHashSet();
        for (Cell themeCell : compromisedThemeCells) {
            String contents = themeCell.getStringCellValue();
            if (null != contents) {
                Iterable<String> themes = Splitter.onPattern("\\s+").omitEmptyStrings().split(contents);
                Iterables.addAll(compromisedThemes, themes);
            }
        }

        for (String theme : compromisedThemes) {
            Collection<Cell> cells = themes.get(theme);
            for (Cell cell : cells) {
                CellStyle cellStyle = cell.getCellStyle();
                Sheet sheet = cell.getSheet();
                Workbook workbook = sheet.getWorkbook();

                int originalFontIndex = cellStyle.getFontIndexAsInt();
                Font originalFont = workbook.getFontAt(originalFontIndex);

                CellStyle clone = workbook.createCellStyle();
                clone.cloneStyleFrom(cellStyle);

                Font font = workbook.findFont(true, IndexedColors.DARK_RED.getIndex(),
                        originalFont.getFontHeight(), originalFont.getFontName(), originalFont.getItalic(),
                        originalFont.getStrikeout(), originalFont.getTypeOffset(), originalFont.getUnderline());

                if (null == font) {
                    font = workbook.createFont();
                    font.setBold(true);
                    font.setColor(IndexedColors.DARK_RED.getIndex());
                    font.setFontHeight(originalFont.getFontHeight());
                    font.setFontName(originalFont.getFontName());
                    font.setItalic(originalFont.getItalic());
                    font.setStrikeout(originalFont.getStrikeout());
                    font.setTypeOffset(originalFont.getTypeOffset());
                    font.setUnderline(originalFont.getUnderline());
                }
                clone.setFont(font);
                cell.setCellStyle(clone);
            }
        }
    }
}

From source file:jdbreport.model.io.xls.poi.Excel2003Writer.java

License:Apache License

private Font getFont(short fontIndex, AttributeSet attributeSet, Workbook wb) {
    Font font = null;/*w w  w.j av a  2  s . c  o  m*/
    String family = null;
    String sizeStr = null;
    short color = 0;
    boolean bold = false;
    boolean italic = false;
    boolean underline = false;
    boolean line_through = false;
    boolean sub = false;
    boolean sup = false;
    Enumeration<?> en = attributeSet.getAttributeNames();
    while (en.hasMoreElements()) {
        Object key = en.nextElement();
        String name = key.toString();
        String attribute = attributeSet.getAttribute(key).toString();

        switch (name) {
        case "font-weight":
            bold = attribute.equals("bold");
            break;
        case "font-style":
            italic = attribute.equals("italic");
            break;
        case "text-decoration":
            if (attribute.equals("underline")) {
                underline = true;
            } else if (attribute.equals("line-through")) {
                line_through = true;
            }
            break;
        case "font-family":
            family = attribute;
            break;
        case "font-size":
            sizeStr = attribute;

            break;
        case "color":
            Color fontColor = Utils.colorByName(attribute);
            if (fontColor == null) {
                try {
                    fontColor = Utils.stringToColor(attribute);
                } catch (Exception ignored) {

                }
            }
            if (fontColor != null) {
                color = colorToIndex(wb, fontColor);
            }
            break;
        case "vertical-align":
            if (attribute.equals("sub")) {
                sub = true;
            } else if (attribute.equals("sup")) {
                sup = true;
            }
            break;
        }
    }
    if (family != null || bold || italic || underline || line_through || color > 0 || sizeStr != null || sub
            || sup) {

        font = wb.createFont();
        if (fontIndex > 0) {
            Font parentFont = wb.getFontAt(fontIndex);
            if (parentFont != null) {
                font.setBold(parentFont.getBold());
                font.setColor(parentFont.getColor());
                try {
                    font.setCharSet(parentFont.getCharSet());
                } catch (Throwable ignored) {
                }
                font.setFontHeight(parentFont.getFontHeight());
                font.setFontName(parentFont.getFontName());
                font.setItalic(parentFont.getItalic());
                font.setStrikeout(parentFont.getStrikeout());
                font.setUnderline(parentFont.getUnderline());
                font.setTypeOffset(parentFont.getTypeOffset());
            }
        }
        if (family != null) {
            font.setFontName(family);
        }
        if (bold) {
            font.setBold(true);
        }
        if (italic) {
            font.setItalic(italic);
        }
        if (underline) {
            font.setUnderline(Font.U_SINGLE);
        }
        if (line_through) {
            font.setStrikeout(line_through);
        }
        if (color > 0) {
            font.setColor(color);
        }
        if (sizeStr != null) {
            short size = (short) Float.parseFloat(sizeStr);
            if (sizeStr.charAt(0) == '+' || sizeStr.charAt(0) == '-') {
                size = (short) (Content.pointToSize(font.getFontHeightInPoints()) + size);
            }
            font.setFontHeightInPoints(Content.sizeToPoints(size));
        }
        if (sup) {
            font.setTypeOffset(Font.SS_SUPER);
        } else if (sub) {
            font.setTypeOffset(Font.SS_SUB);
        }
    }
    return font;
}

From source file:net.ceos.project.poi.annotated.core.ConditionalFormattingHandler.java

License:Apache License

/**
 * Apply the conditional formatting according the values defined at the
 * respective annotation. Is only available at the declared object, in
 * another words, at the linked {@link Sheet} with the object.
 * /* w w  w  . ja v  a2  s  .  c o m*/
 * @param configCriteria
 *            the {@link XConfigCriteria}
 * @param conditionalFomat
 *            the {@link XlsConditionalFormat}
 * @throws ConfigurationException
 */
protected static void applyCondition(XConfigCriteria configCriteria, XlsConditionalFormat conditionalFomat)
        throws ConfigurationException {
    // Define a Conditional Formatting rule, which triggers formatting
    // according the developer definition and applies patternFormatting
    SheetConditionalFormatting sheet = configCriteria.getSheet().getSheetConditionalFormatting();

    /* apply all rules defined */
    int i = 0;
    ConditionalFormattingRule[] rules = new ConditionalFormattingRule[conditionalFomat.rules().length];
    XlsConditionalFormatRules[] rulesAnnotated = conditionalFomat.rules();
    for (XlsConditionalFormatRules rule : rulesAnnotated) {
        ConditionalFormattingRule setRule = sheet.createConditionalFormattingRule(rule.operator(),
                rule.formula1(), StringUtils.isNotBlank(rule.formula2()) ? rule.formula2() : null);

        CellStyle decorator = null;
        try {
            decorator = configCriteria.getCellStyle(conditionalFomat.decorator());
        } catch (ElementException e) {
            throw new ConfigurationException(ExceptionMessage.CONFIGURATION_DECORATOR_MISSING.getMessage(), e);
        }
        /* add FontFormatting */
        FontFormatting fontFormat = setRule.createFontFormatting();
        Font f = configCriteria.getWorkbook().getFontAt(decorator.getFontIndex());
        fontFormat.setFontStyle(f.getItalic(), f.getBold());
        fontFormat.setFontColorIndex(f.getColor());
        fontFormat.setUnderlineType(f.getUnderline());

        /* add BorderFormatting */
        BorderFormatting borderFormat = setRule.createBorderFormatting();
        borderFormat.setBorderBottom(decorator.getBorderBottom());
        borderFormat.setBorderTop(decorator.getBorderTop());
        borderFormat.setBorderLeft(decorator.getBorderLeft());
        borderFormat.setBorderRight(decorator.getBorderRight());
        borderFormat.setBottomBorderColor(decorator.getBottomBorderColor());
        borderFormat.setTopBorderColor(decorator.getTopBorderColor());
        borderFormat.setLeftBorderColor(decorator.getLeftBorderColor());
        borderFormat.setRightBorderColor(decorator.getRightBorderColor());

        /* add PatternFormatting */
        PatternFormatting patternFormat = setRule.createPatternFormatting();
        patternFormat.setFillBackgroundColor(decorator.getFillForegroundColor());

        /* join rule */
        rules[i++] = setRule;
    }

    /* Define a region */
    CellRangeAddress[] regions = { CellRangeAddress.valueOf(CellFormulaConverter
            .calculateRangeAddressFromTemplate(configCriteria, conditionalFomat.rangeAddress())) };

    /* Apply Conditional Formatting rule defined above to the regions */
    sheet.addConditionalFormatting(regions, rules);

}