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

Free Support Forum - aspose.com

Recalculation formulas

Hi. Our workflow with book supposed, that context could have several states. Formulas should be calculated depended of context state.


So i have found that cell, that was calculated in previous state will not recalculated, when i change context state.

Can you please suggest some “invalidate” method for force recalc?

public class AsposeTest {

private boolean locked;

public boolean isLocked() {
return locked;
}

public void setLocked(boolean locked) {
this.locked = locked;
}

public class Resolver implements ICustomFunction {

@Override
public Object calculateCustomFunction(String s, ArrayList arrayList, ArrayList arrayList2) {
if (AsposeTest.this.isLocked()) {
return “is locked”;
} else {
return “unlocked”;
}
}
}

@Test
public void testRecalculationCell() {
try {
Workbook wb = new Workbook();
Cells cells = wb.getWorksheets().get(0).getCells();

Resolver resolver = new Resolver();

Cell cell = cells.get(“A3”);

cell.setFormula("=MYCUSTOM()");

setLocked(true);
cell.calculate(false, resolver);
assertEquals(“is locked”, cell.getDisplayStringValue());

setLocked(false);
cell.calculate(false, resolver);
assertEquals(“unlocked”, cell.getDisplayStringValue());

} catch (Exception e) {
e.printStackTrace();
assertNull(e);
}
}
}


Best regards. Alexey

Hi Alexey,

Thanks for your posting and using Aspose.Cells.

We were able to observe this issue. Once, the formula is calculated, it is not calculated again. There should be some method to invalidate the formula to force re-calculation of the formula.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update/advice for you, we will let you know asap.

This issue has been logged as CELLSJAVA-40769.

The issues you have found earlier (filed as CELLSJAVA-40769) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Shakeel Faiz. Can you provide name of method for invalidate recalculation cache?

Hi,

Thanks for using Aspose.Cells.

You do not need to invalidate recalculation cache explicitly. CalculateFormula() methods for Workbook/Worksheet/Cell will force all formulas to be recalculated automatically. One exception is Workbook.CalculateFormula() method with WorkbookSettings.CreateCalcChain as true(default it is false). When WorkbookSettings.CreateCalcChain is true, Workbook.CalculateFormula() will only calculate those formulas that have not been calculated or need to be recalculated because their precedents have been changed.