You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2015/12/04 15:39:07 UTC
svn commit: r1717973 - in /poi:
site/src/documentation/content/xdocs/status.xml
trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
Author: centic
Date: Fri Dec 4 14:39:07 2015
New Revision: 1717973
URL: http://svn.apache.org/viewvc?rev=1717973&view=rev
Log:
Bug 58084: Fix cloning Cell Styles with Borders
Modified:
poi/site/src/documentation/content/xdocs/status.xml
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/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1717973&r1=1717972&r2=1717973&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Fri Dec 4 14:39:07 2015
@@ -40,6 +40,7 @@
</devs>
<release version="3.14-beta1" date="2015-11-??">
+ <action dev="PD" type="add" fixes-bug="58084">Corrupted .xlsx file created when styles with borders are cloned from other workbooks</action>
<action dev="PD" type="add" fixes-bug="58570">Promote setting and getting the active cell in a worksheet to Common SS</action>
<action dev="PD" type="add" fixes-bug="47904">Update text styles in HSLF MasterSlide</action>
<action dev="PD" type="add" fixes-bug="58670">Change underlying data structure in SXSSFRow to use a TreeMap instead of an array to store SXSSFCells</action>
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=1717973&r1=1717972&r2=1717973&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 Fri Dec 4 14:39:07 2015
@@ -164,6 +164,12 @@ public class XSSFCellStyle implements Ce
);
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 Ce
_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
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=1717973&r1=1717972&r2=1717973&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 Fri Dec 4 14:39:07 2015
@@ -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();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org