We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Automatically calculating formulas when dependents change

Do formulas no longer recalculate when a dependency of a formula changes?

        var workbook = new Workbook();
        workbook.Settings.CalcMode = CalcModeType.Automatic;
        workbook.Settings.CreateCalcChain = true;

        workbook.Worksheets[0].Cells["B1"].Formula = "=5+A1";
        workbook.Worksheets[0].Cells["A1"].Value = 5;
        var value = workbook.Worksheets[0].Cells["B1"].Value;

notice the value of B1 doesn’t change until I call worrkbook.CalculateFormula(false); first.

I thought this used to work automatically. Does this mean every time I write a value, I have to recalculate the entire workbook? That doesn’t seem very efficient.


Yes, you need to call Workbook.CalculateFormula() method before retrieving the calculated value(s) from the cells. This is efficient. Since you have created the calculation chain, so after editing different source cells, when you call Workbook.CalculateFormula(), only those formula will be calculated whose source cells data are edited and not all formulas or irrelevant formulas would be calculated. Even you call this method again and again, the time cost will be much less. It would be best, you call Workbook.CalculateFormula after you have edited all your desired cells data and only once.