From 6f713d4aac4dd89a56916f165f83116b45065b68 Mon Sep 17 00:00:00 2001
From: Yegor Kozlov
Date: Tue, 11 Nov 2008 11:43:20 +0000
Subject: bug# 45973: added factory method for FormulaEvaluator, also fixed
unpaired tags in javadocs
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@713021 13f79535-47bb-0310-9956-ffa450edef68
---
src/documentation/content/xdocs/changes.xml | 1 +
.../content/xdocs/spreadsheet/eval.xml | 177 ++++++++++-----------
src/documentation/content/xdocs/status.xml | 1 +
3 files changed, 86 insertions(+), 93 deletions(-)
(limited to 'src/documentation')
diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml
index 42497beb12..4b1b5566d0 100644
--- a/src/documentation/content/xdocs/changes.xml
+++ b/src/documentation/content/xdocs/changes.xml
@@ -37,6 +37,7 @@
+ 45973 - added CreationHelper.createFormulaEvaluator(), implemeted both for HSSF and XSSF46182 - fixed Slideshow.readPictures() to skip pictures with invalid headers46137 - Handle odd files with a ContinueRecord after EOFRecordFixed problem with linking shared formulas when ranges overlap
diff --git a/src/documentation/content/xdocs/spreadsheet/eval.xml b/src/documentation/content/xdocs/spreadsheet/eval.xml
index 7f31017edd..a0c9896ca0 100644
--- a/src/documentation/content/xdocs/spreadsheet/eval.xml
+++ b/src/documentation/content/xdocs/spreadsheet/eval.xml
@@ -32,10 +32,7 @@
formulas in Excels sheets read-in, or created in POI. This document explains
how to use the API to evaluate your formulas.
- In versions of POI before 3.0.3, this code lived in the
- scratchpad area of the POI SVN repository. If using an such an older
- version of POI, ensure that you have the scratchpad jar or the
- scratchpad build area in your classpath before experimenting with this
+ .xlsx format is suported since POI 3.5, make sure yoy upgraded to that version before experimenting with this
code. Users of all versions of POI may wish to make use of a recent
SVN checkout, as new functions are currently being added fairly frequently.
@@ -47,7 +44,8 @@
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 Formula
- evaluation development guide for details.
+ evaluation development guide and javadocs
+ for details.
Both HSSFWorkbook and XSSFWorkbook are supported, so you can
evaluate formulas on both .xls and .xlsx files.
Note that user-defined functions are not supported, and is not likely to done
@@ -66,38 +64,37 @@
without affecting the cell
+
Thus using the retrieved value (of type
FormulaEvaluator.CellValue - a nested class) returned
by FormulaEvaluator is similar to using a Cell object
@@ -117,39 +114,38 @@ switch (cellValue.getCellType()) {
formula remains in the cell, just with a new value
The return of the function is the type of the
formula result, such as Cell.CELL_TYPE_BOOLEAN
-
Re-calculating all formulas in a Workbook
+
FileInputStream fis = new FileInputStream("/somepath/test.xls");
-Workbook wb = new HSSFWorkbook(fis);
+Workbook wb = new HSSFWorkbook(fis); //or new XSSFWorkbook("/somepath/test.xls")
+FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
for(int sheetNum = 0; sheetNum < wb.getNumberOfSheets(); sheetNum++) {
- Sheet sheet = wb.getSheetAt(sheetNum);
- FormulaEvaluator evaluator = new FormulaEvaluator(sheet, wb);
-
- for(Iterator rit = sheet.rowIterator(); rit.hasNext();) {
- Row r = (Row)rit.next();
- evaluator.setCurrentRow(r);
-
- for(Iterator cit = r.cellIterator(); cit.hasNext();) {
- Cell c = (Cell)cit.next();
- if(c.getCellType() == Cell.CELL_TYPE_FORMULA) {
- evaluator.evaluateFormulaCell(c);
- }
- }
- }
+ Sheet sheet = wb.getSheetAt(sheetNum);
+ for(Row r : sheet) {
+ for(Cell c : r) {
+ if(c.getCellType() == Cell.CELL_TYPE_FORMULA) {
+ evaluator.evaluateFormulaCell(c);
+ }
+ }
+ }
}
-wb.write(new FileOutputStream("/somepath/changed.xls"));
-
+
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index baec54a045..00321db745 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
+ 45973 - added CreationHelper.createFormulaEvaluator(), implemeted both for HSSF and XSSF46182 - fixed Slideshow.readPictures() to skip pictures with invalid headers46137 - Handle odd files with a ContinueRecord after EOFRecordFixed problem with linking shared formulas when ranges overlap
--
cgit v1.2.3