diff options
author | Dominik Stadler <centic@apache.org> | 2015-03-14 19:32:28 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2015-03-14 19:32:28 +0000 |
commit | 7764200fe27a136cf65fbd2fd272193d5e7a919e (patch) | |
tree | 04fa98685f1065c3e99c385270d6b58642212b3f /src/ooxml/testcases/org | |
parent | 1461cf947c6db725f8fbf8e20d3f281668029aa3 (diff) | |
download | poi-7764200fe27a136cf65fbd2fd272193d5e7a919e.tar.gz poi-7764200fe27a136cf65fbd2fd272193d5e7a919e.zip |
Bug 56295: Fix cloning of styles across workbooks and handling of default value of attribute applyFill
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1666736 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/testcases/org')
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java | 57 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java | 10 |
2 files changed, 65 insertions, 2 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index bb9efa4073..5caf72988f 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -31,6 +31,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import java.util.Calendar; import java.util.List; @@ -2308,4 +2309,60 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { // TODO Re-check sheet contents // TODO Re-check formula evaluation } + + @Test + public void testBug56295_MergeXlslsWithStyles() throws IOException { + XSSFWorkbook xlsToAppendWorkbook = XSSFTestDataSamples.openSampleWorkbook("56295.xlsx"); + XSSFSheet sheet = xlsToAppendWorkbook.getSheetAt(0); + XSSFRow srcRow = sheet.getRow(0); + XSSFCell oldCell = srcRow.getCell(0); + XSSFCellStyle cellStyle = oldCell.getCellStyle(); + + checkStyle(cellStyle); + +// StylesTable table = xlsToAppendWorkbook.getStylesSource(); +// List<XSSFCellFill> fills = table.getFills(); +// System.out.println("Having " + fills.size() + " fills"); +// for(XSSFCellFill fill : fills) { +// System.out.println("Fill: " + fill.getFillBackgroundColor() + "/" + fill.getFillForegroundColor()); +// } + + XSSFWorkbook targetWorkbook = new XSSFWorkbook(); + XSSFSheet newSheet = targetWorkbook.createSheet(sheet.getSheetName()); + XSSFRow destRow = newSheet.createRow(0); + XSSFCell newCell = destRow.createCell(0); + + //newCell.getCellStyle().cloneStyleFrom(cellStyle); + CellStyle newCellStyle = targetWorkbook.createCellStyle(); + newCellStyle.cloneStyleFrom(cellStyle); + newCell.setCellStyle(newCellStyle); + checkStyle(newCell.getCellStyle()); + newCell.setCellValue(oldCell.getStringCellValue()); + +// OutputStream os = new FileOutputStream("output.xlsm"); +// try { +// targetWorkbook.write(os); +// } finally { +// os.close(); +// } + + XSSFWorkbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(targetWorkbook); + XSSFCellStyle styleBack = wbBack.getSheetAt(0).getRow(0).getCell(0).getCellStyle(); + checkStyle(styleBack); + } + + private void checkStyle(XSSFCellStyle cellStyle) { + assertNotNull(cellStyle); + assertEquals(0, cellStyle.getFillForegroundColor()); + assertNotNull(cellStyle.getFillForegroundXSSFColor()); + XSSFColor fgColor = cellStyle.getFillForegroundColorColor(); + assertNotNull(fgColor); + assertEquals("FF00FFFF", fgColor.getARGBHex()); + + assertEquals(0, cellStyle.getFillBackgroundColor()); + assertNotNull(cellStyle.getFillBackgroundXSSFColor()); + XSSFColor bgColor = cellStyle.getFillBackgroundColorColor(); + assertNotNull(bgColor); + assertEquals("FF00FFFF", fgColor.getARGBHex()); + } } 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 8d427be552..4ec812d306 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.usermodel; +import java.io.IOException; + import junit.framework.TestCase; import org.apache.poi.hssf.usermodel.HSSFCellStyle; @@ -82,6 +84,9 @@ public class TestXSSFCellStyle extends TestCase { stylesTable.putCellStyleXf(cellStyleXf); stylesTable.putCellXf(cellXf); cellStyle = new XSSFCellStyle(1, 1, stylesTable, null); + + assertNotNull(stylesTable.getFillAt(1).getCTFill().getPatternFill()); + assertEquals(STPatternType.INT_DARK_GRAY, stylesTable.getFillAt(1).getCTFill().getPatternFill().getPatternType().intValue()); } public void testGetSetBorderBottom() { @@ -551,7 +556,7 @@ public class TestXSSFCellStyle extends TestCase { assertEquals(IndexedColors.AUTOMATIC.getIndex(), cellStyle.getFillBackgroundColor()); } - public void testDefaultStyles() { + public void testDefaultStyles() throws IOException { XSSFWorkbook wb1 = new XSSFWorkbook(); @@ -577,6 +582,7 @@ public class TestXSSFCellStyle extends TestCase { assertEquals(style2.getBorderLeft(), style1.getBorderLeft()); assertEquals(style2.getBorderRight(), style1.getBorderRight()); assertEquals(style2.getBorderTop(), style1.getBorderTop()); + wb2.close(); } @@ -618,7 +624,7 @@ public class TestXSSFCellStyle extends TestCase { public void testGetFillPattern() { - assertEquals(CellStyle.NO_FILL, cellStyle.getFillPattern()); + assertEquals(STPatternType.INT_DARK_GRAY-1, cellStyle.getFillPattern()); int num = stylesTable.getFills().size(); cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); |