Error in CalculateFormula()


#1

Thanks for previous replies. I'm trying to execute the code below and it says error in executing the firmula in cell47.

double D27 = double.Parse(TextBox1.Text);

double C33 = double.Parse(TextBox2.Text);

double C34 = double.Parse(TextBox3.Text);

double C41 = double.Parse(TextBox4.Text);

double C42 = double.Parse(TextBox5.Text);

Excel ex = new Excel();

ex.Open(path,FileFormatType.Excel97);

Worksheet sh = ex.Worksheets["DataSheet"];

Cells cells = sh.Cells;

cells["D27"].PutValue(D27);

cells["C33"].PutValue(C33);

cells["C34"].PutValue(C34);

cells["C41"].PutValue(C41);

cells["C42"].PutValue(C42);

ex.CalculateFormula();

Label2.Text = cells["C48"].Value.ToString();

If I put the statement

ex.Save(path,FileFormatType.Excel97);

before

ex.CalculateFormula();

Label2.Text = cells["C48"].Value.ToString();

these lines than it works fine but the in that case I can not read the data from cell C48 and put in the Label2. Please help me.


#2

After calling Save method, data is reset. So if you want to retrieve data in cells, please read them before calling Save method.