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: [email protected]
For additional commands, e-mail: [email protected]