poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1598258 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/HSSFCell.java testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
Date Thu, 29 May 2014 11:39:50 GMT
Author: nick
Date: Thu May 29 11:39:50 2014
New Revision: 1598258

URL: http://svn.apache.org/r1598258
Log:
HSSFCell should follow XSSF, and allow setting a null-style to return to the default style,
fixes bug #56572

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java?rev=1598258&r1=1598257&r2=1598258&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java Thu May 29 11:39:50 2014
@@ -899,7 +899,13 @@ public class HSSFCell implements Cell {
         setCellStyle( (HSSFCellStyle)style );
     }
     public void setCellStyle(HSSFCellStyle style) {
-        // Verify it really does belong to our workbook
+        // A style of null means resetting back to the default style
+        if (style == null) {
+            _record.setXFIndex((short)0xf);
+            return;
+        }
+
+        // Verify the style really does belong to our workbook
         style.verifyBelongsToWorkbook(_book);
 
         short styleIndex;

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java?rev=1598258&r1=1598257&r2=1598258&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java Thu May 29 11:39:50
2014
@@ -459,4 +459,40 @@ public final class TestHSSFCell extends 
         cell.setCellValue((String)null);
         cell.setCellValue((RichTextString)null);
     }
+    
+    public void testSetRemoveStyle() throws Exception {
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sheet = wb.createSheet();
+        HSSFRow row = sheet.createRow(0);
+        HSSFCell cell = row.createCell(0);
+        
+        HSSFCellStyle defaultStyle = wb.getCellStyleAt((short)15);
+        
+        // Starts out with the default style
+        assertEquals(defaultStyle, cell.getCellStyle());
+        
+        // Create some styles, no change
+        HSSFCellStyle style1 = wb.createCellStyle();
+        HSSFCellStyle style2 = wb.createCellStyle();
+        style1.setDataFormat((short)2);
+        style2.setDataFormat((short)3);
+        
+        assertEquals(defaultStyle, cell.getCellStyle());
+        
+        // Apply one, changes
+        cell.setCellStyle(style1);
+        assertEquals(style1, cell.getCellStyle());
+        
+        // Apply the other, changes
+        cell.setCellStyle(style2);
+        assertEquals(style2, cell.getCellStyle());
+        
+        // Remove, goes back to default
+        cell.setCellStyle(null);
+        assertEquals(defaultStyle, cell.getCellStyle());
+        
+        // Add back, returns
+        cell.setCellStyle(style2);
+        assertEquals(style2, cell.getCellStyle());
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message