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 2011/04/21 15:22:18 UTC

svn commit: r1095695 - in /poi/trunk/src: documentation/content/xdocs/ ooxml/java/org/apache/poi/xssf/model/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/xssf/usermodel/

Author: nick
Date: Thu Apr 21 13:22:18 2011
New Revision: 1095695

URL: http://svn.apache.org/viewvc?rev=1095695&view=rev
Log:
Fix bug #50956 - Correct XSSF cell style cloning between workbooks

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1095695&r1=1095694&r2=1095695&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Apr 21 13:22:18 2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta3" date="2011-??-??">
+           <action dev="poi-developers" type="fix">50956 - Correct XSSF cell style cloning between workbooks</action>
            <action dev="poi-developers" type="add">Add get/setForceFormulaRecalculation for XSSF, and promote the methods to the common usermodel Sheet</action>
            <action dev="poi-developers" type="fix">Tweak the logic for sizing the HSSFCells array on a HSSFRow to reduce memory over allocation in many use cases</action>
            <action dev="poi-developers" type="add">49765 - Support for adding a picture to a XSSFRun</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java?rev=1095695&r1=1095694&r2=1095695&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java Thu Apr 21 13:22:18 2011
@@ -297,6 +297,9 @@ public class StylesTable extends POIXMLD
 		xfs.add(cellXf);
 		return xfs.size();
 	}
+   public void replaceCellXfAt(int idx, CTXf cellXf) {
+      xfs.set(idx, cellXf);
+   }
 
 	public CTXf getCellStyleXfAt(int idx) {
 		return styleXfs.get(idx);
@@ -305,6 +308,10 @@ public class StylesTable extends POIXMLD
 		styleXfs.add(cellStyleXf);
 		return styleXfs.size();
 	}
+	public void replaceCellStyleXfAt(int idx, CTXf cellStyleXf) {
+	   styleXfs.set(idx, cellStyleXf);
+	}
+	
 	/**
 	 * get the size of cell styles
 	 */

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java?rev=1095695&r1=1095694&r2=1095695&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java Thu Apr 21 13:22:18 2011
@@ -33,6 +33,8 @@ import org.apache.poi.xssf.usermodel.ext
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide;
 import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlToken;
+import org.w3c.dom.Node;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellAlignment;
@@ -144,9 +146,19 @@ public class XSSFCellStyle implements Ce
             } else {
                // Copy the style
                try {
+                  // Remove any children off the current style, to
+                  //  avoid orphaned nodes
+                  if(_cellXf.isSetAlignment())
+                     _cellXf.unsetAlignment();
+                  if(_cellXf.isSetExtLst())
+                     _cellXf.unsetExtLst();
+                  
+                  // Create a new Xf with the same contents
                   _cellXf = CTXf.Factory.parse(
                         src.getCoreXf().toString()
                   );
+                  // Swap it over
+                  _stylesSource.replaceCellXfAt(_cellXfId, _cellXf);
                } catch(XmlException e) {
                   throw new POIXMLException(e);
                }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java?rev=1095695&r1=1095694&r2=1095695&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java Thu Apr 21 13:22:18 2011
@@ -25,6 +25,7 @@ import org.apache.poi.ss.usermodel.CellS
 import org.apache.poi.ss.usermodel.HorizontalAlignment;
 import org.apache.poi.ss.usermodel.IndexedColors;
 import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.model.StylesTable;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
@@ -656,6 +657,7 @@ public class TestXSSFCellStyle extends T
        XSSFWorkbook wbClone = new XSSFWorkbook();
        assertEquals(1, wbClone.getNumberOfFonts());
        assertEquals(0, wbClone.getStylesSource().getNumberFormats().size());
+       assertEquals(1, wbClone.getNumCellStyles());
        
        XSSFDataFormat fmtClone = wbClone.createDataFormat();
        XSSFCellStyle clone = wbClone.createCellStyle();
@@ -669,11 +671,24 @@ public class TestXSSFCellStyle extends T
        clone.cloneStyleFrom(orig);
        
        assertEquals(2, wbClone.getNumberOfFonts());
+       assertEquals(2, wbClone.getNumCellStyles());
        assertEquals(1, wbClone.getStylesSource().getNumberFormats().size());
        
        assertEquals(HSSFCellStyle.ALIGN_RIGHT, clone.getAlignment());
        assertEquals("TestingFont", clone.getFont().getFontName());
        assertEquals(fmtClone.getFormat("Test##"), clone.getDataFormat());
        assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##"));
+       
+       // Save it and re-check
+       XSSFWorkbook wbReload = XSSFTestDataSamples.writeOutAndReadBack(wbClone);
+       assertEquals(2, wbReload.getNumberOfFonts());
+       assertEquals(2, wbReload.getNumCellStyles());
+       assertEquals(1, wbReload.getStylesSource().getNumberFormats().size());
+       
+       XSSFCellStyle reload = wbReload.getCellStyleAt((short)1);
+       assertEquals(HSSFCellStyle.ALIGN_RIGHT, reload.getAlignment());
+       assertEquals("TestingFont", reload.getFont().getFontName());
+       assertEquals(fmtClone.getFormat("Test##"), reload.getDataFormat());
+       assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##"));
    }
 }



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