Example usage for org.apache.poi.ss.usermodel Workbook getNumCellStyles

List of usage examples for org.apache.poi.ss.usermodel Workbook getNumCellStyles

Introduction

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

Prototype

int getNumCellStyles();

Source Link

Document

Get the number of styles the workbook contains

Usage

From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.xls.helper.HSSFCellStyleProducer.java

License:Open Source License

/**
 * The class does the dirty work of creating the HSSF-objects.
 *
 * @param workbook/*from  w  ww.j av  a  2 s .c o m*/
 *          the workbook for which the styles should be created.
 */
public HSSFCellStyleProducer(final Workbook workbook, final boolean hardLimit,
        final ExcelColorProducer colorProducer, final ExcelColorProducer fontColorProducer) {
    this.fontColorProducer = fontColorProducer;
    if (workbook == null) {
        throw new NullPointerException();
    }
    if (colorProducer == null) {
        throw new NullPointerException();
    }
    this.colorProducer = colorProducer;
    this.styleCache = new HashMap<HSSFCellStyleKey, CellStyle>();
    this.workbook = workbook;
    this.fontFactory = new ExcelFontFactory(workbook, fontColorProducer);
    this.dataFormat = workbook.createDataFormat();
    this.hardLimit = hardLimit;

    if (workbook instanceof XSSFWorkbook) {
        final XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
        final int predefinedStyles = workbook.getNumCellStyles();
        for (int i = 0; i < predefinedStyles; i++) {
            final XSSFCellStyle cellStyleAt = xssfWorkbook.getCellStyleAt(i);
            this.styleCache.put(new HSSFCellStyleKey(cellStyleAt), cellStyleAt);
        }
    } else {
        // Read in the styles ...
        final int predefinedStyles = workbook.getNumCellStyles();
        for (int i = 0; i < predefinedStyles; i++) {
            final CellStyle cellStyleAt = workbook.getCellStyleAt(i);
            this.styleCache.put(new HSSFCellStyleKey(cellStyleAt), cellStyleAt);
        }
    }
}