Exemple #1
0
        private object TryGetFormulaValue(XlsBiffStream biffStream, XlsBiffFormulaCell formulaCell, ExtendedFormat effectiveStyle)
        {
            return(formulaCell.FormulaType switch
            {
                XlsBiffFormulaCell.FormulaValueType.Boolean => formulaCell.BooleanValue,
                XlsBiffFormulaCell.FormulaValueType.Error => null,
                XlsBiffFormulaCell.FormulaValueType.EmptyString => string.Empty,
                XlsBiffFormulaCell.FormulaValueType.Number => TryConvertOADateTime(formulaCell.XNumValue, effectiveStyle.NumberFormatIndex),
                XlsBiffFormulaCell.FormulaValueType.String => TryGetFormulaString(biffStream, effectiveStyle),

                // Bad data or new formula value type
                _ => null,
            });
Exemple #2
0
        private object TryGetFormulaValue(XlsBiffStream biffStream, XlsBiffFormulaCell formulaCell, ushort xFormat)
        {
            switch (formulaCell.FormulaType)
            {
            case XlsBiffFormulaCell.FormulaValueType.Boolean:
                return(formulaCell.BooleanValue);

            case XlsBiffFormulaCell.FormulaValueType.Error:
                return(null);

            case XlsBiffFormulaCell.FormulaValueType.EmptyString:
                return(string.Empty);

            case XlsBiffFormulaCell.FormulaValueType.Number:
                return(TryConvertOADateTime(formulaCell.XNumValue, xFormat));

            case XlsBiffFormulaCell.FormulaValueType.String:
                return(TryGetFormulaString(biffStream));
            }

            // Bad data or new formula value type
            return(null);
        }
Exemple #3
0
        private bool TryGetFormulaValue(XlsBiffFormulaCell formulaCell, ushort xFormat, List <XlsBiffRecord> additionalRecords, out object result)
        {
            switch (formulaCell.FormulaType)
            {
            case XlsBiffFormulaCell.FormulaValueType.Boolean:
                result = formulaCell.BooleanValue;
                return(true);

            case XlsBiffFormulaCell.FormulaValueType.Error:
                result = null;
                return(true);

            case XlsBiffFormulaCell.FormulaValueType.EmptyString:
                result = string.Empty;
                return(true);

            case XlsBiffFormulaCell.FormulaValueType.Number:
                result = TryConvertOADateTime(formulaCell.XNumValue, xFormat);
                return(true);

            case XlsBiffFormulaCell.FormulaValueType.String when additionalRecords.Count == 0:
                result = null;

                // Request additional records.
                return(false);

            case XlsBiffFormulaCell.FormulaValueType.String:
                BIFFRECORDTYPE recId;

                if (additionalRecords.Count == 1)
                {
                    recId = additionalRecords[0].Id;
                    if (recId == BIFFRECORDTYPE.SHAREDFMLA)
                    {
                        result = null;

                        // Request additional records.
                        return(false);
                    }

                    if (recId == BIFFRECORDTYPE.STRING)
                    {
                        var stringRecord = (XlsBiffFormulaString)additionalRecords[0];
                        result = stringRecord.GetValue(Encoding);
                        return(true);
                    }
                }

                // The old implementation would throw an IndexOutOfRangeException if the record isn't
                // a SHAREDFMLA or STRING.
                if (additionalRecords.Count > 1)
                {
                    recId = additionalRecords[1].Id;
                    if (recId == BIFFRECORDTYPE.STRING)
                    {
                        var stringRecord = (XlsBiffFormulaString)additionalRecords[1];
                        result = stringRecord.GetValue(Encoding);
                        return(true);
                    }
                }

                // Bad data - could not find a string following the formula
                break;
            }

            // Bad data or new formula value type
            result = null;
            return(true);
        }