diff --git a/src/java/org/apache/poi/ss/util/CellUtil.java b/src/java/org/apache/poi/ss/util/CellUtil.java index 9dabd2b631..24d9a5126a 100644 --- a/src/java/org/apache/poi/ss/util/CellUtil.java +++ b/src/java/org/apache/poi/ss/util/CellUtil.java @@ -84,9 +84,12 @@ public final class CellUtil { FILL_BACKGROUND_COLOR, INDENTION, DATA_FORMAT, - FONT, ROTATION ))); + private static final Set intValues = Collections.unmodifiableSet( + new HashSet<>(Arrays.asList( + FONT + ))); private static final Set booleanValues = Collections.unmodifiableSet( new HashSet<>(Arrays.asList( LOCKED, @@ -369,6 +372,8 @@ public final class CellUtil { for (final String key : src.keySet()) { if (shortValues.contains(key)) { dest.put(key, getShort(src, key)); + } else if (intValues.contains(key)) { + dest.put(key, getInt(src, key)); } else if (booleanValues.contains(key)) { dest.put(key, getBoolean(src, key)); } else if (borderTypeValues.contains(key)) { diff --git a/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java b/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java index fc507c90e0..416dd4d55b 100644 --- a/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java +++ b/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java @@ -378,4 +378,23 @@ public abstract class BaseTestCellUtil { wb1.close(); } + + /** + * bug 63268 + * @since POI 4.1.0 + */ + @Test + public void setFontShouldNotCreateDuplicateStyle() throws IOException { + Workbook wb1 = _testDataProvider.createWorkbook(); + Cell c = wb1.createSheet().createRow(1).createCell(1); + Font f = wb1.createFont(); + + CellUtil.setFont(c, f); + int num1 = wb1.getNumCellStyles(); + + CellUtil.setFont(c, f); + int num2 = wb1.getNumCellStyles(); + assertEquals(num1, num2); + wb1.close(); + } }