From e4599a03ae95a9e1f70ffa0f47da694650b3c392 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Sat, 23 May 2009 08:20:55 +0000 Subject: [PATCH] Fixed XSSFCell to properly read inline strings git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@777834 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/changes.xml | 1 + src/documentation/content/xdocs/status.xml | 1 + .../apache/poi/xssf/usermodel/XSSFCell.java | 18 ++++++++--- .../poi/xssf/usermodel/TestXSSFCell.java | 29 ++++++++++++++++++ .../org/apache/poi/hssf/data/xlsx-jdbc.xlsx | Bin 0 -> 3072 bytes 5 files changed, 45 insertions(+), 4 deletions(-) create mode 100755 src/testcases/org/apache/poi/hssf/data/xlsx-jdbc.xlsx 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 @@ + 47206 - Fixed XSSFCell to properly read inline strings 47250 - Fixed FontRecord to expect unicode flags even when name length is zero 47198 - Fixed formula evaluator comparison of -0.0 and 0.0 47229 - Fixed ExternalNameRecord to handle DDE links 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 @@ + 47206 - Fixed XSSFCell to properly read inline strings 47250 - Fixed FontRecord to expect unicode flags even when name length is zero 47198 - Fixed formula evaluator comparison of -0.0 and 0.0 47229 - Fixed ExternalNameRecord to handle DDE links 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 0000000000000000000000000000000000000000..d9823b428e7c427c262b323127dcc66240527456 GIT binary patch literal 3072 zcmaJ@2|Sc*7axWh+qD#$7TIOF*+~tf(kOR_vm`XJU8AkHGQ=iN2E@yu8zVG~=_ndjo|NNi-ITk1|mnet__*`_YKL*-i z{J^tI2qplprpmsirMLODs|zI1Blsv$l-fiM;{xZdoAnxv(1iebjpW0!QI5ljU7hbN^1RPH)L= zXh(oIpF(|s;z;+iU1s-6%yLtmdQUx?Z-i&#Ap&WZd(fdl`(~!=ZvO0&9N4y`7m2zW z@Ef>uv7c<1Vydfo{zcqfF++Ruk-3rw*1wiTgw@j;VpJi@U3u;UH3JGJp(sXnzs%9P z{)a`ea;>)_n~56((O?S{lt-a1|Ir|j=r0@~ki|bju^V{9(FhkvzyuOptRsRjcqdgN zHsC>4&)If$VI*^nug6ie2}2S#9p}C(Z(ST67p#zG(>fE3T4$PBP8FA&aY`$1!1sSb zSKQg}J+^OG{DtieisqRilk?U~ST0Yw74(uSjVLewPO#vlhz#*v zt@P2Hx4Gh)$}QIX=`_lV%P-r!7aDq7phcpoHb(~T=RAKOW>hEvCn5VP!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