aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2015-12-04 14:39:07 +0000
committerDominik Stadler <centic@apache.org>2015-12-04 14:39:07 +0000
commit2515c081a6ac30e34cb57dbcac8b3f8f00a907c2 (patch)
tree278a13cddd89930afd30ec93a948e24c18794558 /src/ooxml
parent1f5c49b68bbfa555fc59775eae3e51b7740517d8 (diff)
downloadpoi-2515c081a6ac30e34cb57dbcac8b3f8f00a907c2.tar.gz
poi-2515c081a6ac30e34cb57dbcac8b3f8f00a907c2.zip
Bug 58084: Fix cloning Cell Styles with Borders
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1717973 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java13
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java44
2 files changed, 57 insertions, 0 deletions
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 93798d1b53..15b3e76973 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
@@ -164,6 +164,12 @@ public class XSSFCellStyle implements CellStyle {
);
addFill(fill);
+ // bug 58084: set borders correctly
+ CTBorder border = CTBorder.Factory.parse(
+ src.getCTBorder().toString(), DEFAULT_XML_OPTIONS
+ );
+ addBorder(border);
+
// Swap it over
_stylesSource.replaceCellXfAt(_cellXfId, _cellXf);
} catch(XmlException e) {
@@ -203,6 +209,13 @@ public class XSSFCellStyle implements CellStyle {
_cellXf.setFillId(idx);
_cellXf.setApplyFill(true);
}
+
+ private void addBorder(CTBorder border) {
+ int idx = _stylesSource.putBorder(new XSSFCellBorder(border, _theme));
+
+ _cellXf.setBorderId(idx);
+ _cellXf.setApplyBorder(true);
+ }
/**
* Get the type of horizontal alignment for the cell
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
index 78b624fd68..eb439bc476 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
@@ -1017,4 +1017,48 @@ public class TestXSSFCellStyle {
wb.close();
}
+
+ public static void copyStyles(Workbook reference, Workbook target) {
+ final short numberOfStyles = reference.getNumCellStyles();
+ for (short i = 0; i < numberOfStyles; i++) {
+ final CellStyle referenceStyle = reference.getCellStyleAt(i);
+ if (i == 0) {
+ continue;
+ }
+ final CellStyle targetStyle = target.createCellStyle();
+ targetStyle.cloneStyleFrom(referenceStyle);
+ }
+ /*System.out.println("Reference : "+reference.getNumCellStyles());
+ System.out.println("Target : "+target.getNumCellStyles());*/
+ }
+
+ @Test
+ public void test58084() throws IOException {
+ Workbook reference = XSSFTestDataSamples.openSampleWorkbook("template.xlsx");
+ Workbook target = new XSSFWorkbook();
+ copyStyles(reference, target);
+
+ assertEquals(reference.getNumCellStyles(), target.getNumCellStyles());
+ final Sheet sheet = target.createSheet();
+ final Row row = sheet.createRow(0);
+ int col = 0;
+ for (short i = 1; i < target.getNumCellStyles(); i++) {
+ final Cell cell = row.createCell(col++);
+ cell.setCellValue("Coucou"+i);
+ cell.setCellStyle(target.getCellStyleAt(i));
+ }
+ /*OutputStream out = new FileOutputStream("C:\\temp\\58084.xlsx");
+ target.write(out);
+ out.close();*/
+
+ Workbook copy = XSSFTestDataSamples.writeOutAndReadBack(target);
+
+ // previously this failed because the border-element was not copied over
+ copy.getCellStyleAt((short)1).getBorderBottom();
+
+ copy.close();
+
+ target.close();
+ reference.close();
+ }
}