title: Apache POI evaluate formula
body: <p>I have some formulas in cells of my sheet, and I want to evaluate them after I insert some values. Ex :</p>
  
  <p>My formula is <code>=SUM(B1,B2)</code></p>
  
  <p>Before values insertion <code>B1</code> value was <code>1</code>, and <code>B2</code> value was <code>3</code>, and the formula result is <code>4</code></p>
  
  <p>After insertion of values now B1 has value <code>5</code>, and B2 has value <code>2</code> but the formula still produces <code>4</code>, how can I evaluate/trigger this to be calculated?</p>
  
  <p>Naturally after I hit the return button on the formula cell the new value <code>7</code> is calculated, is there a way to trigger this without manual interaction?</p>
  
  <p>I'm using excel 2007 so <code>XSSFWorkbook</code></p>
  
  <p><strong>EDIT/UPDATE :</strong></p>
  
  <p>I've used Gabors solution before he posted it but I'm using it as a reference, here is what happens :</p>
  
  <pre><code> Exception in thread "main" java.lang.NoSuchMethodError: org.apache.poi.ss.formula.WorkbookEvaluator.&lt;init&gt;(Lorg/apache/poi/ss/formula/EvaluationWorkbook;Lorg/apache/poi/ss/formula/IStabilityClassifier;Lorg/apache/poi/hssf/record/formula/udf/UDFFinder;)V
          at org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator.&lt;init&gt;(XSSFFormulaEvaluator.java:64)
          at org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator.&lt;init&gt;(XSSFFormulaEvaluator.java:51)
  ...............
  ...............
  </code></pre>
  
  <p>Here is a part of the relevant code :</p>
  
  <pre><code>public XSSFFormulaEvaluator getEvaluator(){
          if(evaluator == null){
              evaluator = new XSSFFormulaEvaluator(wb);
          }
          return evaluator;
      }
  </code></pre>
  
  <p>actually invoking evaluator :</p>
  
  <pre><code>//where index is int, and mycell is int
  row = (XSSFRow) sheet.getRow(index);
  cell = row.createCell(mycell);
  getEvaluator().evaluateFormulaCell(cell);
  </code></pre>
  
  <p>I'm looking for someone used this and was successful, not those who google solution without really trying it, I've been googling a lot to say at least.</p>
  
  <p>Per Gagravar suggestion I do have 2 POIs on my classpath :</p>
  
  <pre><code>        &lt;dependency&gt;
          &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
          &lt;artifactId&gt;poi&lt;/artifactId&gt;
          &lt;version&gt;3.8-beta1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
          &lt;artifactId&gt;poi-ooxml&lt;/artifactId&gt;
          &lt;version&gt;3.7&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>I though I need 3.7 version for XSSF workbooks etc.</p>
  
  <p><strong>SOLUTION :</strong></p>
  
  <pre><code>&lt;dependency&gt;
              &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
              &lt;artifactId&gt;poi&lt;/artifactId&gt;
              &lt;version&gt;3.8-beta2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
              &lt;artifactId&gt;poi-ooxml&lt;/artifactId&gt;
              &lt;version&gt;3.8-beta2&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>