Java Code Examples for org.apache.poi.hssf.record.FormulaRecord#getCachedBooleanValue()

The following examples show how to use org.apache.poi.hssf.record.FormulaRecord#getCachedBooleanValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HSSFCell.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * get the value of the cell as a boolean.  For strings, numbers, and errors, we throw an exception.
 * For blank cells we return a false.
 */
@Override
public boolean getBooleanCellValue() {

    switch(_cellType) {
        case BLANK:
            return false;
        case BOOLEAN:
            return (( BoolErrRecord ) _record).getBooleanValue();
        case FORMULA:
            break;
        default:
            throw typeMismatch(CellType.BOOLEAN, _cellType, false);
    }
    FormulaRecord fr = ((FormulaRecordAggregate)_record).getFormulaRecord();
    checkFormulaCachedValueType(CellType.BOOLEAN, fr);
    return fr.getCachedBooleanValue();
}
 
Example 2
Source File: HSSFCell.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
        // Other cases convert to false
        // These choices are not well justified.
        case ERROR:
        case BLANK:
            return false;
    }
    throw new RuntimeException("Unexpected cell type (" + _cellType + ")");
}
 
Example 3
Source File: HSSFCell.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private String convertCellValueToString() {

        switch (_cellType) {
            case BLANK:
                return "";
            case BOOLEAN:
                return ((BoolErrRecord) _record).getBooleanValue() ? "TRUE" : "FALSE";
            case STRING:
                int sstIndex = ((LabelSSTRecord)_record).getSSTIndex();
                return _book.getWorkbook().getSSTString(sstIndex).getString();
            case NUMERIC:
                return NumberToTextConverter.toText(((NumberRecord)_record).getValue());
            case ERROR:
                   return FormulaError.forInt(((BoolErrRecord)_record).getErrorValue()).getString();
            case FORMULA:
                // should really evaluate, but HSSFCell can't call HSSFFormulaEvaluator
                // just use cached formula result instead
                break;
            default:
                throw new IllegalStateException("Unexpected cell type (" + _cellType + ")");
        }
        FormulaRecordAggregate fra = ((FormulaRecordAggregate)_record);
        FormulaRecord fr = fra.getFormulaRecord();
        switch (CellType.forInt(fr.getCachedResultType())) {
            case BOOLEAN:
                return fr.getCachedBooleanValue() ? "TRUE" : "FALSE";
            case STRING:
                return fra.getStringValue();
            case NUMERIC:
                return NumberToTextConverter.toText(fr.getValue());
            case ERROR:
                return FormulaError.forInt(fr.getCachedErrorValue()).getString();
            default:
                throw new IllegalStateException("Unexpected formula result type (" + _cellType + ")");
        }
        
    }