public override CompileResult Compile() { try { var function = _parsingContext.Configuration.FunctionRepository.GetFunction(ExpressionString); var compiler = _functionCompilerFactory.Create(function); var result = compiler.Compile(HasChildren ? Children : Enumerable.Empty <Expression>(), _parsingContext); if (_isNegated) { if (!result.IsNumeric) { throw new ExcelErrorValueException(eErrorType.Value); } else { return(new CompileResult(result.ResultNumeric * -1, result.DataType)); } } return(result); } catch (ExcelErrorValueException e) { return(new CompileResult(e.ErrorValue, DataType.ExcelError)); } }
public override CompileResult Compile() { var function = _parsingContext.Configuration.FunctionRepository.GetFunction(ExpressionString); var compiler = _functionCompilerFactory.Create(function); return(compiler.Compile(Children, _parsingContext)); }
public override CompileResult Compile() { try { var funcName = ExpressionString; // older versions of Excel (pre 2007) adds "_xlfn." in front of some function names for compatibility reasons. // EPPlus implements most of these functions, so we just remove this. if (funcName.StartsWith("_xlfn.")) { funcName = funcName.Replace("_xlfn.", string.Empty); } var function = _parsingContext.Configuration.FunctionRepository.GetFunction(funcName); if (function == null) { // Handle unrecognized func name var pipeline = new FunctionsPipeline(_parsingContext, Children); function = pipeline.FindFunction(funcName); if (function == null) { if (_parsingContext.Debug) { _parsingContext.Configuration.Logger.Log(_parsingContext, string.Format("'{0}' is not a supported function", funcName)); } return(new CompileResult(ExcelErrorValue.Create(eErrorType.Name), DataType.ExcelError)); } } if (_parsingContext.Debug) { _parsingContext.Configuration.Logger.LogFunction(funcName); } var compiler = _functionCompilerFactory.Create(function); var result = compiler.Compile(HasChildren ? Children : Enumerable.Empty <Expression>()); if (_isNegated) { if (!result.IsNumeric) { if (_parsingContext.Debug) { var msg = string.Format("Trying to negate a non-numeric value ({0}) in function '{1}'", result.Result, funcName); _parsingContext.Configuration.Logger.Log(_parsingContext, msg); } return(new CompileResult(ExcelErrorValue.Create(eErrorType.Value), DataType.ExcelError)); } return(new CompileResult(result.ResultNumeric * -1, result.DataType)); } return(result); } catch (ExcelErrorValueException e) { if (_parsingContext.Debug) { _parsingContext.Configuration.Logger.Log(_parsingContext, e); } return(new CompileResult(e.ErrorValue, DataType.ExcelError)); } }
public void CreateHandlesErrorFunctionCompiler() { var functionRepository = FunctionRepository.Create(); var functionCompilerFactory = new FunctionCompilerFactory(functionRepository, _context); var function = new IsError(); var functionCompiler = functionCompilerFactory.Create(function); Assert.IsInstanceOfType(functionCompiler, typeof(ErrorHandlingFunctionCompiler)); }
public void CreateHandlesLookupFunctionCompiler() { var functionRepository = FunctionRepository.Create(); var functionCompilerFactory = new FunctionCompilerFactory(functionRepository, _context); var function = new Column(); var functionCompiler = functionCompilerFactory.Create(function); Assert.IsInstanceOfType(functionCompiler, typeof(LookupFunctionCompiler)); }
public void CreateHandlesSpecialIfNaCompiler() { var functionRepository = FunctionRepository.Create(); var functionCompilerFactory = new FunctionCompilerFactory(functionRepository, _context); var function = new IfNa(); var functionCompiler = functionCompilerFactory.Create(function); Assert.IsInstanceOfType(functionCompiler, typeof(IfNaFunctionCompiler)); }
public void CreateHandlesStandardFunctionCompiler() { var functionRepository = FunctionRepository.Create(); var functionCompilerFactory = new FunctionCompilerFactory(functionRepository, _context); var function = new Sum(); var functionCompiler = functionCompilerFactory.Create(function); Assert.IsInstanceOfType(functionCompiler, typeof(DefaultCompiler)); }
public void CreateHandlesCustomFunctionCompiler() { var functionRepository = FunctionRepository.Create(); functionRepository.LoadModule(new TestFunctionModule(_context)); var functionCompilerFactory = new FunctionCompilerFactory(functionRepository, _context); var function = new MyFunction(); var functionCompiler = functionCompilerFactory.Create(function); Assert.IsInstanceOfType(functionCompiler, typeof(MyFunctionCompiler)); }
public override CompileResult Compile() { try { var function = _parsingContext.Configuration.FunctionRepository.GetFunction(ExpressionString); if (function == null) { if (_parsingContext.Debug) { _parsingContext.Configuration.Logger.Log(_parsingContext, string.Format("'{0}' is not a supported function", ExpressionString)); } return(new CompileResult(ExcelErrorValue.Create(eErrorType.Name), DataType.ExcelError)); } if (_parsingContext.Debug) { _parsingContext.Configuration.Logger.LogFunction(ExpressionString); } var compiler = _functionCompilerFactory.Create(function); var result = compiler.Compile(HasChildren ? Children : Enumerable.Empty <Expression>(), _parsingContext); if (_isNegated) { if (!result.IsNumeric) { if (_parsingContext.Debug) { var msg = string.Format("Trying to negate a non-numeric value ({0}) in function '{1}'", result.Result, ExpressionString); _parsingContext.Configuration.Logger.Log(_parsingContext, msg); } return(new CompileResult(ExcelErrorValue.Create(eErrorType.Value), DataType.ExcelError)); } return(new CompileResult(result.ResultNumeric * -1, result.DataType)); } return(result); } catch (ExcelErrorValueException e) { if (_parsingContext.Debug) { _parsingContext.Configuration.Logger.Log(_parsingContext, e); } return(new CompileResult(e.ErrorValue, DataType.ExcelError)); } }
public override bool Handle(string funcName, IEnumerable <Expression> children, ParsingContext context, out ExcelFunction function) { function = null; if (funcName.Contains(":OFFSET")) { var functionCompilerFactory = new FunctionCompilerFactory(context.Configuration.FunctionRepository, context); var startRange = funcName.Split(':')[0]; var c = context.Scopes.Current; var resultRange = context.ExcelDataProvider.GetRange(c.Address.Worksheet, c.Address.FromRow, c.Address.FromCol, startRange); var rangeOffset = new RangeOffset { StartRange = resultRange }; var compiler = functionCompilerFactory.Create(new Offset()); children.First().Children.First().IgnoreCircularReference = true; var compileResult = compiler.Compile(children); rangeOffset.EndRange = compileResult.Result as ExcelDataProvider.IRangeInfo; function = rangeOffset; return(true); } return(false); }