case CELL_TYPE_FORMULA :
cellValue = (( FormulaRecordAggregate ) cval).getFormulaRecord().getValue();
+ stringValue=((FormulaRecordAggregate) cval).getStringValue();
break;
case CELL_TYPE_BOOLEAN :
/**
* 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()
throw new NumberFormatException(
"You cannot get a string value from an error cell");
}
+ if (cellType == CELL_TYPE_FORMULA)
+ {
+ if (stringValue==null) return "";
+ }
return stringValue;
}
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");