Use Variable in CalculateFormula

Hi


I want to use variable in CalculateFormaula Method. Something like this:

int num1 = 1;
int num2 = 2;
int num3 = 3;
_etcResultWorksheet.Cells[0, 0].Formula = “Average(num1,num2,num3)”;
_etcResultWorkbook.CalculateFormula();
var x = _etcResultWorksheet.Cells[0, 0].Value.ToString();

How i can do it?

Hi,


You may try as following for your reference, see the line of code in bold.

Sample code:

Workbook _etcResultWorkbook = new Workbook();

Worksheet _etcResultWorksheet = _etcResultWorkbook.Worksheets[0];


int num1 = 1;
int num2 = 2;
int num3 = 3;
_etcResultWorksheet.Cells[0, 0].Formula = “Average(” + num1 + “,” + num2 + “,” + num3 + “)”;
_etcResultWorkbook.CalculateFormula();
var x = _etcResultWorksheet.Cells[0, 0].Value.ToString(); //2 - OK

Thank you.