aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2011-04-21 13:22:18 +0000
committerNick Burch <nick@apache.org>2011-04-21 13:22:18 +0000
commit11a75497e546c6f190fa684681b36f5e1e475aad (patch)
tree188bd053cc3f1ec59db3f4a518ce68347c654c0c /src/ooxml/java
parentf7ed387745d7c9fe324f0be285a172277aa12a0c (diff)
downloadpoi-11a75497e546c6f190fa684681b36f5e1e475aad.tar.gz
poi-11a75497e546c6f190fa684681b36f5e1e475aad.zip
Fix bug #50956 - Correct XSSF cell style cloning between workbooks
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1095695 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java7
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java12
2 files changed, 19 insertions, 0 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
index e643f9fa1f..3a2e87903c 100644
--- a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
+++ b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
@@ -297,6 +297,9 @@ public class StylesTable extends POIXMLDocumentPart {
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 POIXMLDocumentPart {
styleXfs.add(cellStyleXf);
return styleXfs.size();
}
+ public void replaceCellStyleXfAt(int idx, CTXf cellStyleXf) {
+ styleXfs.set(idx, cellStyleXf);
+ }
+
/**
* get the size of cell styles
*/
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
index 55590a2b42..86a8aac235 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
@@ -33,6 +33,8 @@ import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
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 CellStyle {
} 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);
}