Coder Social home page Coder Social logo

stephensmitchell-forks / calculation-engine-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from syncfusionexamples/calculation-engine-example

0.0 1.0 0.0 6 KB

This example demonstrates to perform a formula calculation using Calculation Engine.

C# 100.00%

calculation-engine-example's Introduction

Calculate any formulas and built-in functions using Calculation Engine.

About the sample

This example will explain how to parse and compute the formulas and expressions using CalcEngine. Also, you can set and retrive the values in row and column index using ICalcData.

The below code explain how to create a class for set and retrive the values in row and column index using ICalcData.

public class CalcData : ICalcData
{
    public event ValueChangedEventHandler ValueChanged;

    Dictionary<string, object> values = new Dictionary<string, object>();
    public object GetValueRowCol(int row, int col)
    {
        object value = null;
        var key = RangeInfo.GetAlphaLabel(col) + row;
        this.values.TryGetValue(key, out value);
        return value;
    }

    public void SetValueRowCol(object value, int row, int col)
    {
        var key = RangeInfo.GetAlphaLabel(col) + row;
        if (!values.ContainsKey(key))
            values.Add(key, value);
        else if (values.ContainsKey(key) && values[key] != value)
            values[key] = value;
    }

    public void WireParentObject()
    {
    }

    private void OnValueChanged(int row, int col, string value)
    {
        if (ValueChanged != null)
            ValueChanged(this, new ValueChangedEventArgs(row, col, value));
    }
}

The below code will explain how to set the data value of a specified row and column index.

CalcData calcData = new CalcData();
CalcEngine engine = new CalcEngine(calcData);

// To set the data value of a specified row and column.
calcData.SetValueRowCol(90, 1, 1);
calcData.SetValueRowCol(50, 1, 2);

Now calculate using built-in functions with cell reference of stored values,

 // Calculate the built in function based on cell reference.
string formula = "SUM(A1, B1)";
string result = engine.ParseAndComputeFormula(formula);

Also we can parse and compute the expressions and built-in functions using Calculation engine.

//Computing Expressions,
string formula1 = "(5+25) *2";
string result1 = engine.ParseAndComputeFormula(formula1);

//Computing In-Built formulas,
string formula2 = "AVG(4,5,6)";
string result2 = engine.ParseAndComputeFormula(formula2);

The output of parse and compute expressions and formulas using Calculation Engine,

Parse and compute expressions and formulas using Calculation Engine

calculation-engine-example's People

Contributors

ganesanvelusamy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.