Search in sources :

Example 6 with BoolErrRecord

use of org.apache.poi.hssf.record.BoolErrRecord in project poi by apache.

the class HSSFCell method convertCellValueToBoolean.

/**
     * Chooses a new boolean value for the cell when its type is changing.<p/>
     *
     * Usually the caller is calling setCellType() with the intention of calling
     * setCellValue(boolean) straight afterwards.  This method only exists to give
     * the cell a somewhat reasonable value until the setCellValue() call (if at all).
     * TODO - perhaps a method like setCellTypeAndValue(int, Object) should be introduced to avoid this
     */
private boolean convertCellValueToBoolean() {
    switch(_cellType) {
        case BOOLEAN:
            return ((BoolErrRecord) _record).getBooleanValue();
        case STRING:
            int sstIndex = ((LabelSSTRecord) _record).getSSTIndex();
            String text = _book.getWorkbook().getSSTString(sstIndex).getString();
            return Boolean.valueOf(text).booleanValue();
        case NUMERIC:
            return ((NumberRecord) _record).getValue() != 0;
        case FORMULA:
            // use cached formula result if it's the right type:
            FormulaRecord fr = ((FormulaRecordAggregate) _record).getFormulaRecord();
            checkFormulaCachedValueType(CellType.BOOLEAN, fr);
            return fr.getCachedBooleanValue();
        // These choices are not well justified.
        case ERROR:
        case BLANK:
            return false;
    }
    throw new RuntimeException("Unexpected cell type (" + _cellType + ")");
}
Also used : BoolErrRecord(org.apache.poi.hssf.record.BoolErrRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) FormulaRecordAggregate(org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate) RichTextString(org.apache.poi.ss.usermodel.RichTextString) UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) LabelSSTRecord(org.apache.poi.hssf.record.LabelSSTRecord)

Aggregations

BoolErrRecord (org.apache.poi.hssf.record.BoolErrRecord)6 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)5 FormulaRecordAggregate (org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate)5 LabelSSTRecord (org.apache.poi.hssf.record.LabelSSTRecord)4 BlankRecord (org.apache.poi.hssf.record.BlankRecord)2 NumberRecord (org.apache.poi.hssf.record.NumberRecord)2 UnicodeString (org.apache.poi.hssf.record.common.UnicodeString)2 RichTextString (org.apache.poi.ss.usermodel.RichTextString)2 LastCellOfRowDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord)1 MissingCellDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord)1 BOFRecord (org.apache.poi.hssf.record.BOFRecord)1 LabelRecord (org.apache.poi.hssf.record.LabelRecord)1 NoteRecord (org.apache.poi.hssf.record.NoteRecord)1 RKRecord (org.apache.poi.hssf.record.RKRecord)1 StringRecord (org.apache.poi.hssf.record.StringRecord)1