You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2008/08/09 21:47:40 UTC
svn commit: r684321 [1/2] - in /poi/trunk/src:
java/org/apache/poi/hssf/model/ java/org/apache/poi/hssf/usermodel/
testcases/org/apache/poi/hssf/model/
testcases/org/apache/poi/hssf/record/formula/eval/
testcases/org/apache/poi/hssf/record/formula/func...
Author: josh
Date: Sat Aug 9 12:47:39 2008
New Revision: 684321
URL: http://svn.apache.org/viewvc?rev=684321&view=rev
Log:
added getRowIndex() to HSSFCell, deprecated HSSFFormulaEvaluator.setCurrentRow()
Modified:
poi/trunk/src/java/org/apache/poi/hssf/model/FormulaParser.java
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestPercentEval.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestDate.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
Modified: poi/trunk/src/java/org/apache/poi/hssf/model/FormulaParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/model/FormulaParser.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/model/FormulaParser.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/model/FormulaParser.java Sat Aug 9 12:47:39 2008
@@ -25,6 +25,7 @@
import org.apache.poi.hssf.record.formula.*;
import org.apache.poi.hssf.record.formula.function.FunctionMetadata;
import org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
@@ -112,7 +113,7 @@
}
public static Ptg[] parse(String formula, HSSFWorkbook workbook, int formulaType) {
- FormulaParser fp = new FormulaParser(formula, workbook);
+ FormulaParser fp = HSSFFormulaEvaluator.getUnderlyingParser(workbook, formula);
fp.parse();
return fp.getRPNPtg(formulaType);
}
@@ -816,7 +817,7 @@
/**
* API call to execute the parsing of the formula
- * @deprecated use Ptg[] FormulaParser.parse(String, HSSFWorkbook) directly
+ * @deprecated use {@link #parse(String, HSSFWorkbook)} directly
*/
public void parse() {
pointer=0;
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java Sat Aug 9 12:47:39 2008
@@ -48,6 +48,7 @@
import org.apache.poi.hssf.record.UnicodeString;
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
/**
* High level representation of a cell in a row of a spreadsheet.
@@ -69,59 +70,24 @@
*/
public final class HSSFCell {
- /**
- * Numeric Cell type (0)
- * @see #setCellType(int)
- * @see #getCellType()
- */
-
- public final static int CELL_TYPE_NUMERIC = 0;
-
- /**
- * String Cell type (1)
- * @see #setCellType(int)
- * @see #getCellType()
- */
-
- public final static int CELL_TYPE_STRING = 1;
-
- /**
- * Formula Cell type (2)
- * @see #setCellType(int)
- * @see #getCellType()
- */
-
- public final static int CELL_TYPE_FORMULA = 2;
-
- /**
- * Blank Cell type (3)
- * @see #setCellType(int)
- * @see #getCellType()
- */
-
- public final static int CELL_TYPE_BLANK = 3;
-
- /**
- * Boolean Cell type (4)
- * @see #setCellType(int)
- * @see #getCellType()
- */
-
- public final static int CELL_TYPE_BOOLEAN = 4;
-
- /**
- * Error Cell type (5)
- * @see #setCellType(int)
- * @see #getCellType()
- */
-
- public final static int CELL_TYPE_ERROR = 5;
+ /** Numeric Cell type (0) @see #setCellType(int) @see #getCellType() */
+ public final static int CELL_TYPE_NUMERIC = 0;
+ /** String Cell type (1) @see #setCellType(int) @see #getCellType() */
+ public final static int CELL_TYPE_STRING = 1;
+ /** Formula Cell type (2) @see #setCellType(int) @see #getCellType() */
+ public final static int CELL_TYPE_FORMULA = 2;
+ /** Blank Cell type (3) @see #setCellType(int) @see #getCellType() */
+ public final static int CELL_TYPE_BLANK = 3;
+ /** Boolean Cell type (4) @see #setCellType(int) @see #getCellType() */
+ public final static int CELL_TYPE_BOOLEAN = 4;
+ /** Error Cell type (5) @see #setCellType(int) @see #getCellType() */
+ public final static int CELL_TYPE_ERROR = 5;
+
public final static short ENCODING_UNCHANGED = -1;
public final static short ENCODING_COMPRESSED_UNICODE = 0;
public final static short ENCODING_UTF_16 = 1;
private int cellType;
private HSSFRichTextString stringValue;
- private short encoding = ENCODING_UNCHANGED;
private HSSFWorkbook book;
private Sheet sheet;
private CellValueRecordInterface record;
@@ -191,9 +157,7 @@
* @param sheet - Sheet record of the sheet containing this cell
* @param cval - the Cell Value Record we wish to represent
*/
- protected HSSFCell(HSSFWorkbook book, Sheet sheet, int row,
- CellValueRecordInterface cval)
- {
+ protected HSSFCell(HSSFWorkbook book, Sheet sheet, CellValueRecordInterface cval) {
record = cval;
cellType = determineType(cval);
stringValue = null;
@@ -266,6 +230,12 @@
}
/**
+ * @return the (zero based) index of the row containing this cell
+ */
+ public int getRowIndex() {
+ return record.getRow();
+ }
+ /**
* Set the cell's number within the row (0 based).
* @param num short the cell number
* @deprecated Doesn't update the row's idea of what cell this is, use {@link HSSFRow#moveCell(HSSFCell, short)} instead
@@ -975,13 +945,13 @@
* Errors are displayed as #ERR<errIdx>
*/
public String toString() {
- switch (getCellType()) {
+ switch (getCellType()) {
case CELL_TYPE_BLANK:
return "";
case CELL_TYPE_BOOLEAN:
return getBooleanCellValue()?"TRUE":"FALSE";
case CELL_TYPE_ERROR:
- return "#ERR"+getErrorCellValue();
+ return ErrorEval.getText((( BoolErrRecord ) record).getErrorValue());
case CELL_TYPE_FORMULA:
return getCellFormula();
case CELL_TYPE_NUMERIC:
@@ -989,7 +959,7 @@
if (HSSFDateUtil.isCellDateFormatted(this)) {
DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
return sdf.format(getDateCellValue());
- }else {
+ } else {
return getNumericCellValue() + "";
}
case CELL_TYPE_STRING:
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java Sat Aug 9 12:47:39 2008
@@ -1,19 +1,19 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
package org.apache.poi.hssf.usermodel;
@@ -27,7 +27,6 @@
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.record.formula.Area3DPtg;
import org.apache.poi.hssf.record.formula.AreaPtg;
-import org.apache.poi.hssf.record.formula.AttrPtg;
import org.apache.poi.hssf.record.formula.BoolPtg;
import org.apache.poi.hssf.record.formula.ControlPtg;
import org.apache.poi.hssf.record.formula.IntPtg;
@@ -37,7 +36,6 @@
import org.apache.poi.hssf.record.formula.NameXPtg;
import org.apache.poi.hssf.record.formula.NumberPtg;
import org.apache.poi.hssf.record.formula.OperationPtg;
-import org.apache.poi.hssf.record.formula.ParenthesisPtg;
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.record.formula.Ref3DPtg;
import org.apache.poi.hssf.record.formula.RefPtg;
@@ -93,17 +91,20 @@
}
- protected HSSFRow row;
- protected HSSFSheet sheet;
- protected HSSFWorkbook workbook;
+ protected HSSFSheet _sheet;
+ protected HSSFWorkbook _workbook;
public HSSFFormulaEvaluator(HSSFSheet sheet, HSSFWorkbook workbook) {
- this.sheet = sheet;
- this.workbook = workbook;
+ _sheet = sheet;
+ _workbook = workbook;
}
+ /**
+ * Does nothing
+ * @deprecated - not needed, since the current row can be derived from the cell
+ */
public void setCurrentRow(HSSFRow row) {
- this.row = row;
+ // do nothing
}
@@ -142,7 +143,7 @@
retval.setErrorValue(cell.getErrorCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
- retval = getCellValueForEval(internalEvaluate(cell, row, sheet, workbook));
+ retval = getCellValueForEval(internalEvaluate(cell, _sheet, _workbook));
break;
case HSSFCell.CELL_TYPE_NUMERIC:
retval = new CellValue(HSSFCell.CELL_TYPE_NUMERIC);
@@ -180,7 +181,7 @@
if (cell != null) {
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_FORMULA:
- CellValue cv = getCellValueForEval(internalEvaluate(cell, row, sheet, workbook));
+ CellValue cv = getCellValueForEval(internalEvaluate(cell, _sheet, _workbook));
switch (cv.getCellType()) {
case HSSFCell.CELL_TYPE_BOOLEAN:
cell.setCellValue(cv.getBooleanValue());
@@ -225,7 +226,7 @@
if (cell != null) {
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_FORMULA:
- CellValue cv = getCellValueForEval(internalEvaluate(cell, row, sheet, workbook));
+ CellValue cv = getCellValueForEval(internalEvaluate(cell, _sheet, _workbook));
switch (cv.getCellType()) {
case HSSFCell.CELL_TYPE_BOOLEAN:
cell.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
@@ -270,7 +271,6 @@
for (Iterator rit = sheet.rowIterator(); rit.hasNext();) {
HSSFRow r = (HSSFRow)rit.next();
- evaluator.setCurrentRow(r);
for (Iterator cit = r.cellIterator(); cit.hasNext();) {
HSSFCell c = (HSSFCell)cit.next();
@@ -324,8 +324,8 @@
* else a runtime exception will be thrown somewhere inside the method.
* (Hence this is a private method.)
*/
- private static ValueEval internalEvaluate(HSSFCell srcCell, HSSFRow srcRow, HSSFSheet sheet, HSSFWorkbook workbook) {
- int srcRowNum = srcRow.getRowNum();
+ private static ValueEval internalEvaluate(HSSFCell srcCell, HSSFSheet sheet, HSSFWorkbook workbook) {
+ int srcRowNum = srcCell.getRowIndex();
short srcColNum = srcCell.getCellNum();
@@ -392,7 +392,7 @@
int rowIx = refPtg.getRow();
HSSFRow row = sheet.getRow(rowIx);
HSSFCell cell = (row != null) ? row.getCell(colIx) : null;
- stack.push(createRef2DEval(refPtg, cell, row, sheet, workbook));
+ stack.push(createRef2DEval(refPtg, cell, sheet, workbook));
}
else if (ptg instanceof Ref3DPtg) {
Ref3DPtg refPtg = (Ref3DPtg) ptg;
@@ -402,7 +402,7 @@
HSSFSheet xsheet = workbook.getSheetAt(wb.getSheetIndexFromExternSheetIndex(refPtg.getExternSheetIndex()));
HSSFRow row = xsheet.getRow(rowIx);
HSSFCell cell = (row != null) ? row.getCell(colIx) : null;
- stack.push(createRef3DEval(refPtg, cell, row, xsheet, workbook));
+ stack.push(createRef3DEval(refPtg, cell, xsheet, workbook));
}
else if (ptg instanceof AreaPtg) {
AreaPtg ap = (AreaPtg) ptg;
@@ -592,7 +592,7 @@
case HSSFCell.CELL_TYPE_STRING:
return new StringEval(cell.getRichStringCellValue().getString());
case HSSFCell.CELL_TYPE_FORMULA:
- return internalEvaluate(cell, row, sheet, workbook);
+ return internalEvaluate(cell, sheet, workbook);
case HSSFCell.CELL_TYPE_BOOLEAN:
return BoolEval.valueOf(cell.getBooleanCellValue());
case HSSFCell.CELL_TYPE_BLANK:
@@ -608,7 +608,7 @@
* Non existent cells are treated as RefEvals containing BlankEval.
*/
private static Ref2DEval createRef2DEval(RefPtg ptg, HSSFCell cell,
- HSSFRow row, HSSFSheet sheet, HSSFWorkbook workbook) {
+ HSSFSheet sheet, HSSFWorkbook workbook) {
if (cell == null) {
return new Ref2DEval(ptg, BlankEval.INSTANCE);
}
@@ -619,7 +619,7 @@
case HSSFCell.CELL_TYPE_STRING:
return new Ref2DEval(ptg, new StringEval(cell.getRichStringCellValue().getString()));
case HSSFCell.CELL_TYPE_FORMULA:
- return new Ref2DEval(ptg, internalEvaluate(cell, row, sheet, workbook));
+ return new Ref2DEval(ptg, internalEvaluate(cell, sheet, workbook));
case HSSFCell.CELL_TYPE_BOOLEAN:
return new Ref2DEval(ptg, BoolEval.valueOf(cell.getBooleanCellValue()));
case HSSFCell.CELL_TYPE_BLANK:
@@ -634,7 +634,7 @@
* create a Ref3DEval for Ref3DPtg.
*/
private static Ref3DEval createRef3DEval(Ref3DPtg ptg, HSSFCell cell,
- HSSFRow row, HSSFSheet sheet, HSSFWorkbook workbook) {
+ HSSFSheet sheet, HSSFWorkbook workbook) {
if (cell == null) {
return new Ref3DEval(ptg, BlankEval.INSTANCE);
}
@@ -644,7 +644,7 @@
case HSSFCell.CELL_TYPE_STRING:
return new Ref3DEval(ptg, new StringEval(cell.getRichStringCellValue().getString()));
case HSSFCell.CELL_TYPE_FORMULA:
- return new Ref3DEval(ptg, internalEvaluate(cell, row, sheet, workbook));
+ return new Ref3DEval(ptg, internalEvaluate(cell, sheet, workbook));
case HSSFCell.CELL_TYPE_BOOLEAN:
return new Ref3DEval(ptg, BoolEval.valueOf(cell.getBooleanCellValue()));
case HSSFCell.CELL_TYPE_BLANK:
@@ -756,7 +756,7 @@
* @param workbook
*/
void inspectPtgs(String formula) {
- FormulaParser fp = new FormulaParser(formula, workbook);
+ FormulaParser fp = new FormulaParser(formula, _workbook);
fp.parse();
Ptg[] ptgs = fp.getRPNPtg();
System.out.println("<ptg-group>");
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java Sat Aug 9 12:47:39 2008
@@ -190,14 +190,10 @@
* @param cell low level cell to create the high level representation from
* @return HSSFCell representing the low level record passed in
*/
-
- protected HSSFCell createCellFromRecord(CellValueRecordInterface cell)
- {
- HSSFCell hcell = new HSSFCell(book, sheet, getRowNum(), cell);
+ protected HSSFCell createCellFromRecord(CellValueRecordInterface cell) {
+ HSSFCell hcell = new HSSFCell(book, sheet, cell);
addCell(hcell);
-
- // sheet.addValueRecord(getRowNum(),cell.getCellValueRecord());
return hcell;
}
@@ -304,15 +300,7 @@
}
/**
- * Get the hssfcell representing a given column (logical cell)
- * 0-based. If you ask for a cell that is not defined then
- * you get a null, unless you have set a different
- * {@link MissingCellPolicy} on the base workbook.
- * Short method signature provided to retain binary
- * compatibility.
- *
- * @param cellnum 0 based column number
- * @return HSSFCell representing that column or null if undefined.
+ * @deprecated (Aug 2008) use {@link #getCell(int)}
*/
public HSSFCell getCell(short cellnum) {
int ushortCellNum = cellnum & 0x0000FFFF; // avoid sign extension
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java Sat Aug 9 12:47:39 2008
@@ -38,42 +38,34 @@
*/
public final class TestFormulaParserEval extends TestCase {
- public void testWithNamedRange() throws Exception {
+ public void testWithNamedRange() {
HSSFWorkbook workbook = new HSSFWorkbook();
- FormulaParser fp;
Ptg[] ptgs;
HSSFSheet s = workbook.createSheet("Foo");
- s.createRow(0).createCell((short)0).setCellValue(1.1);
- s.createRow(1).createCell((short)0).setCellValue(2.3);
- s.createRow(2).createCell((short)2).setCellValue(3.1);
+ s.createRow(0).createCell(0).setCellValue(1.1);
+ s.createRow(1).createCell(0).setCellValue(2.3);
+ s.createRow(2).createCell(2).setCellValue(3.1);
HSSFName name = workbook.createName();
name.setNameName("testName");
name.setReference("A1:A2");
- fp = HSSFFormulaEvaluator.getUnderlyingParser(workbook, "SUM(testName)");
- fp.parse();
- ptgs = fp.getRPNPtg();
+ ptgs = FormulaParser.parse("SUM(testName)", workbook);
assertTrue("two tokens expected, got "+ptgs.length,ptgs.length == 2);
assertEquals(NamePtg.class, ptgs[0].getClass());
assertEquals(FuncVarPtg.class, ptgs[1].getClass());
// Now make it a single cell
name.setReference("C3");
-
- fp = HSSFFormulaEvaluator.getUnderlyingParser(workbook, "SUM(testName)");
- fp.parse();
- ptgs = fp.getRPNPtg();
+ ptgs = FormulaParser.parse("SUM(testName)", workbook);
assertTrue("two tokens expected, got "+ptgs.length,ptgs.length == 2);
assertEquals(NamePtg.class, ptgs[0].getClass());
assertEquals(FuncVarPtg.class, ptgs[1].getClass());
// And make it non-contiguous
name.setReference("A1:A2,C3");
- fp = HSSFFormulaEvaluator.getUnderlyingParser(workbook, "SUM(testName)");
- fp.parse();
- ptgs = fp.getRPNPtg();
+ ptgs = FormulaParser.parse("SUM(testName)", workbook);
assertTrue("two tokens expected, got "+ptgs.length,ptgs.length == 2);
assertEquals(NamePtg.class, ptgs[0].getClass());
assertEquals(FuncVarPtg.class, ptgs[1].getClass());
@@ -86,15 +78,14 @@
wb.setSheetName(0, "Sheet1");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
cell.setCellFormula("SUM(A32769:A32770)");
// put some values in the cells to make the evaluation more interesting
- sheet.createRow(32768).createCell((short)0).setCellValue(31);
- sheet.createRow(32769).createCell((short)0).setCellValue(11);
+ sheet.createRow(32768).createCell(0).setCellValue(31);
+ sheet.createRow(32769).createCell(0).setCellValue(11);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
- fe.setCurrentRow(row);
CellValue result;
try {
result = fe.evaluate(cell);
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java Sat Aug 9 12:47:39 2008
@@ -35,10 +35,9 @@
/**
* Translates StackOverflowError into AssertionFailedError
*/
- private static CellValue evaluateWithCycles(HSSFWorkbook wb, HSSFSheet sheet, HSSFRow row, HSSFCell testCell)
+ private static CellValue evaluateWithCycles(HSSFWorkbook wb, HSSFSheet sheet, HSSFCell testCell)
throws AssertionFailedError {
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
- evaluator.setCurrentRow(row);
try {
return evaluator.evaluate(testCell);
} catch (StackOverflowError e) {
@@ -63,12 +62,12 @@
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet1");
- short colB = 1;
+ int colB = 1;
sheet.createRow(0).createCell(colB).setCellValue(1);
sheet.createRow(1).createCell(colB).setCellValue(2);
sheet.createRow(2).createCell(colB).setCellValue(3);
HSSFRow row4 = sheet.createRow(3);
- HSSFCell testCell = row4.createCell((short)0);
+ HSSFCell testCell = row4.createCell(0);
// This formula should evaluate to the contents of B2,
testCell.setCellFormula("INDEX(A1:B4,2,2)");
// However the range A1:B4 also includes the current cell A4. If the other parameters
@@ -76,7 +75,7 @@
// arguments before invoking operators, POI must handle such potential cycles gracefully.
- CellValue cellValue = evaluateWithCycles(wb, sheet, row4, testCell);
+ CellValue cellValue = evaluateWithCycles(wb, sheet, testCell);
assertTrue(cellValue.getCellType() == HSSFCell.CELL_TYPE_NUMERIC);
assertEquals(2, cellValue.getNumberValue(), 0);
@@ -91,12 +90,11 @@
HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFRow row = sheet.createRow(0);
- HSSFCell testCell = row.createCell((short)0);
+ HSSFCell testCell = row.createCell(0);
testCell.setCellFormula("A1");
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
- evaluator.setCurrentRow(row);
- CellValue cellValue = evaluateWithCycles(wb, sheet, row, testCell);
+ CellValue cellValue = evaluateWithCycles(wb, sheet, testCell);
confirmCycleErrorCode(cellValue);
}
@@ -110,15 +108,14 @@
HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFRow row = sheet.createRow(0);
- row.createCell((short)0).setCellFormula("B1");
- row.createCell((short)1).setCellFormula("C1");
- row.createCell((short)2).setCellFormula("D1");
- HSSFCell testCell = row.createCell((short)3);
+ row.createCell(0).setCellFormula("B1");
+ row.createCell(1).setCellFormula("C1");
+ row.createCell(2).setCellFormula("D1");
+ HSSFCell testCell = row.createCell(3);
testCell.setCellFormula("A1");
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
- evaluator.setCurrentRow(row);
- CellValue cellValue = evaluateWithCycles(wb, sheet, row, testCell);
+ CellValue cellValue = evaluateWithCycles(wb, sheet, testCell);
confirmCycleErrorCode(cellValue);
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java Sat Aug 9 12:47:39 2008
@@ -40,7 +40,7 @@
HSSFSheet sheet = wb.createSheet();
wb.setSheetName(0, "Sheet1");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
HSSFName hssfName = wb.createName();
hssfName.setNameName("myFunc");
@@ -50,7 +50,6 @@
assertEquals("myFunc()", actualFormula);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
- fe.setCurrentRow(row);
CellValue evalResult = fe.evaluate(cell);
// Check the return value from ExternalFunction.evaluate()
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java Sat Aug 9 12:47:39 2008
@@ -67,7 +67,6 @@
// We might as well evaluate the formula
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
- fe.setCurrentRow(row);
CellValue cv = fe.evaluate(cell);
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
@@ -84,20 +83,20 @@
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("input");
// input row 0
- HSSFRow row = sheet.createRow((short) 0);
- HSSFCell cell = row.createCell((short) 0);
- cell = row.createCell((short) 1);
+ HSSFRow row = sheet.createRow(0);
+ HSSFCell cell = row.createCell(0);
+ cell = row.createCell(1);
cell.setCellValue(1); // B1
// input row 1
- row = sheet.createRow((short) 1);
- cell = row.createCell((short) 1);
+ row = sheet.createRow(1);
+ cell = row.createCell(1);
cell.setCellValue(999); // B2
int rno = 4;
row = sheet.createRow(rno);
- cell = row.createCell((short) 1); // B5
+ cell = row.createCell(1); // B5
cell.setCellFormula("isnumber(b1)");
- cell = row.createCell((short) 3); // D5
+ cell = row.createCell(3); // D5
cell.setCellFormula("IF(ISNUMBER(b1),b1,b2)");
if (false) { // set true to check excel file manually
@@ -113,7 +112,6 @@
// use POI's evaluator as an extra sanity check
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
- fe.setCurrentRow(row);
CellValue cv;
cv = fe.evaluate(cell);
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
@@ -132,7 +130,7 @@
HSSFSheet sheet1 = wb.createSheet("Sheet1");
HSSFRow row = sheet1.createRow(0);
- HSSFCell cell = row.createCell((short) 0);
+ HSSFCell cell = row.createCell(0);
// it's important to create the referenced sheet first
HSSFSheet sheet2 = wb.createSheet("A"); // note name 'A'
@@ -165,7 +163,6 @@
double expectedResult = (4.0 * 8.0 + 5.0 * 9.0) / 10.0;
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet1, wb);
- fe.setCurrentRow(row);
CellValue cv = fe.evaluate(cell);
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
@@ -174,6 +171,6 @@
private static void addCell(HSSFSheet sheet, int rowIx, int colIx,
double value) {
- sheet.createRow(rowIx).createCell((short) colIx).setCellValue(value);
+ sheet.createRow(rowIx).createCell(colIx).setCellValue(value);
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java Sat Aug 9 12:47:39 2008
@@ -1,19 +1,19 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
package org.apache.poi.hssf.record.formula.eval;
@@ -69,7 +69,7 @@
/**
* Index of the column that contains the function names
*/
- public static final short COLUMN_INDEX_FUNCTION_NAME = 1; // Column 'B'
+ public static final int COLUMN_INDEX_FUNCTION_NAME = 1; // Column 'B'
/**
* Used to indicate when there are no more functions left
@@ -96,7 +96,7 @@
private int _evaluationFailureCount;
private int _evaluationSuccessCount;
- private static final HSSFCell getExpectedValueCell(HSSFRow row, short columnIndex) {
+ private static final HSSFCell getExpectedValueCell(HSSFRow row, int columnIndex) {
if (row == null) {
return null;
}
@@ -238,10 +238,9 @@
int result = Result.NO_EVALUATIONS_FOUND; // so far
short endcolnum = formulasRow.getLastCellNum();
- evaluator.setCurrentRow(formulasRow);
// iterate across the row for all the evaluation cases
- for (short colnum=SS.COLUMN_INDEX_FIRST_TEST_VALUE; colnum < endcolnum; colnum++) {
+ for (int colnum=SS.COLUMN_INDEX_FIRST_TEST_VALUE; colnum < endcolnum; colnum++) {
HSSFCell c = formulasRow.getCell(colnum);
if (c == null || c.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
continue;
@@ -297,7 +296,6 @@
for(int i=startIx; i<endIx; i++) {
ps.println("\tat " + stes[i].toString());
}
-
}
/**
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestPercentEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestPercentEval.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestPercentEval.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestPercentEval.java Sat Aug 9 12:47:39 2008
@@ -59,12 +59,11 @@
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
cell.setCellFormula("B1%");
- row.createCell((short)1).setCellValue(50.0);
+ row.createCell(1).setCellValue(50.0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
- fe.setCurrentRow(row);
CellValue cv;
try {
cv = fe.evaluate(cell);
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java Sat Aug 9 12:47:39 2008
@@ -290,7 +290,6 @@
continue;
}
HSSFCell cell = row.getCell(COL_IX_ACTUAL);
- fe.setCurrentRow(row);
CellValue cv = fe.evaluate(cell);
double actualValue = cv.getNumberValue();
double expectedValue = row.getCell(COL_IX_EXPECTED).getNumericCellValue();
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestDate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestDate.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestDate.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestDate.java Sat Aug 9 12:47:39 2008
@@ -1,100 +1,83 @@
-/*
- * Created on Sep 11, 2007
- *
- * The Copyright statements and Licenses for the commons application may be
- * found in the file LICENSE.txt
- */
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
package org.apache.poi.hssf.record.formula.functions;
import junit.framework.TestCase;
-import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
/**
* @author Pavel Krupets (pkrupets at palmtreebusiness dot com)
*/
-public class TestDate extends TestCase {
+public final class TestDate extends TestCase {
+
+ private HSSFCell cell11;
+ private HSSFFormulaEvaluator evaluator;
+
public void setUp() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
- HSSFRow row1 = sheet.createRow((short) 0);
-
- this.cell11 = row1.createCell((short) 0);
-
- this.evaluator = new HSSFFormulaEvaluator(sheet, wb);
- this.evaluator.setCurrentRow(row1);
+ cell11 = sheet.createRow(0).createCell(0);
+ cell11.setCellType(HSSFCell.CELL_TYPE_FORMULA);
+ evaluator = new HSSFFormulaEvaluator(sheet, wb);
}
/**
- * Test disabled pending a fix in the formula parser
+ * Test disabled pending a fix in the formula evaluator
+ * TODO - create MissingArgEval and modify the formula evaluator to handle this
*/
- public void DISABLEDtestSomeArgumentsMissing() throws Exception {
- this.cell11.setCellFormula("DATE(, 1, 0)");
- assertEquals(0.0, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(, 1, 1)");
- assertEquals(1.0, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
+ public void DISABLEDtestSomeArgumentsMissing() {
+ confirm("DATE(, 1, 0)", 0.0);
+ confirm("DATE(, 1, 1)", 1.0);
}
- public void testValid() throws Exception {
- this.cell11.setCellType(HSSFCell.CELL_TYPE_FORMULA);
-
- this.cell11.setCellFormula("DATE(1900, 1, 1)");
- assertEquals(1, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1900, 1, 32)");
- assertEquals(32, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
+ public void testValid() {
- this.cell11.setCellFormula("DATE(1900, 222, 1)");
- assertEquals(6727, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1900, 2, 0)");
- assertEquals(31, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(2000, 1, 222)");
- assertEquals(36747.00, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(2007, 1, 1)");
- assertEquals(39083, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
+ confirm("DATE(1900, 1, 1)", 1);
+ confirm("DATE(1900, 1, 32)", 32);
+ confirm("DATE(1900, 222, 1)", 6727);
+ confirm("DATE(1900, 2, 0)", 31);
+ confirm("DATE(2000, 1, 222)", 36747.00);
+ confirm("DATE(2007, 1, 1)", 39083);
}
public void testBugDate() {
- this.cell11.setCellFormula("DATE(1900, 2, 29)");
- assertEquals(60, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1900, 2, 30)");
- assertEquals(61, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1900, 1, 222)");
- assertEquals(222, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1900, 1, 2222)");
- assertEquals(2222, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1900, 1, 22222)");
- assertEquals(22222, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
+ confirm("DATE(1900, 2, 29)", 60);
+ confirm("DATE(1900, 2, 30)", 61);
+ confirm("DATE(1900, 1, 222)", 222);
+ confirm("DATE(1900, 1, 2222)", 2222);
+ confirm("DATE(1900, 1, 22222)", 22222);
}
public void testPartYears() {
- this.cell11.setCellFormula("DATE(4, 1, 1)");
- assertEquals(1462.00, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(14, 1, 1)");
- assertEquals(5115.00, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(104, 1, 1)");
- assertEquals(37987.00, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1004, 1, 1)");
- assertEquals(366705.00, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
+ confirm("DATE(4, 1, 1)", 1462.00);
+ confirm("DATE(14, 1, 1)", 5115.00);
+ confirm("DATE(104, 1, 1)", 37987.00);
+ confirm("DATE(1004, 1, 1)", 366705.00);
}
-
- private HSSFCell cell11;
- private HSSFFormulaEvaluator evaluator;
+
+ private void confirm(String formulaText, double expectedResult) {
+ cell11.setCellFormula(formulaText);
+ double actualValue = evaluator.evaluate(cell11).getNumberValue();
+ assertEquals(expectedResult, actualValue, 0);
+ }
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java Sat Aug 9 12:47:39 2008
@@ -32,8 +32,6 @@
*/
public final class TestIsBlank extends TestCase {
-
-
public void test3DArea() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet();
@@ -41,13 +39,12 @@
wb.createSheet();
wb.setSheetName(1, "Sheet2");
HSSFRow row = sheet1.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
cell.setCellFormula("isblank(Sheet2!A1:A1)");
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet1, wb);
- fe.setCurrentRow(row);
CellValue result = fe.evaluate(cell);
assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, result.getCellType());
assertEquals(true, result.getBooleanValue());
@@ -57,6 +54,5 @@
result = fe.evaluate(cell);
assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, result.getCellType());
assertEquals(true, result.getBooleanValue());
-
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java Sat Aug 9 12:47:39 2008
@@ -1,25 +1,22 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
package org.apache.poi.hssf.record.formula.functions;
-import java.io.FileInputStream;
-import java.io.IOException;
import java.io.PrintStream;
import junit.framework.Assert;
@@ -70,10 +67,10 @@
/** Row (zero-based) in each sheet where the evaluation cases start. */
public static final int START_TEST_CASES_ROW_INDEX = 4; // Row '5'
/** Index of the column that contains the function names */
- public static final short COLUMN_INDEX_MARKER = 0; // Column 'A'
- public static final short COLUMN_INDEX_EVALUATION = 1; // Column 'B'
- public static final short COLUMN_INDEX_EXPECTED_RESULT = 2; // Column 'C'
- public static final short COLUMN_ROW_COMMENT = 3; // Column 'D'
+ public static final int COLUMN_INDEX_MARKER = 0; // Column 'A'
+ public static final int COLUMN_INDEX_EVALUATION = 1; // Column 'B'
+ public static final int COLUMN_INDEX_EXPECTED_RESULT = 2; // Column 'C'
+ public static final int COLUMN_ROW_COMMENT = 3; // Column 'D'
/** Used to indicate when there are no more test cases on the current sheet */
public static final String TEST_CASES_END_MARKER = "<end>";
@@ -240,7 +237,6 @@
if (c == null || c.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
continue;
}
- evaluator.setCurrentRow(r);
CellValue actualValue = evaluator.evaluate(c);
HSSFCell expectedValueCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_RESULT);
String rowComment = getRowCommentColumnValue(r);
@@ -307,9 +303,8 @@
throw new RuntimeException("First sheet's name was '" + firstSheetName + "' but expected '" + SS.README_SHEET_NAME + "'");
}
HSSFSheet sheet = workbook.getSheetAt(0);
- String specifiedClassName = sheet.getRow(2).getCell((short)0).getRichStringCellValue().getString();
+ String specifiedClassName = sheet.getRow(2).getCell(0).getRichStringCellValue().getString();
assertEquals("Test class name in spreadsheet comment", getClass().getName(), specifiedClassName);
-
}
@@ -362,7 +357,7 @@
if(r == null) {
return null;
}
- HSSFCell cell = r.getCell((short) colIndex);
+ HSSFCell cell = r.getCell(colIndex);
if(cell == null) {
return null;
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java Sat Aug 9 12:47:39 2008
@@ -51,7 +51,6 @@
Iterator it = s.rowIterator();
while(it.hasNext()) {
HSSFRow r = (HSSFRow)it.next();
- eval.setCurrentRow(r);
process(r, eval);
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java Sat Aug 9 12:47:39 2008
@@ -19,41 +19,43 @@
import junit.framework.TestCase;
-public class TestBug43093 extends TestCase {
+/**
+ *
+ */
+public final class TestBug43093 extends TestCase {
private static void addNewSheetWithCellsA1toD4(HSSFWorkbook book, int sheet) {
HSSFSheet sht = book .createSheet("s" + sheet);
- for (short r=0; r < 4; r++) {
+ for (int r=0; r < 4; r++) {
HSSFRow row = sht.createRow (r);
- for (short c=0; c < 4; c++) {
+ for (int c=0; c < 4; c++) {
HSSFCell cel = row.createCell(c);
- /**/ cel.setCellValue(sheet*100 + r*10 + c);
+ cel.setCellValue(sheet*100 + r*10 + c);
}
}
}
- public void testBug43093() throws Exception {
- HSSFWorkbook xlw = new HSSFWorkbook();
+ public void testBug43093() {
+ HSSFWorkbook xlw = new HSSFWorkbook();
- addNewSheetWithCellsA1toD4(xlw, 1);
- addNewSheetWithCellsA1toD4(xlw, 2);
- addNewSheetWithCellsA1toD4(xlw, 3);
- addNewSheetWithCellsA1toD4(xlw, 4);
-
- HSSFSheet s2 = xlw.getSheet("s2");
- HSSFRow s2r3 = s2.getRow(3);
- HSSFCell s2E4 = s2r3.createCell((short)4);
- /**/ s2E4.setCellFormula("SUM(s3!B2:C3)");
-
- HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(s2, xlw);
- eva.setCurrentRow(s2r3);
- double d = eva.evaluate(s2E4).getNumberValue();
-
- // internalEvaluate(...) Area3DEval.: 311+312+321+322 expected
- assertEquals(d, (double)(311+312+321+322), 0.0000001);
- // System.out.println("Area3DEval ok.: 311+312+321+322=" + d);
+ addNewSheetWithCellsA1toD4(xlw, 1);
+ addNewSheetWithCellsA1toD4(xlw, 2);
+ addNewSheetWithCellsA1toD4(xlw, 3);
+ addNewSheetWithCellsA1toD4(xlw, 4);
+
+ HSSFSheet s2 = xlw.getSheet("s2");
+ HSSFRow s2r3 = s2.getRow(3);
+ HSSFCell s2E4 = s2r3.createCell(4);
+ s2E4.setCellFormula("SUM(s3!B2:C3)");
+
+ HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(s2, xlw);
+ double d = eva.evaluate(s2E4).getNumberValue();
+
+ // internalEvaluate(...) Area3DEval.: 311+312+321+322 expected
+ assertEquals(d, (311+312+321+322), 0.0000001);
+ // System.out.println("Area3DEval ok.: 311+312+321+322=" + d);
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Sat Aug 9 12:47:39 2008
@@ -78,7 +78,7 @@
HSSFWorkbook wb = openSample("15228.xls");
HSSFSheet s = wb.getSheetAt(0);
HSSFRow r = s.createRow(0);
- HSSFCell c = r.createCell((short)0);
+ HSSFCell c = r.createCell(0);
c.setCellValue(10);
writeTestOutputFileForViewing(wb, "test15228");
}
@@ -87,7 +87,7 @@
HSSFWorkbook wb = openSample("13796.xls");
HSSFSheet s = wb.getSheetAt(0);
HSSFRow r = s.createRow(0);
- HSSFCell c = r.createCell((short)0);
+ HSSFCell c = r.createCell(0);
c.setCellValue(10);
writeOutAndReadBack(wb);
}
@@ -97,7 +97,7 @@
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFRow r = s.createRow(0);
- r.createCell((short)0).setCellFormula("HYPERLINK( \"http://jakarta.apache.org\", \"Jakarta\" )");
+ r.createCell(0).setCellFormula("HYPERLINK( \"http://jakarta.apache.org\", \"Jakarta\" )");
writeTestOutputFileForViewing(wb, "test23094");
}
@@ -109,8 +109,8 @@
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("My sheet");
- HSSFRow row = sheet.createRow( (short) 0 );
- HSSFCell cell = row.createCell( (short) 0 );
+ HSSFRow row = sheet.createRow( 0 );
+ HSSFCell cell = row.createCell( 0 );
cell.setCellFormula("HYPERLINK(\"http://google.com\",\"Google\")");
writeOutAndReadBack(wb);
@@ -142,9 +142,9 @@
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(5);
- HSSFCell cell = row.getCell((short)3);
+ HSSFCell cell = row.getCell(3);
if (cell == null)
- cell = row.createCell((short)3);
+ cell = row.createCell(3);
// Write test
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
@@ -153,9 +153,9 @@
// change existing numeric cell value
HSSFRow oRow = sheet.getRow(14);
- HSSFCell oCell = oRow.getCell((short)4);
+ HSSFCell oCell = oRow.getCell(4);
oCell.setCellValue(75);
- oCell = oRow.getCell((short)5);
+ oCell = oRow.getCell(5);
setCellText(oCell, "0.3");
writeTestOutputFileForViewing(wb, "test15375");
@@ -177,13 +177,13 @@
tmp2 = "Test2" + i;
tmp3 = "Test3" + i;
- HSSFRow row = sheet.createRow((short)i);
+ HSSFRow row = sheet.createRow(i);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
setCellText(cell, tmp1);
- cell = row.createCell((short)1);
+ cell = row.createCell(1);
setCellText(cell, tmp2);
- cell = row.createCell((short)2);
+ cell = row.createCell(2);
setCellText(cell, tmp3);
}
writeTestOutputFileForViewing(wb, "test15375-2");
@@ -203,16 +203,16 @@
HSSFRow rw = null ;
HSSFCell cell =null;
- rw = sheet.createRow((short)0) ;
+ rw = sheet.createRow(0) ;
//Header row
- for(short j=0; j<col_cnt; j++){
+ for(int j=0; j<col_cnt; j++){
cell = rw.createCell(j) ;
setCellText(cell, "Col " + (j+1)) ;
}
for(int i=1; i<rw_cnt; i++){
- rw = sheet.createRow((short)i) ;
- for(short j=0; j<col_cnt; j++){
+ rw = sheet.createRow(i) ;
+ for(int j=0; j<col_cnt; j++){
cell = rw.createCell(j) ;
setCellText(cell, "Row:" + (i+1) + ",Column:" + (j+1)) ;
}
@@ -277,7 +277,7 @@
HSSFRow row = sheet.getRow(rowIndex);
int cells = row.getLastCellNum();
- for (short cellIndex = 0; cellIndex < cells; cellIndex++) {
+ for (int cellIndex = 0; cellIndex < cells; cellIndex++) {
row.getCell(cellIndex);
}
}
@@ -289,12 +289,12 @@
book.createSheet("TEST");
HSSFSheet sheet = book.cloneSheet(0);
book.setSheetName(1,"CLONE");
- sheet.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Test"));
+ sheet.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Test"));
book = writeOutAndReadBack(book);
sheet = book.getSheet("CLONE");
HSSFRow row = sheet.getRow(0);
- HSSFCell cell = row.getCell((short)0);
+ HSSFCell cell = row.getCell(0);
assertEquals("Test", cell.getRichStringCellValue().getString());
}
@@ -336,14 +336,14 @@
HSSFWorkbook w = openSample("25695.xls");
- HSSFCell a1 = w.getSheetAt(0).getRow(0).getCell((short) 0);
- HSSFCell a2 = w.getSheetAt(0).getRow(0).getCell((short) 1);
- HSSFCell b1 = w.getSheetAt(0).getRow(1).getCell((short) 0);
- HSSFCell b2 = w.getSheetAt(0).getRow(1).getCell((short) 1);
- HSSFCell c1 = w.getSheetAt(0).getRow(2).getCell((short) 0);
- HSSFCell c2 = w.getSheetAt(0).getRow(2).getCell((short) 1);
- HSSFCell d1 = w.getSheetAt(0).getRow(3).getCell((short) 0);
- HSSFCell d2 = w.getSheetAt(0).getRow(3).getCell((short) 1);
+ HSSFCell a1 = w.getSheetAt(0).getRow(0).getCell(0);
+ HSSFCell a2 = w.getSheetAt(0).getRow(0).getCell(1);
+ HSSFCell b1 = w.getSheetAt(0).getRow(1).getCell(0);
+ HSSFCell b2 = w.getSheetAt(0).getRow(1).getCell(1);
+ HSSFCell c1 = w.getSheetAt(0).getRow(2).getCell(0);
+ HSSFCell c2 = w.getSheetAt(0).getRow(2).getCell(1);
+ HSSFCell d1 = w.getSheetAt(0).getRow(3).getCell(0);
+ HSSFCell d2 = w.getSheetAt(0).getRow(3).getCell(1);
if (false) {
// THAI code page
@@ -366,14 +366,14 @@
HSSFWorkbook rw = writeOutAndReadBack(w);
- HSSFCell ra1 = rw.getSheetAt(0).getRow(0).getCell((short) 0);
- HSSFCell ra2 = rw.getSheetAt(0).getRow(0).getCell((short) 1);
- HSSFCell rb1 = rw.getSheetAt(0).getRow(1).getCell((short) 0);
- HSSFCell rb2 = rw.getSheetAt(0).getRow(1).getCell((short) 1);
- HSSFCell rc1 = rw.getSheetAt(0).getRow(2).getCell((short) 0);
- HSSFCell rc2 = rw.getSheetAt(0).getRow(2).getCell((short) 1);
- HSSFCell rd1 = rw.getSheetAt(0).getRow(3).getCell((short) 0);
- HSSFCell rd2 = rw.getSheetAt(0).getRow(3).getCell((short) 1);
+ HSSFCell ra1 = rw.getSheetAt(0).getRow(0).getCell(0);
+ HSSFCell ra2 = rw.getSheetAt(0).getRow(0).getCell(1);
+ HSSFCell rb1 = rw.getSheetAt(0).getRow(1).getCell(0);
+ HSSFCell rb2 = rw.getSheetAt(0).getRow(1).getCell(1);
+ HSSFCell rc1 = rw.getSheetAt(0).getRow(2).getCell(0);
+ HSSFCell rc2 = rw.getSheetAt(0).getRow(2).getCell(1);
+ HSSFCell rd1 = rw.getSheetAt(0).getRow(3).getCell(0);
+ HSSFCell rd2 = rw.getSheetAt(0).getRow(3).getCell(1);
confirmSameCellText(a1, ra1);
confirmSameCellText(b1, rb1);
@@ -425,7 +425,7 @@
wb.setSheetName(0, "Sheet1");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
String formulaText =
"IF(ROUND(A2*B2*C2,2)>ROUND(B2*D2,2),ROUND(A2*B2*C2,2),ROUND(B2*D2,2))";
cell.setCellFormula(formulaText);
@@ -487,7 +487,7 @@
for(int i = 1; i < 400; i++) {
HSSFRow row = sheet.getRow(i);
if(row != null) {
- row.getCell((short)0);
+ row.getCell(0);
}
}
@@ -497,7 +497,7 @@
for(int i = 1; i < 400; i++) {
HSSFRow row = sheet.getRow(i);
if(row != null) {
- row.getCell((short)0);
+ row.getCell(0);
}
}
}
@@ -521,7 +521,7 @@
for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
HSSFRow row = sheet.getRow(i);
if (row != null) {
- HSSFCell cell = row .getCell((short)0);
+ HSSFCell cell = row .getCell(0);
assertEquals(HSSFCell.CELL_TYPE_STRING, cell.getCellType());
count++;
}
@@ -630,11 +630,11 @@
HSSFSheet workSheet = workBook.createSheet("Sheet1");
HSSFCell cell;
HSSFRow row = workSheet.createRow(0);
- cell = row.createCell((short)0, HSSFCell.CELL_TYPE_NUMERIC);
+ cell = row.createCell(0, HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue(1.0);
- cell = row.createCell((short)1, HSSFCell.CELL_TYPE_NUMERIC);
+ cell = row.createCell(1, HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue(2.0);
- cell = row.createCell((short)2, HSSFCell.CELL_TYPE_FORMULA);
+ cell = row.createCell(2, HSSFCell.CELL_TYPE_FORMULA);
cell.setCellFormula("SUM(A1:B1)");
writeOutAndReadBack(wb);
@@ -751,12 +751,12 @@
// Textual value
HSSFRow r1 = s.getRow(0);
- HSSFCell c1 = r1.getCell((short)1);
+ HSSFCell c1 = r1.getCell(1);
assertEquals("=CHOOSE(2,A2,A3,A4)", c1.getRichStringCellValue().toString());
// Formula Value
HSSFRow r2 = s.getRow(1);
- HSSFCell c2 = r2.getCell((short)1);
+ HSSFCell c2 = r2.getCell(1);
assertEquals(25, (int)c2.getNumericCellValue());
try {
@@ -898,7 +898,7 @@
* Had a problem apparently, not sure what as it
* works just fine...
*/
- public void test44891() throws Exception {
+ public void test44891() {
HSSFWorkbook wb = openSample("44891.xls");
assertTrue("no errors reading sample xls", true);
writeOutAndReadBack(wb);
@@ -910,7 +910,7 @@
*
* Works fine with poi-3.1-beta1.
*/
- public void test44235() throws Exception {
+ public void test44235() {
HSSFWorkbook wb = openSample("44235.xls");
assertTrue("no errors reading sample xls", true);
writeOutAndReadBack(wb);
@@ -925,16 +925,16 @@
public void test21334() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sh = wb.createSheet();
- HSSFCell cell = sh.createRow(0).createCell((short)0);
+ HSSFCell cell = sh.createRow(0).createCell(0);
String formula = "SUM(IF(FREQUENCY(IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),\"\"),IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),\"\"))>0,1))";
cell.setCellFormula(formula);
HSSFWorkbook wb_sv = writeOutAndReadBack(wb);
- HSSFCell cell_sv = wb_sv.getSheetAt(0).getRow(0).getCell((short)0);
+ HSSFCell cell_sv = wb_sv.getSheetAt(0).getRow(0).getCell(0);
assertEquals(formula, cell_sv.getCellFormula());
}
- public void test36947() throws Exception {
+ public void test36947() {
HSSFWorkbook wb = openSample("36947.xls");
assertTrue("no errors reading sample xls", true);
writeOutAndReadBack(wb);
@@ -946,12 +946,12 @@
*/
public void test42448(){
HSSFWorkbook wb = new HSSFWorkbook();
- HSSFCell cell = wb.createSheet().createRow(0).createCell((short)0);
+ HSSFCell cell = wb.createSheet().createRow(0).createCell(0);
cell.setCellFormula("SUMPRODUCT(A!C7:A!C67, B8:B68) / B69");
assertTrue("no errors parsing formula", true);
}
- public void test39634() throws Exception {
+ public void test39634() {
HSSFWorkbook wb = openSample("39634.xls");
assertTrue("no errors reading sample xls", true);
writeOutAndReadBack(wb);
@@ -963,7 +963,7 @@
* HSSFObjectData
* @throws Exception
*/
- public void test44840() throws Exception {
+ public void test44840() {
HSSFWorkbook wb = openSample("WithCheckBoxes.xls");
// Take a look at the embeded objects
@@ -991,7 +991,11 @@
try {
obj.getDirectory();
fail();
- } catch(FileNotFoundException e) {}
+ } catch(FileNotFoundException e) {
+ // expectd during successful test
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
}
/**
@@ -1000,7 +1004,7 @@
* used for printing stuff.
* Currently broken, as we change the Ptg
*/
- public void test30978() throws Exception {
+ public void test30978() {
HSSFWorkbook wb = openSample("30978-alt.xls");
assertEquals(1, wb.getNumberOfNames());
assertEquals(3, wb.getNumberOfSheets());
@@ -1056,15 +1060,15 @@
/**
* Test that fonts get added properly
*/
- public void test45338() throws Exception {
+ public void test45338() {
HSSFWorkbook wb = new HSSFWorkbook();
assertEquals(4, wb.getNumberOfFonts());
HSSFSheet s = wb.createSheet();
s.createRow(0);
s.createRow(1);
- HSSFCell c1 = s.getRow(0).createCell((short)0);
- HSSFCell c2 = s.getRow(1).createCell((short)0);
+ HSSFCell c1 = s.getRow(0).createCell(0);
+ HSSFCell c2 = s.getRow(1).createCell(0);
assertEquals(4, wb.getNumberOfFonts());
@@ -1140,15 +1144,14 @@
/**
* From the mailing list - ensure we can handle a formula
* containing a zip code, eg ="70164"
- * @throws Exception
*/
- public void testZipCodeFormulas() throws Exception {
+ public void testZipCodeFormulas() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
s.createRow(0);
- HSSFCell c1 = s.getRow(0).createCell((short)0);
- HSSFCell c2 = s.getRow(0).createCell((short)1);
- HSSFCell c3 = s.getRow(0).createCell((short)2);
+ HSSFCell c1 = s.getRow(0).createCell(0);
+ HSSFCell c2 = s.getRow(0).createCell(1);
+ HSSFCell c3 = s.getRow(0).createCell(2);
// As number and string
c1.setCellFormula("70164");
@@ -1176,7 +1179,6 @@
// Now evaluate, they should all be changed
HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(s, wb);
- eval.setCurrentRow(s.getRow(0));
eval.evaluateFormulaCell(c1);
eval.evaluateFormulaCell(c2);
eval.evaluateFormulaCell(c3);
@@ -1194,9 +1196,9 @@
// Write and read
HSSFWorkbook nwb = writeOutAndReadBack(wb);
HSSFSheet ns = nwb.getSheetAt(0);
- HSSFCell nc1 = ns.getRow(0).getCell((short)0);
- HSSFCell nc2 = ns.getRow(0).getCell((short)1);
- HSSFCell nc3 = ns.getRow(0).getCell((short)2);
+ HSSFCell nc1 = ns.getRow(0).getCell(0);
+ HSSFCell nc2 = ns.getRow(0).getCell(1);
+ HSSFCell nc3 = ns.getRow(0).getCell(2);
// Re-check
assertEquals(70164.0, nc1.getNumericCellValue(), 0.00001);
@@ -1241,7 +1243,7 @@
* For now, blows up with an exception from ExtPtg
* Expected ExpPtg to be converted from Shared to Non-Shared...
*/
- public void DISABLEDtest43623() throws Exception {
+ public void DISABLEDtest43623() {
HSSFWorkbook wb = openSample("43623.xls");
assertEquals(1, wb.getNumberOfSheets());
@@ -1272,7 +1274,7 @@
* People are all getting confused about the last
* row and cell number
*/
- public void test30635() throws Exception {
+ public void test30635() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
@@ -1301,17 +1303,17 @@
assertEquals(0, r.getPhysicalNumberOfCells());
// Add a cell, things move off -1
- r.createCell((short)0);
+ r.createCell(0);
assertEquals(0, r.getFirstCellNum());
assertEquals(1, r.getLastCellNum()); // last cell # + 1
assertEquals(1, r.getPhysicalNumberOfCells());
- r.createCell((short)1);
+ r.createCell(1);
assertEquals(0, r.getFirstCellNum());
assertEquals(2, r.getLastCellNum()); // last cell # + 1
assertEquals(2, r.getPhysicalNumberOfCells());
- r.createCell((short)4);
+ r.createCell(4);
assertEquals(0, r.getFirstCellNum());
assertEquals(5, r.getLastCellNum()); // last cell # + 1
assertEquals(3, r.getPhysicalNumberOfCells());
@@ -1320,7 +1322,7 @@
/**
* Data Tables - ptg 0x2
*/
- public void test44958() throws Exception {
+ public void test44958() {
HSSFWorkbook wb = openSample("44958.xls");
HSSFSheet s;
HSSFRow r;
@@ -1351,7 +1353,7 @@
/**
* 45322: HSSFSheet.autoSizeColumn fails when style.getDataFormat() returns -1
*/
- public void test45322() throws Exception {
+ public void test45322() {
HSSFWorkbook wb = openSample("44958.xls");
HSSFSheet sh = wb.getSheetAt(0);
for(short i=0; i < 30; i++) sh.autoSizeColumn(i);
@@ -1361,7 +1363,7 @@
* We used to add too many UncalcRecords to sheets
* with diagrams on. Don't any more
*/
- public void test45414() throws Exception {
+ public void test45414() {
HSSFWorkbook wb = openSample("WithThreeCharts.xls");
wb.getSheetAt(0).setForceFormulaRecalculation(true);
wb.getSheetAt(1).setForceFormulaRecalculation(false);
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java Sat Aug 9 12:47:39 2008
@@ -59,11 +59,11 @@
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(0);
- row.getCell((short) 0).setCellValue(4.2);
- row.getCell((short) 2).setCellValue(25);
+ row.getCell(0).setCellValue(4.2);
+ row.getCell(2).setCellValue(25);
HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
- assertEquals(4.2 * 25, row.getCell((short) 3).getNumericCellValue(), 0.0001);
+ assertEquals(4.2 * 25, row.getCell(3).getNumericCellValue(), 0.0001);
// Save
File existing = new File(tmpDirName, "44636-existing.xls");
@@ -77,14 +77,14 @@
sheet = wb.createSheet();
row = sheet.createRow(0);
- row.createCell((short) 0).setCellValue(1.2);
- row.createCell((short) 1).setCellValue(4.2);
+ row.createCell(0).setCellValue(1.2);
+ row.createCell(1).setCellValue(4.2);
row = sheet.createRow(1);
- row.createCell((short) 0).setCellFormula("SUM(A1:B1)");
+ row.createCell(0).setCellFormula("SUM(A1:B1)");
HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
- assertEquals(5.4, row.getCell((short) 0).getNumericCellValue(), 0.0001);
+ assertEquals(5.4, row.getCell(0).getNumericCellValue(), 0.0001);
// Save
File scratch = new File(tmpDirName, "44636-scratch.xls");
@@ -113,57 +113,48 @@
HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(sheet, wb);
row = sheet.getRow(0);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("31+46", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(77, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(1);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("30+53", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(83, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(2);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("SUM(A1:A2)", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(160, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(4);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("32767+32768", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(65535, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(7);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("32744+42333", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(75077, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(8);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("327680.0/32768", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(10, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(9);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("32767+32769", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(65536, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(10);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("35000+36000", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(71000, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(11);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("-1000000.0-3000000.0", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(-4000000, eva.evaluate(cell).getNumberValue(), 0);
}
@@ -189,7 +180,7 @@
HSSFRow rowSUM2D = sheet.getRow(5);
// Test the sum
- HSSFCell cellSUM = rowSUM.getCell((short) 0);
+ HSSFCell cellSUM = rowSUM.getCell(0);
FormulaRecordAggregate frec = (FormulaRecordAggregate) cellSUM.getCellValueRecord();
List ops = frec.getFormulaRecord().getParsedExpression();
@@ -210,7 +201,6 @@
// rows it covers as we don't have the sheet
// to hand when turning the Ptgs into a string
assertEquals("SUM(C:C)", cellSUM.getCellFormula());
- eva.setCurrentRow(rowSUM);
// But the evaluator knows the sheet, so it
// can do it properly
@@ -219,15 +209,13 @@
// Test the index
// Again, the formula string will be right but
// lacking row count, evaluated will be right
- HSSFCell cellIDX = rowIDX.getCell((short) 0);
+ HSSFCell cellIDX = rowIDX.getCell(0);
assertEquals("INDEX(C:C,2,1)", cellIDX.getCellFormula());
- eva.setCurrentRow(rowIDX);
assertEquals(2, eva.evaluate(cellIDX).getNumberValue(), 0);
// Across two colums
- HSSFCell cellSUM2D = rowSUM2D.getCell((short) 0);
+ HSSFCell cellSUM2D = rowSUM2D.getCell(0);
assertEquals("SUM(C:D)", cellSUM2D.getCellFormula());
- eva.setCurrentRow(rowSUM2D);
assertEquals(66, eva.evaluate(cellSUM2D).getNumberValue(), 0);
}
@@ -239,12 +227,11 @@
HSSFSheet sheet = wb.createSheet();
wb.setSheetName(0, "Sheet1");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short) 0);
+ HSSFCell cell = row.createCell(0);
cell.setCellFormula("1=1");
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
- fe.setCurrentRow(row);
try {
fe.evaluateInCell(cell);
} catch (NumberFormatException e) {
@@ -267,7 +254,6 @@
for (Iterator rows = s.rowIterator(); rows.hasNext();) {
HSSFRow r = (HSSFRow) rows.next();
- eval.setCurrentRow(r);
for (Iterator cells = r.cellIterator(); cells.hasNext();) {
HSSFCell c = (HSSFCell) cells.next();
@@ -281,10 +267,9 @@
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFRow row = sheet.createRow(1);
- HSSFCell cell = row.createCell((short) 0);
+ HSSFCell cell = row.createCell(0);
cell.setCellFormula("na()"); // this formula evaluates to an Excel error code '#N/A'
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
- fe.setCurrentRow(row);
try {
fe.evaluateInCell(cell);
} catch (NumberFormatException e) {
@@ -320,8 +305,6 @@
final HSSFFormulaEvaluator evaluator = new
HSSFFormulaEvaluator(sheet, wb);
- evaluator.setCurrentRow(excelRow);
-
now = System.currentTimeMillis();
evaluator.evaluate(excelCell);
then = System.currentTimeMillis();
@@ -333,8 +316,6 @@
final HSSFFormulaEvaluator evaluator = new
HSSFFormulaEvaluator(sheet, wb);
- evaluator.setCurrentRow(excelRow);
-
now = System.currentTimeMillis();
evaluator.evaluate(excelCell);
then = System.currentTimeMillis();
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java?rev=684321&r1=684320&r2=684321&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java Sat Aug 9 12:47:39 2008
@@ -1,3 +1,20 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hssf.usermodel;
import java.util.Iterator;
@@ -9,15 +26,12 @@
* http://poi.apache.org/hssf/eval.html
* all actually works as we'd expect them to
*/
-public class TestFormulaEvaluatorDocs extends TestCase {
- protected void setUp() throws Exception {
- super.setUp();
- }
+public final class TestFormulaEvaluatorDocs extends TestCase {
/**
* http://poi.apache.org/hssf/eval.html#EvaluateAll
*/
- public void testEvaluateAll() throws Exception {
+ public void testEvaluateAll() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s1 = wb.createSheet();
HSSFSheet s2 = wb.createSheet();
@@ -28,21 +42,21 @@
HSSFRow s1r2 = s1.createRow(1);
HSSFRow s2r1 = s2.createRow(0);
- HSSFCell s1r1c1 = s1r1.createCell((short)0);
- HSSFCell s1r1c2 = s1r1.createCell((short)1);
- HSSFCell s1r1c3 = s1r1.createCell((short)2);
+ HSSFCell s1r1c1 = s1r1.createCell(0);
+ HSSFCell s1r1c2 = s1r1.createCell(1);
+ HSSFCell s1r1c3 = s1r1.createCell(2);
s1r1c1.setCellValue(22.3);
s1r1c2.setCellValue(33.4);
s1r1c3.setCellFormula("SUM(A1:B1)");
- HSSFCell s1r2c1 = s1r2.createCell((short)0);
- HSSFCell s1r2c2 = s1r2.createCell((short)1);
- HSSFCell s1r2c3 = s1r2.createCell((short)2);
+ HSSFCell s1r2c1 = s1r2.createCell(0);
+ HSSFCell s1r2c2 = s1r2.createCell(1);
+ HSSFCell s1r2c3 = s1r2.createCell(2);
s1r2c1.setCellValue(-1.2);
s1r2c2.setCellValue(-3.4);
s1r2c3.setCellFormula("SUM(A2:B2)");
- HSSFCell s2r1c1 = s2r1.createCell((short)0);
+ HSSFCell s2r1c1 = s2r1.createCell(0);
s2r1c1.setCellFormula("S1!A1");
// Not evaluated yet
@@ -58,7 +72,6 @@
for(Iterator rit = sheet.rowIterator(); rit.hasNext();) {
HSSFRow r = (HSSFRow)rit.next();
- evaluator.setCurrentRow(r);
for(Iterator cit = r.cellIterator(); cit.hasNext();) {
HSSFCell c = (HSSFCell)cit.next();
@@ -73,17 +86,17 @@
}
// Check now as expected
- assertEquals(55.7, wb.getSheetAt(0).getRow(0).getCell((short)2).getNumericCellValue(), 0);
- assertEquals("SUM(A1:B1)", wb.getSheetAt(0).getRow(0).getCell((short)2).getCellFormula());
- assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(0).getRow(0).getCell((short)2).getCellType());
-
- assertEquals(-4.6, wb.getSheetAt(0).getRow(1).getCell((short)2).getNumericCellValue(), 0);
- assertEquals("SUM(A2:B2)", wb.getSheetAt(0).getRow(1).getCell((short)2).getCellFormula());
- assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(0).getRow(1).getCell((short)2).getCellType());
-
- assertEquals(22.3, wb.getSheetAt(1).getRow(0).getCell((short)0).getNumericCellValue(), 0);
- assertEquals("'S1'!A1", wb.getSheetAt(1).getRow(0).getCell((short)0).getCellFormula());
- assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(1).getRow(0).getCell((short)0).getCellType());
+ assertEquals(55.7, wb.getSheetAt(0).getRow(0).getCell(2).getNumericCellValue(), 0);
+ assertEquals("SUM(A1:B1)", wb.getSheetAt(0).getRow(0).getCell(2).getCellFormula());
+ assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(0).getRow(0).getCell(2).getCellType());
+
+ assertEquals(-4.6, wb.getSheetAt(0).getRow(1).getCell(2).getNumericCellValue(), 0);
+ assertEquals("SUM(A2:B2)", wb.getSheetAt(0).getRow(1).getCell(2).getCellFormula());
+ assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(0).getRow(1).getCell(2).getCellType());
+
+ assertEquals(22.3, wb.getSheetAt(1).getRow(0).getCell(0).getNumericCellValue(), 0);
+ assertEquals("'S1'!A1", wb.getSheetAt(1).getRow(0).getCell(0).getCellFormula());
+ assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(1).getRow(0).getCell(0).getCellType());
// Now do the alternate call, which zaps the formulas
@@ -94,7 +107,6 @@
for(Iterator rit = sheet.rowIterator(); rit.hasNext();) {
HSSFRow r = (HSSFRow)rit.next();
- evaluator.setCurrentRow(r);
for(Iterator cit = r.cellIterator(); cit.hasNext();) {
HSSFCell c = (HSSFCell)cit.next();
@@ -105,13 +117,13 @@
}
}
- assertEquals(55.7, wb.getSheetAt(0).getRow(0).getCell((short)2).getNumericCellValue(), 0);
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(0).getRow(0).getCell((short)2).getCellType());
+ assertEquals(55.7, wb.getSheetAt(0).getRow(0).getCell(2).getNumericCellValue(), 0);
+ assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(0).getRow(0).getCell(2).getCellType());
- assertEquals(-4.6, wb.getSheetAt(0).getRow(1).getCell((short)2).getNumericCellValue(), 0);
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(0).getRow(1).getCell((short)2).getCellType());
+ assertEquals(-4.6, wb.getSheetAt(0).getRow(1).getCell(2).getNumericCellValue(), 0);
+ assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(0).getRow(1).getCell(2).getCellType());
- assertEquals(22.3, wb.getSheetAt(1).getRow(0).getCell((short)0).getNumericCellValue(), 0);
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(1).getRow(0).getCell((short)0).getCellType());
+ assertEquals(22.3, wb.getSheetAt(1).getRow(0).getCell(0).getNumericCellValue(), 0);
+ assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(1).getRow(0).getCell(0).getCellType());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org