Example usage for org.apache.poi.hssf.record FormulaRecord hasCachedResultString

List of usage examples for org.apache.poi.hssf.record FormulaRecord hasCachedResultString

Introduction

In this page you can find the example usage for org.apache.poi.hssf.record FormulaRecord hasCachedResultString.

Prototype

public boolean hasCachedResultString() 

Source Link

Usage

From source file:org.jreserve.gui.poi.read.xls.XlsTableReader.java

License:Open Source License

private void cellRecord(int row, short column, Record record) throws Exception {
    try {// w  ww  .  j  a  v a2  s  .com
        //Not on the good sheet, before first row/column
        if (!onReferencedSheet || firstRow > row || firstColumn > column)
            return;

        //The cell is empty, do not read it
        boolean isEmptyCell = isEmpty(record);
        if (isEmptyCell) {
            //If first cell is empty, whole table is empty
            if (firstRow == row && firstColumn == column)
                lastColumn = (short) (firstColumn - 1);
            return;
        }

        //Calculate the last column, based on the first row
        if (firstRow == row) {
            //If we missed a cell, do not read other columns
            if ((column - lastColumn) < 2)
                lastColumn = column;
        }

        //after the last column
        if (column > lastColumn)
            return;

        if (column == firstColumn)
            prevColumn = firstColumn;

        //missed a row, do not read further
        if ((row - prevRow) > 1 || (column - prevColumn) > 1)
            return;

        short sid = record.getSid();
        switch (sid) {
        case NumberRecord.sid:
            factory.numberFound(row, column, ((NumberRecord) record).getValue());
            break;
        case LabelSSTRecord.sid:
            if (sstRecord == null)
                throw new IllegalArgumentException("SSTRecord is null");
            int stringId = ((LabelSSTRecord) record).getSSTIndex();
            String str = sstRecord.getString(stringId).getString();
            factory.stringFound(row, column, str);
            break;
        case LabelRecord.sid:
            factory.stringFound(row, column, ((LabelRecord) record).getValue());
            break;
        case StringRecord.sid:
            factory.stringFound(row, column, ((StringRecord) record).getString());
            break;
        case FormulaRecord.sid:
            FormulaRecord fr = (FormulaRecord) record;
            if (fr.hasCachedResultString()) {
                outputNextString = true;
            } else {
                factory.numberFound(row, column, fr.getValue());
            }
            break;
        case BoolErrRecord.sid:
            BoolErrRecord ber = (BoolErrRecord) record;
            if (ber.isBoolean()) {
                factory.booleanFound(row, column, ber.getBooleanValue());
            } else {
                factory.errorFound(row, column, getErrorMsg(ber.getErrorValue()));
            }
            break;
        default:
            break;
        }

        prevRow = row;
        prevColumn = column;
    } catch (Exception ex) {
        CellReference ref = new CellReference(sheetName, row, column, false, false);
        throw new ExcelReadException(ref, ex);
    }
}