Using the attached template and the sample code below, I get this output:
Before calculate:
Retail_Pipeline!C91 formula: =C43C56C66C81
Retail_Pipeline!C43 value: 773.27
Retail_Pipeline!C91 value: 1,046.24
After set C43 to 0 and calculateFormula()
Retail_Pipeline!C91 formula: =C43C56C66C81
Retail_Pipeline!C43 value: -
Retail_Pipeline!C91 value: 1,046.24
Note that the last line should show the value “0”. But, if you comment out the middle “calculateFormula()” call, it works!
We need to set, calculate, and read lots of values in our application, of course.
Thanks for your help!
import java.io.IOException;
import com.aspose.cells.Cell;
import com.aspose.cells.Workbook;
public class AsposeTest2 {
public static void main(String[] args) {
Workbook simWorkbook = new Workbook();
try {
simWorkbook.open("/Users/brandon/Documents/sim.xls");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Cell simCellC43 = simWorkbook.getWorksheets().getSheet(“Retail_Pipeline”).getCells().getCell(“C43”);
Cell simCellC91 = simWorkbook.getWorksheets().getSheet(“Retail_Pipeline”).getCells().getCell(“C91”);
System.out.println(“Before calculate:”);
System.out.println("Retail_Pipeline!C91 formula: " + simCellC91.getFormula()); // =C43C56C66C81
System.out.println("Retail_Pipeline!C43 value: " + simCellC43.getStringValue()); // 773.27
System.out.println("Retail_Pipeline!C91 value: " + simCellC91.getStringValue()); // 1,046.24
// comment out the next line, and it works!
simWorkbook.calculateFormula();
System.out.println(“After set C43 to 0 and calculateFormula()”);
simCellC43.setValue(0);
simWorkbook.calculateFormula();
System.out.println("Retail_Pipeline!C91 formula: " + simCellC91.getFormula()); // =C43C56C66C81
System.out.println("Retail_Pipeline!C43 value: " + simCellC43.getStringValue()); // -
System.out.println("Retail_Pipeline!C91 value: " + simCellC91.getStringValue()); // ERROR: 1,046.24 – should be 0!
}