Esempio n. 1
0
        public static object Calculate(this ExcelWorksheet worksheet, string Formula, ExcelCalculationOption options)
        {
            try
            {
                worksheet.CheckSheetType();
                if (string.IsNullOrEmpty(Formula.Trim()))
                {
                    return(null);
                }
                Init(worksheet.Workbook);
                var parser = worksheet.Workbook.FormulaParser;
                parser.InitNewCalc();
                if (Formula[0] == '=')
                {
                    Formula = Formula.Substring(1);                    //Remove any starting equal sign
                }
                var dc = DependencyChainFactory.Create(worksheet, Formula, options);
                var f  = dc.list[0];
                dc.CalcOrder.RemoveAt(dc.CalcOrder.Count - 1);

                CalcChain(worksheet.Workbook, parser, dc);

                return(parser.ParseCell(f.Tokens, worksheet.Name, -1, -1));
            }
            catch (Exception ex)
            {
                return(new ExcelErrorValueException(ex.Message, ExcelErrorValue.Create(eErrorType.Value)));
            }
        }