Example usage for org.apache.poi.ss.usermodel CellStyle getFontIndex

List of usage examples for org.apache.poi.ss.usermodel CellStyle getFontIndex

Introduction

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

Prototype

@Removal(version = "4.2")
short getFontIndex();

Source Link

Document

gets the index of the font for this style

Usage

From source file:CellStyleDetails.java

License:Apache License

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        throw new IllegalArgumentException("Filename must be given");
    }//from  ww  w.ja  v  a2  s  . c o  m

    Workbook wb = WorkbookFactory.create(new File(args[0]));
    DataFormatter formatter = new DataFormatter();

    for (int sn = 0; sn < wb.getNumberOfSheets(); sn++) {
        Sheet sheet = wb.getSheetAt(sn);
        System.out.println("Sheet #" + sn + " : " + sheet.getSheetName());

        for (Row row : sheet) {
            System.out.println("  Row " + row.getRowNum());

            for (Cell cell : row) {
                CellReference ref = new CellReference(cell);
                System.out.print("    " + ref.formatAsString());
                System.out.print(" (" + cell.getColumnIndex() + ") ");

                CellStyle style = cell.getCellStyle();
                System.out.print("Format=" + style.getDataFormatString() + " ");
                System.out.print("FG=" + renderColor(style.getFillForegroundColorColor()) + " ");
                System.out.print("BG=" + renderColor(style.getFillBackgroundColorColor()) + " ");

                Font font = wb.getFontAt(style.getFontIndex());
                System.out.print("Font=" + font.getFontName() + " ");
                System.out.print("FontColor=");
                if (font instanceof HSSFFont) {
                    System.out.print(renderColor(((HSSFFont) font).getHSSFColor((HSSFWorkbook) wb)));
                }
                if (font instanceof XSSFFont) {
                    System.out.print(renderColor(((XSSFFont) font).getXSSFColor()));
                }

                System.out.println();
                System.out.println("        " + formatter.formatCellValue(cell));
            }
        }

        System.out.println();
    }
}

From source file:bad.robot.excel.style.ReplaceExistingStyle.java

License:Apache License

private void applyFontTo(CellStyle style, Workbook workbook) {
    if (fontSize != null) {
        Font font = workbook.createFont();
        font.setFontHeightInPoints(fontSize.value());
        font.setColor(fontColour.value().getPoiStyle());
        style.setFont(font);//from  ww w  .j a  v a  2  s .c  om
    } else {
        // doesn't work
        Font existing = workbook.getFontAt(style.getFontIndex());
        existing.setColor(fontColour.value().getPoiStyle());
        style.setFont(existing);
    }
}

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;/* www  .  j a  va  2 s . c  om*/
    }
    out.format("  font-size: %dpt;%n", fontheight);

    // Font color is handled with the other colors
}

From source file:com.b2international.snowowl.datastore.server.importer.ExcelUtilities.java

License:Apache License

/**
 * Returns true if the cell (NOT the text inside) is set to bold.
 * @param cell/*  w  w  w .j  a v a 2 s  . c o  m*/
 * @return
 */
public static boolean isBold(Cell cell) {
    CellStyle style = cell.getCellStyle();
    Workbook workBook = cell.getSheet().getWorkbook();
    Font font = workBook.getFontAt(style.getFontIndex());
    XSSFFont xssfFont = (XSSFFont) font;
    return xssfFont.getBold();
}

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

License:Open Source License

private Font getFont(final CellStyle cellStyle) {
    return getExcelWorkbook().getFontAt(cellStyle.getFontIndex());
}

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

License:Open Source License

public void testUnknownProperties() throws Exception {
    final ExcelVerifyCellStyle step = (ExcelVerifyCellStyle) getStep();
    step.setCell("B2");
    final CellStyle cellStyle = step.getExcelCell().getCellStyle();
    cellStyle.setBorderTop(Short.MAX_VALUE);
    cellStyle.setAlignment(Short.MAX_VALUE);
    cellStyle.setVerticalAlignment(Short.MAX_VALUE);
    cellStyle.setFillPattern(Short.MAX_VALUE);
    final Font fontAt = step.getExcelWorkbook().getFontAt(cellStyle.getFontIndex());
    fontAt.setUnderline(Byte.MAX_VALUE);
    step.setBorder("top:unknown");
    step.setAlign("unknown");
    step.setValign("unknown");
    step.setFillPattern("unknown");
    step.setFontStyle("bold underline-unknown");
    executeStep(step);/*from   w  w w.j a  v  a2  s  .  c o m*/
}

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 .ja v  a  2  s. com*/
    }
    out.format("  font-size: %dpt;%n", fontheight);

    // Font color is handled with the other colors
}

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;//from  www.j  a v  a 2  s. c om
    }
    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;/* w w w . j a v  a 2  s  . co 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 defaultFontStyle(CellStyle cellStyle, StringBuilder sb) {
    if (cellStyle.getIndex() == 0) {
        defaultFont = spreadsheet.getWorkbook().getFontAt(cellStyle.getFontIndex());
        defaultFontFamily = styleFontFamily(defaultFont);
        sb.append(defaultFontFamily);//  www . j  av  a 2s .  c o m
        if (defaultFont.getBoldweight() != Font.BOLDWEIGHT_NORMAL) {
            sb.append("font-weight:");
            sb.append(defaultFont.getBoldweight());
            sb.append(";");
        }
        if (defaultFont.getItalic()) {
            sb.append("font-style:italic;");
        }
        defaultFontHeightInPoints = defaultFont.getFontHeightInPoints();
        sb.append("font-size:");
        sb.append(defaultFontHeightInPoints);
        sb.append("pt;");
        if (defaultFont.getUnderline() != Font.U_NONE) {
            sb.append("text-decoration:underline;");
        } else if (defaultFont.getStrikeout()) {
            sb.append("text-decoration:overline;");
        }
    }
}