<!-- Don't forget to update status.xml too! -->
<release version="3.5-beta6" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">fixed Sheet.autoSizeColumn() to use cached formula values when processing formula cells </action>
<action dev="POI-DEVELOPERS" type="fix">Fixed formula parser to handle names with backslashes</action>
<action dev="POI-DEVELOPERS" type="add">46660 - added Workbook getHidden() and setHidden(boolean)</action>
<action dev="POI-DEVELOPERS" type="fix">46693 - Fixed bugs serialization bugs in records: CHARTFORMAT, SHTPROPS, SXVD and SXVDEX</action>
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.5-beta6" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">fixed Sheet.autoSizeColumn() to use cached formula values when processing formula cells </action>
<action dev="POI-DEVELOPERS" type="fix">Fixed formula parser to handle names with backslashes</action>
<action dev="POI-DEVELOPERS" type="add">46660 - added Workbook getHidden() and setHidden(boolean)</action>
<action dev="POI-DEVELOPERS" type="fix">46693 - Fixed bugs serialization bugs in records: CHARTFORMAT, SHTPROPS, SXVD and SXVDEX</action>
}
HSSFCellStyle style = cell.getCellStyle();
+ int cellType = cell.getCellType();
+ if(cellType == HSSFCell.CELL_TYPE_FORMULA) cellType = cell.getCachedFormulaResultType();
+
HSSFFont font = wb.getFontAt(style.getFontIndex());
- if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
+ if (cellType == HSSFCell.CELL_TYPE_STRING) {
HSSFRichTextString rt = cell.getRichStringCellValue();
String[] lines = rt.getString().split("\\n");
for (int i = 0; i < lines.length; i++) {
}
} else {
String sval = null;
- if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
- String format = style.getDataFormatString().replaceAll("\"", "");
+ if (cellType == HSSFCell.CELL_TYPE_NUMERIC) {
+ String dfmt = style.getDataFormatString();
+ String format = dfmt == null ? null : dfmt.replaceAll("\"", "");
double value = cell.getNumericCellValue();
try {
NumberFormat fmt;
} catch (Exception e) {
sval = "" + value;
}
- } else if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN) {
+ } else if (cellType == HSSFCell.CELL_TYPE_BOOLEAN) {
sval = String.valueOf(cell.getBooleanCellValue());
}
if(sval != null) {
*/
int getCellType();
+ /**
+ * Only valid for formula cells
+ * @return one of ({@link #CELL_TYPE_NUMERIC}, {@link #CELL_TYPE_STRING},
+ * {@link #CELL_TYPE_BOOLEAN}, {@link #CELL_TYPE_ERROR}) depending
+ * on the cached value of the formula
+ */
+ int getCachedFormulaResultType();
+
/**
* Set a numeric value for the cell
*
return CELL_TYPE_FORMULA;
}
- switch (this.cell.getT().intValue()) {
+ return getBaseCellType();
+ }
+
+ /**
+ * Only valid for formula cells
+ * @return one of ({@link #CELL_TYPE_NUMERIC}, {@link #CELL_TYPE_STRING},
+ * {@link #CELL_TYPE_BOOLEAN}, {@link #CELL_TYPE_ERROR}) depending
+ * on the cached value of the formula
+ */
+ public int getCachedFormulaResultType() {
+ if (cell.getF() == null) {
+ throw new IllegalStateException("Only formula cells have cached results");
+ }
+
+ return getBaseCellType();
+ }
+
+ /**
+ * Detect cell type based on the "t" attribute of the CTCell bean
+ */
+ private int getBaseCellType() {
+ switch (cell.getT().intValue()) {
case STCellType.INT_B:
return CELL_TYPE_BOOLEAN;
case STCellType.INT_N:
}
XSSFCellStyle style = cell.getCellStyle();
+ int cellType = cell.getCellType();
+ if(cellType == XSSFCell.CELL_TYPE_FORMULA) cellType = cell.getCachedFormulaResultType();
XSSFFont font = wb.getFontAt(style.getFontIndex());
- if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) {
+ if (cellType == XSSFCell.CELL_TYPE_STRING) {
XSSFRichTextString rt = cell.getRichStringCellValue();
String[] lines = rt.getString().split("\\n");
for (int i = 0; i < lines.length; i++) {
}
} else {
String sval = null;
- if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
- String format = style.getDataFormatString().replaceAll("\"", "");
+ if (cellType == XSSFCell.CELL_TYPE_NUMERIC) {
+ String dfmt = style.getDataFormatString();
+ String format = dfmt == null ? null : dfmt.replaceAll("\"", "");
double value = cell.getNumericCellValue();
try {
NumberFormat fmt;
} catch (Exception e) {
sval = "" + value;
}
- } else if (cell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) {
+ } else if (cellType == XSSFCell.CELL_TYPE_BOOLEAN) {
sval = String.valueOf(cell.getBooleanCellValue());
}
if(sval != null) {