From: Yegor Kozlov Date: Sat, 30 May 2009 10:37:08 +0000 (+0000) Subject: Fixed XSSFCell to avoid generating xsi:nil entries in shared string table X-Git-Tag: REL_3_5_BETA6~6 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=23ddda6853b8b71d4b542eed52175e11e851f6ad;p=poi.git Fixed XSSFCell to avoid generating xsi:nil entries in shared string table git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@780228 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 5689633510..dc160de51d 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 47278 - Fixed XSSFCell to avoid generating xsi:nil entries in shared string table 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 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 63a3d80813..e817553a4c 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -293,7 +293,7 @@ public final class XSSFCell implements Cell { * If value is null then we will change the cell to a Blank cell. */ public void setCellValue(RichTextString str) { - if(str == null){ + if(str == null || str.getString() == null){ setBlank(); return; } 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 40a937b110..a5abde4adc 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.apache.poi.xssf.model.SharedStringsTable; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType; /** @@ -79,4 +80,30 @@ public final class TestXSSFCell extends BaseTestCell { assertTrue(cell_2.getCTCell().isSetIs()); assertEquals("bar", row.getCell(2).getStringCellValue()); } + + /** + * Bug 47278 - xsi:nil attribute for tag caused Excel 2007 to fail to open workbook + */ + public void test47278() throws Exception { + XSSFWorkbook wb = (XSSFWorkbook)_testDataProvider.createWorkbook(); + XSSFSheet sheet = wb.createSheet(); + XSSFRow row = sheet.createRow(0); + SharedStringsTable sst = wb.getSharedStringSource(); + assertEquals(0, sst.getCount()); + + //case 1. cell.setCellValue(new XSSFRichTextString((String)null)); + XSSFCell cell_0 = row.createCell(0); + XSSFRichTextString str = new XSSFRichTextString((String)null); + assertNull(str.getString()); + cell_0.setCellValue(str); + assertEquals(0, sst.getCount()); + assertEquals(XSSFCell.CELL_TYPE_BLANK, cell_0.getCellType()); + + //case 2. cell.setCellValue((String)null); + XSSFCell cell_1 = row.createCell(1); + cell_1.setCellValue((String)null); + assertEquals(0, sst.getCount()); + assertEquals(XSSFCell.CELL_TYPE_BLANK, cell_1.getCellType()); + } + } \ No newline at end of file