aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java/org
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2009-02-19 17:29:55 +0000
committerYegor Kozlov <yegor@apache.org>2009-02-19 17:29:55 +0000
commit2ea123586aabe249b3a853ea2e7747b86cd28761 (patch)
tree3467fd57ee9257ad9e8714c61b9ae031affd5eb0 /src/ooxml/java/org
parent627105e288b7135c905d6724c0d9dd3ce77abc3b (diff)
downloadpoi-2ea123586aabe249b3a853ea2e7747b86cd28761.tar.gz
poi-2ea123586aabe249b3a853ea2e7747b86cd28761.zip
fixed autoSizeColumn() to use cached formula values when processing formula cells, see bug #46736
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@745937 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java/org')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java23
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java11
2 files changed, 29 insertions, 5 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
index 26fb2dc8a5..433b2c650c 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
@@ -466,7 +466,28 @@ public final class XSSFCell implements 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:
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java
index c796776f47..30da5efd42 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java
@@ -346,9 +346,11 @@ public class ColumnHelper {
}
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++) {
@@ -388,8 +390,9 @@ public class ColumnHelper {
}
} 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;
@@ -403,7 +406,7 @@ public class ColumnHelper {
} 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) {