aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2009-05-23 08:20:55 +0000
committerYegor Kozlov <yegor@apache.org>2009-05-23 08:20:55 +0000
commite4599a03ae95a9e1f70ffa0f47da694650b3c392 (patch)
treed92b75a03a7f65b590e157f2fe445ac6b08b1184 /src
parentb61446ecb01c1a69e2e7453c3f40741141f9e202 (diff)
downloadpoi-e4599a03ae95a9e1f70ffa0f47da694650b3c392.tar.gz
poi-e4599a03ae95a9e1f70ffa0f47da694650b3c392.zip
Fixed XSSFCell to properly read inline strings
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@777834 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/documentation/content/xdocs/changes.xml1
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java18
-rwxr-xr-xsrc/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java29
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/data/xlsx-jdbc.xlsxbin0 -> 3072 bytes
5 files changed, 45 insertions, 4 deletions
diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml
index 939ab49263..b79dac6509 100644
--- a/src/documentation/content/xdocs/changes.xml
+++ b/src/documentation/content/xdocs/changes.xml
@@ -37,6 +37,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.5-beta6" date="2009-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">47206 - Fixed XSSFCell to properly read inline strings</action>
<action dev="POI-DEVELOPERS" type="add">47250 - Fixed FontRecord to expect unicode flags even when name length is zero</action>
<action dev="POI-DEVELOPERS" type="add">47198 - Fixed formula evaluator comparison of -0.0 and 0.0</action>
<action dev="POI-DEVELOPERS" type="add">47229 - Fixed ExternalNameRecord to handle DDE links</action>
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index 481dce9d50..5689633510 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.5-beta6" date="2009-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">47206 - Fixed XSSFCell to properly read inline strings</action>
<action dev="POI-DEVELOPERS" type="add">47250 - Fixed FontRecord to expect unicode flags even when name length is zero</action>
<action dev="POI-DEVELOPERS" type="add">47198 - Fixed formula evaluator comparison of -0.0 and 0.0</action>
<action dev="POI-DEVELOPERS" type="add">47229 - Fixed ExternalNameRecord to handle DDE links</action>
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 3143037430..63a3d80813 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
@@ -242,14 +242,24 @@ public final class XSSFCell implements Cell {
rt = new XSSFRichTextString("");
break;
case CELL_TYPE_STRING:
- if (!cell.isSetV()) rt = new XSSFRichTextString("");
- else {
- if (cell.getT() == STCellType.INLINE_STR) {
- return new XSSFRichTextString(cell.getV());
+ if (cell.getT() == STCellType.INLINE_STR) {
+ if(cell.isSetIs()) {
+ //string is expressed directly in the cell definition instead of implementing the shared string table.
+ rt = new XSSFRichTextString(cell.getIs());
+ } else if (cell.isSetV()) {
+ //cached result of a formula
+ rt = new XSSFRichTextString(cell.getV());
} else {
+ rt = new XSSFRichTextString("");
+ }
+ } else {
+ if (cell.isSetV()) {
int idx = Integer.parseInt(cell.getV());
rt = new XSSFRichTextString(sharedStringSource.getEntryAt(idx));
}
+ else {
+ rt = new XSSFRichTextString("");
+ }
}
break;
case CELL_TYPE_FORMULA:
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
index f97a6d1b81..40a937b110 100755
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
@@ -19,6 +19,7 @@ package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType;
/**
* @author Yegor Kozlov
@@ -50,4 +51,32 @@ public final class TestXSSFCell extends BaseTestCell {
cell.setCellFormula(null);
cell.setCellValue("456");
}
+
+ /**
+ * Test that we can read inline strings that are expressed directly in the cell definition
+ * instead of implementing the shared string table.
+ *
+ * Some programs, for example, Microsoft Excel Driver for .xlsx insert inline string
+ * instead of using the shared string table. See bug 47206
+ */
+ public void testInlineString() throws Exception {
+ XSSFWorkbook wb = (XSSFWorkbook)_testDataProvider.openSampleWorkbook("xlsx-jdbc.xlsx");
+ XSSFSheet sheet = wb.getSheetAt(0);
+ XSSFRow row = sheet.getRow(1);
+
+ XSSFCell cell_0 = row.getCell(0);
+ assertEquals(STCellType.INT_INLINE_STR, cell_0.getCTCell().getT().intValue());
+ assertTrue(cell_0.getCTCell().isSetIs());
+ assertEquals("A Very large string in column 1 AAAAAAAAAAAAAAAAAAAAA", cell_0.getStringCellValue());
+
+ XSSFCell cell_1 = row.getCell(1);
+ assertEquals(STCellType.INT_INLINE_STR, cell_1.getCTCell().getT().intValue());
+ assertTrue(cell_1.getCTCell().isSetIs());
+ assertEquals("foo", cell_1.getStringCellValue());
+
+ XSSFCell cell_2 = row.getCell(2);
+ assertEquals(STCellType.INT_INLINE_STR, cell_2.getCTCell().getT().intValue());
+ assertTrue(cell_2.getCTCell().isSetIs());
+ assertEquals("bar", row.getCell(2).getStringCellValue());
+ }
} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/hssf/data/xlsx-jdbc.xlsx b/src/testcases/org/apache/poi/hssf/data/xlsx-jdbc.xlsx
new file mode 100755
index 0000000000..d9823b428e
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/data/xlsx-jdbc.xlsx
Binary files differ