You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2015/10/28 18:42:56 UTC
svn commit: r1711082 - in /poi/trunk/src:
ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
Author: nick
Date: Wed Oct 28 17:42:56 2015
New Revision: 1711082
URL: http://svn.apache.org/viewvc?rev=1711082&view=rev
Log:
#58558 SXSSFCell.setCellValue((RichTextString)null) fixed to work like XSSF and HSSF, with common unit tests to verify this
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java?rev=1711082&r1=1711081&r2=1711082&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java Wed Oct 28 17:42:56 2015
@@ -222,16 +222,21 @@ public class SXSSFCell implements Cell {
*/
public void setCellValue(RichTextString value)
{
- ensureRichTextStringType();
-
- if(value.length() > SpreadsheetVersion.EXCEL2007.getMaxTextLength()){
- throw new IllegalArgumentException("The maximum length of cell contents (text) is 32,767 characters");
- }
-
- ((RichTextValue)_value).setValue(value);
+ XSSFRichTextString xvalue = (XSSFRichTextString)value;
- if (((XSSFRichTextString)value).hasFormatting())
- logger.log(POILogger.WARN, "SXSSF doesn't support Shared Strings, rich text formatting information has be lost");
+ if (xvalue != null) {
+ ensureRichTextStringType();
+
+ if (xvalue.length() > SpreadsheetVersion.EXCEL2007.getMaxTextLength()) {
+ throw new IllegalArgumentException("The maximum length of cell contents (text) is 32,767 characters");
+ }
+ if (xvalue.hasFormatting())
+ logger.log(POILogger.WARN, "SXSSF doesn't support Shared Strings, rich text formatting information has be lost");
+
+ ((RichTextValue)_value).setValue(xvalue);
+ } else {
+ setCellType(CELL_TYPE_BLANK);
+ }
}
/**
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java?rev=1711082&r1=1711081&r2=1711082&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java Wed Oct 28 17:42:56 2015
@@ -767,7 +767,39 @@ public abstract class BaseTestCell {
wb1.close();
}
- private void checkUnicodeValues(Workbook wb) {
+ /**
+ * Setting a cell value of a null RichTextString should set
+ * the cell to Blank, test case for 58558
+ */
+ @Test
+ public void testSetCellValueNullRichTextString() throws IOException {
+ Workbook wb = _testDataProvider.createWorkbook();
+ Sheet sheet = wb.createSheet();
+ Cell cell = sheet.createRow(0).createCell(0);
+
+ RichTextString nullStr = null;
+ cell.setCellValue(nullStr);
+ assertEquals("", cell.getStringCellValue());
+ assertEquals(Cell.CELL_TYPE_BLANK, cell.getCellType());
+
+ cell = sheet.createRow(0).createCell(1);
+ cell.setCellValue(1.2d);
+ assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ cell.setCellValue(nullStr);
+ assertEquals("", cell.getStringCellValue());
+ assertEquals(Cell.CELL_TYPE_BLANK, cell.getCellType());
+
+ cell = sheet.createRow(0).createCell(1);
+ cell.setCellValue(wb.getCreationHelper().createRichTextString("Test"));
+ assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
+ cell.setCellValue(nullStr);
+ assertEquals("", cell.getStringCellValue());
+ assertEquals(Cell.CELL_TYPE_BLANK, cell.getCellType());
+
+ wb.close();
+ }
+
+ private void checkUnicodeValues(Workbook wb) {
assertEquals((wb instanceof HSSFWorkbook ? "row 0, cell 0 _x0046_ without changes" : "row 0, cell 0 F without changes"),
wb.getSheetAt(0).getRow(0).getCell(0).toString());
assertEquals((wb instanceof HSSFWorkbook ? "row 0, cell 1 _x005fx0046_ with changes" : "row 0, cell 1 _x005fx0046_ with changes"),
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org