You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2025/05/14 16:49:33 UTC

svn commit: r1925551 - /poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java

Author: fanningpj
Date: Wed May 14 16:49:33 2025
New Revision: 1925551

URL: http://svn.apache.org/viewvc?rev=1925551&view=rev
Log:
add tests for cell style cloning

Modified:
    poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java

Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java?rev=1925551&r1=1925550&r2=1925551&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java (original)
+++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java Wed May 14 16:49:33 2025
@@ -1090,4 +1090,67 @@ class TestXSSFCellStyle {
 
         workbook.close();
     }
+
+    @Test
+    void cloneToHSSF() throws IOException {
+        try (
+                XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
+                HSSFWorkbook hssfWorkbook = new HSSFWorkbook()
+        ) {
+            XSSFCellStyle cellStyle = xssfWorkbook.createCellStyle();
+            DataFormat format = xssfWorkbook.createDataFormat();
+
+            cellStyle.setDataFormat(format.getFormat("###0"));
+
+            cellStyle.setFillBackgroundColor(IndexedColors.DARK_BLUE.getIndex());
+            cellStyle.setFillForegroundColor(IndexedColors.DARK_RED.getIndex());
+            cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+
+            cellStyle.setAlignment(HorizontalAlignment.RIGHT);
+            cellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+
+            HSSFCellStyle hssfCellStyle = hssfWorkbook.createCellStyle();
+            hssfCellStyle.cloneStyleFrom(cellStyle);
+
+            // not everything is cloned by some properties are set
+            assertEquals(cellStyle.getDataFormat(), hssfCellStyle.getDataFormat());
+            assertEquals(IndexedColors.DARK_BLUE.getIndex(), hssfCellStyle.getFillBackgroundColor());
+            assertEquals(IndexedColors.DARK_RED.getIndex(), hssfCellStyle.getFillForegroundColor());
+            assertEquals(FillPatternType.SOLID_FOREGROUND, hssfCellStyle.getFillPattern());
+            assertEquals(HorizontalAlignment.RIGHT, hssfCellStyle.getAlignment());
+            assertEquals(VerticalAlignment.TOP, hssfCellStyle.getVerticalAlignment());
+        }
+    }
+
+    @Test
+    void cloneFromHSSF() throws IOException {
+        try (
+                XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
+                HSSFWorkbook hssfWorkbook = new HSSFWorkbook()
+        ) {
+            HSSFCellStyle cellStyle = hssfWorkbook.createCellStyle();
+            DataFormat format = hssfWorkbook.createDataFormat();
+
+            cellStyle.setDataFormat(format.getFormat("###0"));
+
+            cellStyle.setFillBackgroundColor(IndexedColors.DARK_BLUE.getIndex());
+            cellStyle.setFillForegroundColor(IndexedColors.DARK_RED.getIndex());
+            cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+
+            cellStyle.setAlignment(HorizontalAlignment.RIGHT);
+            cellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+
+            XSSFCellStyle xssfCellStyle = xssfWorkbook.createCellStyle();
+            xssfCellStyle.cloneStyleFrom(cellStyle);
+
+            // not everything is cloned by some properties are set
+            assertEquals(cellStyle.getDataFormat(), xssfCellStyle.getDataFormat());
+            // assertEquals(IndexedColors.DARK_BLUE.getIndex(), xssfCellStyle.getFillBackgroundColor());
+            assertEquals(IndexedColors.DARK_RED.getIndex(), xssfCellStyle.getFillForegroundColor());
+            assertEquals(FillPatternType.SOLID_FOREGROUND, xssfCellStyle.getFillPattern());
+            assertEquals(HorizontalAlignment.RIGHT, xssfCellStyle.getAlignment());
+            assertEquals(VerticalAlignment.TOP, xssfCellStyle.getVerticalAlignment());
+        }
+    }
+
 }



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