From: Josh Micich Date: Sun, 13 Jul 2008 23:23:13 +0000 (+0000) Subject: Fix for bug 45380 - added return keyword in ArrayPtg.toFormulaString() X-Git-Tag: REL_3_2_FINAL~241 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=197b6cab7f2d1c44350ac730b5210e7ee48bb111;p=poi.git Fix for bug 45380 - added return keyword in ArrayPtg.toFormulaString() git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@676457 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index be530cb5c2..15f1a29d5e 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 45380 - Missing return keyword in ArrayPtg.toFormulaString() 44958 - Record level support for Data Tables. (No formula parser support though) 35583 - Include a version class, org.apache.poi.Version, to allow easy introspection of the POI version Allow the cloning of one HSSFCellStyle onto another, including cloning styles from one HSSFWorkbook onto another diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 2ec98011f6..b77bcae69f 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 45380 - Missing return keyword in ArrayPtg.toFormulaString() 44958 - Record level support for Data Tables. (No formula parser support though) 35583 - Include a version class, org.apache.poi.Version, to allow easy introspection of the POI version Allow the cloning of one HSSFCellStyle onto another, including cloning styles from one HSSFWorkbook onto another diff --git a/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java b/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java index 43e3d04e3e..97fad47b9e 100644 --- a/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java @@ -176,7 +176,7 @@ public final class ArrayPtg extends Ptg { return ((Double)o).toString(); } if (o instanceof Boolean) { - ((Boolean)o).toString(); + return ((Boolean)o).booleanValue() ? "TRUE" : "FALSE"; } if (o instanceof ErrorConstant) { return ((ErrorConstant)o).getText(); diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java index 2ba27e963b..14bcde38b3 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java @@ -102,7 +102,7 @@ public final class TestArrayPtg extends TestCase { public void testElementOrderingInSpreadsheet() { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex42564-elementOrder.xls"); - // The formula has an array with 3 rows and 5 column + // The formula has an array with 3 rows and 5 columns String formula = wb.getSheetAt(0).getRow(0).getCell((short)0).getCellFormula(); // TODO - These number literals should not have '.0'. Excel has different number rendering rules @@ -111,4 +111,21 @@ public final class TestArrayPtg extends TestCase { } assertEquals("SUM({1.0,2.0,3.0;4.0,5.0,6.0;7.0,8.0,9.0;10.0,11.0,12.0;13.0,14.0,15.0})", formula); } + + public void testToFormulaString() { + ArrayPtg ptg = new ArrayPtg(new TestcaseRecordInputStream(ArrayPtg.sid, ENCODED_PTG_DATA)); + + ptg.readTokenValues(new TestcaseRecordInputStream(0, ENCODED_CONSTANT_DATA)); + + String actualFormula; + try { + actualFormula = ptg.toFormulaString(null); + } catch (IllegalArgumentException e) { + if (e.getMessage().equals("Unexpected constant class (java.lang.Boolean)")) { + throw new AssertionFailedError("Identified bug 45380"); + } + throw e; + } + assertEquals("{TRUE,\"ABCD\";\"E\",0.0;FALSE,\"FG\"}", actualFormula); + } }