From 15a46deae0a0c52056ec19b74193fe71ffccfed7 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Sat, 30 May 2009 10:37:08 +0000 Subject: [PATCH] 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 --- src/documentation/content/xdocs/status.xml | 1 + .../apache/poi/xssf/usermodel/XSSFCell.java | 2 +- .../poi/xssf/usermodel/TestXSSFCell.java | 27 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 568963351..dc160de51 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 63a3d8081..e817553a4 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 40a937b11..a5abde4ad 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