Named Formulas in Syncfusion.Calculate

In Syncfusion.Calculate, I would like to be able to add named formulas with formulas that reference a grid/datatable and potentially other named formulas. For example...

engine.AddNamedRange("myName", "SUM(grid1!A1:A10) + myOtherName")

I could not find an example of the above using Calculate. Can someone provide an example?


2 Replies

JG James Grimes February 23, 2008 04:03 AM UTC

>In Syncfusion.Calculate, I would like to be able to add named formulas with formulas that reference a grid/datatable and potentially other named formulas. For example...

engine.AddNamedRange("myName", "SUM(grid1!A1:A10) + myOtherName")

I could not find an example of the above using Calculate. Can someone provide an example?



I am currently using the following code...

##### CODE #####

private CalcEngine engine;
private DataTable dt;

private void button1_Click(object sender, EventArgs e)
{
this.dt = GetDataTable();
this.dataGrid1.DataSource = this.dt;

CalcEngine.ResetSheetFamilyID();
engine = new CalcEngine(this.dataGrid1);

engine.AddNamedRange("TestVal", "SUM(C1:C3)");

engine.UseDependencies = true;
engine.RecalculateRange(RangeInfo.Cells(1, 1, dt.Rows.Count,
dt.Columns.Count), this.dataGrid1);

label1.Text = engine.ParseAndComputeFormula("TestVal");
}

################

The value in label1.Text is correct. The ParseAndComputeFormula works fine. However, if I have a cell in dataGrid1 that contains the formula "=TestVal", an object reference error is thrown.

What am I missing?



AN Anonymous March 14, 2008 02:53 PM UTC

Here is our DataGrid sample modified to show

engine.AddNamedRange("TestVal", "SUM(C1:C3)"); //<<<<<<< added

when you type testval into the Textbox and also when you type =testval cell A1.

The only thing I see different than the code you listed is that

engine.RegisterGridAsSheet("SingleGrid", this.dataGrid1, sheetfamilyID);

is in the sample and not in the code you showed.



CS.zip

Loader.
Up arrow icon