]> source.dussan.org Git - poi.git/commitdiff
Update documentation, and add section on whole-workbook recalculating
authorNick Burch <nick@apache.org>
Wed, 9 Jan 2008 20:37:06 +0000 (20:37 +0000)
committerNick Burch <nick@apache.org>
Wed, 9 Jan 2008 20:37:06 +0000 (20:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@610553 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/hssf/eval.xml

index d697eb082bcede2e093273276f5a8640e30ef7d0..197391b381e785153dde0247eef33116b557ece5 100644 (file)
                                formulas in Excels sheets read-in, or created in POI. This document explains
                                how to use the API to evaluate your formulas. 
                        </p>
-                       <note> This code currently lives the scratchpad area of the POI CVS repository. 
+                       <note> This code currently lives the scratchpad area of the POI SVN repository. 
                                Ensure that you have the scratchpad jar or the scratchpad build area in your
-                               classpath before experimenting with this code.
+                               classpath before experimenting with this code. You are advised
+                               to make use of a recent SVN checkout, as new functions are
+                               being supported fairly frequently.
                        </note>
                </section>
                <section><title>Status</title>
+                       <anchor id="Status"/>
                        <p>     The code currently provides implementations for all the arithmatic operators.
-                               It also provides implementations for approx. 20 built in 
+                               It also provides implementations for approx. 100 built in 
                                functions in Excel. The framework however makes is easy to add 
                                implementation of new functions. See the <link href="eval-devguide.html"> Formula
                                evaluation development guide</link> for details. </p>
@@ -53,6 +56,7 @@
                        </p>
                        <p>There are two ways in which you can use the HSSFFormulaEvalutator API.</p>
                        <section><title>Using HSSFFormulaEvaluator.<strong>evaluate</strong>(HSSFCell cell)</title>
+                               <anchor id="Evaluate"/>
                                <source>
 FileInputStream fis = new FileInputStream("c:/temp/test.xls");
 HSSFWorkbook wb = new HSSFWorkbook(fis);
@@ -96,8 +100,12 @@ switch (cellValue.getCellType()) {
                                </p>
                                
                        </section>
-                       <section><title>Using HSSFFormulaEvaluator.<strong>evaluateInCell</strong>(HSSFCell cell)
-                               </title>
+                       <section><title>Using HSSFFormulaEvaluator.<strong>evaluateInCell</strong>(HSSFCell cell)</title>
+                               <anchor id="EvaluateInCell"/>
+                               <p><strong>evaluateInCell</strong>(HSSFCell cell) will check to
+                               see if the supplied cell is a formula cell. If it isn't,
+                               then no changes will be made to it. If it is, then the
+                               formula is evaluated, and the new value saved into the cell.</p>
                                <source>
 FileInputStream fis = new FileInputStream("/somepath/test.xls");
 HSSFWorkbook wb = new HSSFWorkbook(fis);
@@ -132,12 +140,36 @@ if (cell!=null) {
                    break;
        }
 }
-                                       </source>
+                               </source>
+                       </section>
+                       <section><title>Re-calculating all formulas in a Workbook</title>
+                               <anchor id="EvaluateAll"/>
+                               <source>
+FileInputStream fis = new FileInputStream("/somepath/test.xls");
+HSSFWorkbook wb = new HSSFWorkbook(fis);
+for(int sheetNum = 0; sheetNum &lt; wb.getNumberOfSheets(); sheetNum++) {
+       HSSFSheet sheet = wb.getSheetAt(sheetNum);
+       HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
 
-                               </section>
+       for(Iterator rit = s.rowIterator(); rit.hasNext();) {
+               HSSFRow r = (HSSFRow)rit.next();
+               evaluator.setCurrentRow(r);
+
+               for(Iterator cit = r.cellIterator(); cit.hasNext();) {
+                       HSSFCell c = (HSSFCell)cit.next();
+                       if(c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
+                               evaluator.evaluateInCell(c);
+                       }
+               }
+       }
+}
+wb.write(new FileOutputStream("/somepath/changed.xls"));
+                               </source>
+                       </section>
                </section>
                
                <section><title>Performance Notes</title>
+                       <anchor id="Performance"/>
                        <ul>
                                <li>Generally you should have to create only one HSSFFormulaEvaluator 
                                        instance per sheet, but there really is no overhead in creating