View | Details | Raw Unified | Return to bug 44508
Collapse All | Expand All

(-)src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (-1 / +29 lines)
Lines 452-458 Link Here
452
                boolRec.setColumn(col);
452
                boolRec.setColumn(col);
453
                if (setValue)
453
                if (setValue)
454
                {
454
                {
455
                    boolRec.setValue(getBooleanCellValue());
455
                    boolRec.setValue(convertCellValueToBoolean());
456
                }
456
                }
457
                boolRec.setXFIndex(styleIndex);
457
                boolRec.setXFIndex(styleIndex);
458
                boolRec.setRow(row);
458
                boolRec.setRow(row);
Lines 825-831 Link Here
825
        }
825
        }
826
        (( BoolErrRecord ) record).setValue(value);
826
        (( BoolErrRecord ) record).setValue(value);
827
    }
827
    }
828
    /**
829
     * Chooses a new boolean value for the cell when its type is changing.<p/>
830
     * 
831
     * Usually the caller is calling setCellType() with the intention of calling 
832
     * setCellValue(boolean) straight afterwards.  This method only exists to give
833
     * the cell a somewhat reasonable value until the setCellValue() call (if at all).
834
     * TODO - perhaps a method like setCellTypeAndValue(int, Object) should be introduced to avoid this
835
     */
836
    private boolean convertCellValueToBoolean() {
837
        
838
        switch (cellType) {
839
            case CELL_TYPE_BOOLEAN:
840
                return (( BoolErrRecord ) record).getBooleanValue();
841
            case CELL_TYPE_STRING:
842
                return Boolean.valueOf(((StringRecord)record).getString()).booleanValue();
843
            case CELL_TYPE_NUMERIC:
844
                return ((NumberRecord)record).getValue() != 0;
828
845
846
            // All other cases convert to false
847
            // These choices are not well justified.
848
            case CELL_TYPE_FORMULA:  
849
                // should really evaluate, but HSSFCell can't call HSSFFormulaEvaluator
850
            case CELL_TYPE_ERROR:
851
            case CELL_TYPE_BLANK:
852
                return false;  
853
        }
854
        throw new RuntimeException("Unexpected cell type (" + cellType + ")");
855
    }
856
829
    /**
857
    /**
830
     * get the value of the cell as a boolean.  For strings, numbers, and errors, we throw an exception.
858
     * get the value of the cell as a boolean.  For strings, numbers, and errors, we throw an exception.
831
     * For blank cells we return a false.
859
     * For blank cells we return a false.

Return to bug 44508