Example usage for org.apache.poi.hssf.usermodel HSSFFont getIndex

List of usage examples for org.apache.poi.hssf.usermodel HSSFFont getIndex

Introduction

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

Prototype


public short getIndex() 

Source Link

Document

get the index within the HSSFWorkbook (sequence within the collection of Font objects)

Usage

From source file:com.develog.utils.report.engine.export.JRXlsExporter.java

License:Open Source License

/**
 *
 *///www  .j a  v a 2 s .  c  om
protected HSSFCellStyle getLoadedCellStyle(short mode, short backcolor, short horizontalAlignment,
        short verticalAlignment, short rotation, HSSFFont font) {
    HSSFCellStyle cellStyle = null;

    if (loadedCellStyles != null && loadedCellStyles.size() > 0) {
        HSSFCellStyle cs = null;
        for (int i = 0; i < loadedCellStyles.size(); i++) {
            cs = (HSSFCellStyle) loadedCellStyles.get(i);

            if (cs.getFillPattern() == mode && cs.getFillForegroundColor() == backcolor
                    && cs.getAlignment() == horizontalAlignment
                    && cs.getVerticalAlignment() == verticalAlignment && cs.getRotation() == rotation
                    && cs.getFontIndex() == font.getIndex()) {
                cellStyle = cs;
                break;
            }
        }
    }

    if (cellStyle == null) {
        cellStyle = workbook.createCellStyle();
        cellStyle.setFillForegroundColor(backcolor);
        cellStyle.setFillPattern(mode);
        cellStyle.setAlignment(horizontalAlignment);
        cellStyle.setVerticalAlignment(verticalAlignment);
        cellStyle.setRotation(rotation);
        cellStyle.setFont(font);
        cellStyle.setWrapText(true);

        loadedCellStyles.add(cellStyle);
    }

    return cellStyle;
}

From source file:com.haulmont.cuba.gui.export.ExcelAutoColumnSizer.java

License:Apache License

private FontMetrics getFontMetrics(HSSFFont hf) {
    FontMetrics fm;//from w  ww  .j ava 2 s.  c  o m
    Short pFont = new Short(hf.getIndex());

    fm = (FontMetrics) fontMetrics.get(pFont);
    if (fm == null) {
        int style;
        if ((hf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) || hf.getItalic()) {
            style = 0;
            if (hf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD)
                style ^= Font.BOLD;
            if (hf.getItalic())
                style ^= Font.ITALIC;
        } else {
            style = Font.PLAIN;
        }
        Font f = new java.awt.Font(hf.getFontName(), style, hf.getFontHeightInPoints());

        if (graphics == null) {
            BufferedImage i = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY);
            graphics = i.createGraphics();
        }

        fm = graphics.getFontMetrics(f);
        fontMetrics.put(pFont, fm);
    }

    return fm;
}