avik 2003/08/30 23:19:41
Modified: src/java/org/apache/poi/hssf/record/aggregates
FormulaRecordAggregate.java
src/java/org/apache/poi/hssf/usermodel HSSFCell.java
src/testcases/org/apache/poi/hssf/usermodel
TestFormulas.java
Log:
Sync to REL_2_BR: HSSFCell.getStringValue now returns the formula result if it is a
string.
Revision Changes Path
1.7 +5 -0
jakarta-poi/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java
Index: FormulaRecordAggregate.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FormulaRecordAggregate.java 27 Jul 2003 19:15:15 -0000 1.6
+++ FormulaRecordAggregate.java 31 Aug 2003 06:19:41 -0000 1.7
@@ -266,5 +266,10 @@
return true;
}
+
+ public String getStringValue() {
+ if(stringRecord==null) return null;
+ return stringRecord.getString();
+ }
}
1.25 +6 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
Index: HSSFCell.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- HSSFCell.java 31 Aug 2003 06:16:57 -0000 1.24
+++ HSSFCell.java 31 Aug 2003 06:19:41 -0000 1.25
@@ -338,6 +338,7 @@
case CELL_TYPE_FORMULA :
cellValue = (( FormulaRecordAggregate )
cval).getFormulaRecord().getValue();
+ stringValue=((FormulaRecordAggregate) cval).getStringValue();
break;
case CELL_TYPE_BOOLEAN :
@@ -820,6 +821,7 @@
/**
* get the value of the cell as a string - for numeric cells we throw an
exception.
* For blank cells we return an empty string.
+ * For formulaCells that are not string Formulas, we return empty String
*/
public String getStringCellValue()
@@ -842,6 +844,10 @@
{
throw new NumberFormatException(
"You cannot get a string value from an error cell");
+ }
+ if (cellType == CELL_TYPE_FORMULA)
+ {
+ if (stringValue==null) return "";
}
return stringValue;
}
1.32 +14 -0
jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
Index: TestFormulas.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- TestFormulas.java 31 Aug 2003 06:16:57 -0000 1.31
+++ TestFormulas.java 31 Aug 2003 06:19:41 -0000 1.32
@@ -1106,6 +1106,20 @@
assertEquals(4d, d2.getNumericCellValue(), 1e-9);
}
+ public void testStringFormulaRead() throws IOException {
+ File dir = new File(System.getProperty("HSSF.testdata.path"));
+ File xls = new File(dir, "StringFormulas.xls");
+ FileInputStream in = new FileInputStream(xls);
+ HSSFWorkbook w;
+ try {
+ w = new HSSFWorkbook(in);
+ } finally {
+ in.close();
+ }
+ HSSFCell c = w.getSheetAt(0).getRow(0).getCell((short)0);
+ assertEquals("String Cell value","XYZ",c.getStringCellValue());
+ }
+
public static void main(String [] args) {
System.out
.println("Testing org.apache.poi.hssf.usermodel.TestFormulas");
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]