title: Apache POI formula cell duplication very slow
body: <p>I'm generating an excel file using Apache POI 3.8 , and have the need to replicate some existing row n° times.</p>
  
  <p>This because I have some complex formula which I use as a template to create new lines, replacing cell indexes with regexps.</p>
  
  <p>The problem is that performance are awful, it takes 2h to generate some 4000 rows.</p>
  
  <p>I've pinpointed the problem to be not in the regexp part, as I initially thought, but in the duplication of formula cells.</p>
  
  <p>I actually use this to replicate formula cells:</p>
  
  <pre><code>case Cell.CELL_TYPE_FORMULA:
      newCell.setCellType(oldCell.getCellType());
      newCell.setCellFormula(oldCell.getCellFormula());
      break; 
  </code></pre>
  
  <p>If I copy the formula as text like this:</p>
  
  <pre><code>case Cell.CELL_TYPE_FORMULA:
      newCell.setCellType(Cell.CELL_TYPE_STRING);
      newCell.setCellValue("="+oldCell.getCellFormula());
      break;
  </code></pre>
  
  <p>it's instead pretty fast, even with my regexp in place.</p>
  
  <p>Anyway, this is an imperfect solution, because the formula has english keywords (ie IF()), when I need to write in italian format.</p>
  
  <p>More, cells with formula inserted like that need to be forcefully re-evaluated in excel with something like "replace all -> '=' with '='".</p>
  
  <p>The problem seems to rely in the setCellFormula(), because of the HSSFFormulaParser.parse().</p>
  
  <p>What's strange, is that parsing time seems to grow exponentially:</p>
  
  <pre><code>100 rows -&gt;  6785ms
  200 rows -&gt; 23933ms
  300 rows -&gt; 51388ms
  400 rows -&gt; 88586ms
  </code></pre>
  
  <p>What it seems, is that each time I copy a formula, the POI library re-evaluates or re-parses or re-something all preceding rows.</p>
  
  <p>Do anyone know how can solve this problem?
  Thanks in advance.</p>