From 9eff4e10b36d171ed5a33771066b779604897aff Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Fri, 17 Apr 2009 18:02:01 +0000 Subject: [PATCH] Fixed XSSFCell to preserve cell style when cell value is set to blank, also avoid NPE in XSSFCell.setCellType() when workbook does not have SST, see bugs 47026 and 47028 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@766103 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/changes.xml | 2 ++ src/documentation/content/xdocs/status.xml | 2 ++ .../apache/poi/xssf/usermodel/XSSFCell.java | 1 + .../poi/xssf/usermodel/XSSFWorkbook.java | 10 ++++---- .../poi/xssf/usermodel/TestXSSFCell.java | 24 +++++++++++++++++- .../org/apache/poi/hssf/data/47026.xlsm | Bin 0 -> 8203 bytes .../apache/poi/ss/usermodel/BaseTestCell.java | 19 +++++++++++--- 7 files changed, 49 insertions(+), 9 deletions(-) create mode 100755 src/testcases/org/apache/poi/hssf/data/47026.xlsm diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 4a1d8116cc..f58747e7ed 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,8 @@ + 47028 - Fixed XSSFCell to preserve cell style when cell value is set to blank + 47026 - Avoid NPE in XSSFCell.setCellType() when workbook does not have SST 46987 - Allow RecordFactory to handle non-zero padding at the end of the workbook stream 47034 - Fix reading the name of a NameRecord when the name is very long 47001 - Fixed WriteAccessRecord and LinkTable to handle unusual format written by Google Docs diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 7564d7d259..4ef245ad87 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,8 @@ + 47028 - Fixed XSSFCell to preserve cell style when cell value is set to blank + 47026 - Avoid NPE in XSSFCell.setCellType() when workbook does not have SST 46987 - Allow RecordFactory to handle non-zero padding at the end of the workbook stream 47034 - Fix reading the name of a NameRecord when the name is very long 47001 - Fixed WriteAccessRecord and LinkTable to handle unusual format written by Google Docs 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 f0ad410adf..2a0e1ff4b2 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -627,6 +627,7 @@ public final class XSSFCell implements Cell { private void setBlank(){ CTCell blank = CTCell.Factory.newInstance(); blank.setR(cell.getR()); + blank.setS(cell.getS()); cell.set(blank); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 9cb66c5311..1648ac86f3 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -179,6 +179,11 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable(shIdMap.size()); for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) { @@ -192,11 +197,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable(); if(workbook.isSetDefinedNames()) { 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 b851d8827e..f97a6d1b81 100755 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java @@ -17,7 +17,7 @@ package org.apache.poi.xssf.usermodel; -import org.apache.poi.ss.usermodel.BaseTestCell; +import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.XSSFITestDataProvider; /** @@ -28,4 +28,26 @@ public final class TestXSSFCell extends BaseTestCell { public TestXSSFCell() { super(XSSFITestDataProvider.getInstance()); } + + /** + * Bug 47026: trouble changing cell type when workbook doesn't contain + * Shared String Table + */ + public void test47026_1() throws Exception { + Workbook source = _testDataProvider.openSampleWorkbook("47026.xlsm"); + Sheet sheet = source.getSheetAt(0); + Row row = sheet.getRow(0); + Cell cell = row.getCell(0); + cell.setCellType(Cell.CELL_TYPE_STRING); + cell.setCellValue("456"); + } + + public void test47026_2() throws Exception { + Workbook source = _testDataProvider.openSampleWorkbook("47026.xlsm"); + Sheet sheet = source.getSheetAt(0); + Row row = sheet.getRow(0); + Cell cell = row.getCell(0); + cell.setCellFormula(null); + cell.setCellValue("456"); + } } \ No newline at end of file diff --git a/src/testcases/org/apache/poi/hssf/data/47026.xlsm b/src/testcases/org/apache/poi/hssf/data/47026.xlsm new file mode 100755 index 0000000000000000000000000000000000000000..77e4eb97f31cb0fb89fff05029eeeab14aacf0f2 GIT binary patch literal 8203 zcmeHMcTiK?_D-nMizqd82wgfzM^GX3-UJODrPm-u>7hxHUZvM49i#^k1O!1kkt!fa zS3s)#g7>}gUaoKE{r!G-XU;j3$@y0H?Deg+zP+}l3MLi>00(dd001xnq9qFO{DA;K zAT|JS6)+1lQE+l}w{mp9uj}n>H=loNcF7YAo;Ys)P#=13b@zxfnbe@2Dj74OBlC^i+lkJJ+4KQYD4;z3XNl9V8&! z+qI*4XI3XL_7>u;LRv(o81|_ zV<`Lx_t91Y-e-5F+l!3AV=GX8=Y))LM)Wi+by#a(n%lsW8+xpsK);cx_KO>3yI2!mrHuI zuFRQV@5Uk{%ppNx{c2~l(N2TF3FJEcg<3a^NOD$Wbb(8=l0|7J=P6&N&PUzaX{$UM z?{74wh=mF)kpF!gu=~gJtDuRwwz*}dkfiF2#&110-5dN)RwXzQVg1+}PIl6Mx#7)6 zLF%n&9-W_K0yO^;jJ10FEc@tRRMD|U02l<`ceS#2yTNyHXUy&UCkX#%f-frmy?Q4< zVfVIDv%=EJ7e}QlIR#CsN=;0<^zE!$47JgDta9HEf-wUj7O3Ha&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