Free Support Forum - aspose.com

Excel exceution of prebuilt calculations

I working with a licensed aspose.cells. I tried a simple injection and evaluation test using a prebuilt excel 2003 spreadsheet (.xls) containing formulas that depend on input values. I wanted to be able to programmatically write the input values into the excel doc then read off the calculated values:

Example

In the document Test.xls in cell A2 is a formula: =if(A1>0;"true";"false"). I want to be able to set the value into A1 and then read the evaluated value from cell A2 which should be true. I entered, however it returns "false" as if no value in A1 has been set. Perhaps I am missing something - is this possible using Aspose.Cells ?

Heres my code
int inputValue = System.Convert.ToInt32(txtInputValue.Text);
Workbook wb = new Workbook();
wb.LoadData("c:\Test.xls");
Worksheet ws = wb.Worksheets["Sheet1"];
ws.Cells["A1"].PutValue(inputValue);
ltlOutput.Text = ws.Cells["A2"].Value.ToString();

Thanks for your help.

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Please use Workbook.CalculateFormula() method before retrieving the updated value from the cell (to evaluate the formulas). Please see the following updated code:

int inputValue = System.Convert.ToInt32(txtInputValue.Text);

Workbook wb = new Workbook();

wb.LoadData("c:\Test.xls");

Worksheet ws = wb.Worksheets["Sheet1"];

ws.Cells["A1"].PutValue(inputValue);

wb.CalculateFormula();

ltlOutput.Text = ws.Cells["A2"].Value.ToString();

Thank You & Best Regards,