]> source.dussan.org Git - poi.git/commitdiff
[bug-63268] fix issue where CellUtil.setFont is adding unnecessary styles
authorPJ Fanning <fanningpj@apache.org>
Tue, 19 Mar 2019 05:59:00 +0000 (05:59 +0000)
committerPJ Fanning <fanningpj@apache.org>
Tue, 19 Mar 2019 05:59:00 +0000 (05:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1855806 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/util/CellUtil.java
src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java

index 9dabd2b631f8b194f67a507fa42bdfe08ccd96d9..24d9a5126a11b6febf825b6eac28a9ec4927ac1e 100644 (file)
@@ -84,9 +84,12 @@ public final class CellUtil {
                     FILL_BACKGROUND_COLOR,
                     INDENTION,
                     DATA_FORMAT,
-                    FONT,
                     ROTATION
             )));
+    private static final Set<String> intValues = Collections.unmodifiableSet(
+            new HashSet<>(Arrays.asList(
+                    FONT
+            )));
     private static final Set<String> 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)) {
index fc507c90e0d4240f8d487816d280a82bb5cae774..416dd4d55b4875db3daacc63c38618a1c4729685 100644 (file)
@@ -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();
+    }
 }