Exemplo n.º 1
0
        /*package*/
        private void SetType(CellType type)
        {
            switch (type)
            {
            case CellType.Numeric:
            {
                _value = new NumericValue();
                break;
            }

            case CellType.String:
            {
                PlainStringValue sval = new PlainStringValue();
                if (_value != null)
                {
                    // if a cell is not blank then convert the old value to string
                    String str = ConvertCellValueToString();
                    sval.Value = str;
                }
                _value = sval;
                break;
            }

            case CellType.Formula:
            {
                _value = new NumericFormulaValue();
                break;
            }

            case CellType.Blank:
            {
                _value = new BlankValue();
                break;
            }

            case CellType.Boolean:
            {
                BooleanValue bval = new BooleanValue();
                if (_value != null)
                {
                    // if a cell is not blank then convert the old value to string
                    bool val = convertCellValueToBoolean();
                    bval.Value = val;
                }
                _value = bval;
                break;
            }

            case CellType.Error:
            {
                _value = new ErrorValue();
                break;
            }

            default:
            {
                throw new ArgumentException("Illegal type " + type);
            }
            }
        }
Exemplo n.º 2
0
 private void EnsurePlainStringType()
 {
     if (_value.GetType() != CellType.String ||
         ((StringValue)_value).IsRichText())
     {
         _value = new PlainStringValue();
     }
 }
Exemplo n.º 3
0
 private void EnsureRichTextStringType()
 {
     if (_value.GetType() != CellType.String ||
         !((StringValue)_value).IsRichText())
     {
         _value = new RichTextValue();
     }
 }
Exemplo n.º 4
0
        private void setFormulaType(CellType type)
        {
            Value prevValue = _value;

            switch (type)
            {
            case CellType.Numeric:
            {
                _value = new NumericFormulaValue();
                break;
            }

            case CellType.String:
            {
                _value = new StringFormulaValue();
                break;
            }

            case CellType.Boolean:
            {
                _value = new BooleanFormulaValue();
                break;
            }

            case CellType.Error:
            {
                _value = new ErrorFormulaValue();
                break;
            }

            default:
            {
                throw new ArgumentException("Illegal type " + type);
            }
            }

            // if we had a Formula before, we should copy over the _value of the formula
            if (prevValue is FormulaValue)
            {
                ((FormulaValue)_value).Value = ((FormulaValue)prevValue).Value;
            }
        }
Exemplo n.º 5
0
        public void RemoveFormula()
        {
            if (CellType != CellType.Formula)
            {
                return;
            }
            switch (CachedFormulaResultType)
            {
            case CellType.Numeric:
                double numericValue = ((NumericFormulaValue)_value).PreEvaluatedValue;
                _value = new NumericValue();
                ((NumericValue)_value).Value = numericValue;
                break;

            case CellType.String:
                String stringValue = ((StringFormulaValue)_value).PreEvaluatedValue;
                _value = new PlainStringValue();
                ((PlainStringValue)_value).Value = stringValue;
                break;

            case CellType.Boolean:
                bool booleanValue = ((BooleanFormulaValue)_value).PreEvaluatedValue;
                _value = new BooleanValue();
                ((BooleanValue)_value).Value = booleanValue;
                break;

            case CellType.Error:
                byte errorValue = (byte)((ErrorFormulaValue)_value).PreEvaluatedValue;
                _value = new ErrorValue();
                ((ErrorValue)_value).Value = errorValue;
                break;

            default:
                throw new InvalidOperationException();
            }
        }