]> source.dussan.org Git - poi.git/commitdiff
fixed fetching names of user defined styles, see Bugzila 49751
authorYegor Kozlov <yegor@apache.org>
Thu, 19 Aug 2010 18:08:54 +0000 (18:08 +0000)
committerYegor Kozlov <yegor@apache.org>
Thu, 19 Aug 2010 18:08:54 +0000 (18:08 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@987256 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/model/InternalWorkbook.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
test-data/spreadsheet/49751.xls [new file with mode: 0644]

index ad5baeebdd61e250da7fe5c930cef294826bf6c8..67f61e161533f4c9380e99f7b60f3892d7d03655 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta3" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">49751 - fixed fetching names of user defined styles in HSSFCellStyle.getUserStyleName()</action>
            <action dev="POI-DEVELOPERS" type="add">48900 - support for protecting a XSSF workbook</action>
            <action dev="POI-DEVELOPERS" type="fix">49725 - fixed FormulaParser to correctly process defined names with underscore</action>
            <action dev="POI-DEVELOPERS" type="add">48526 - added implementation for RANDBETWEEN()</action>
index f2719bba5e5d5943a0b603e8b9e9459d122f69a5..1ac6a2a3755ce0b3729db5083a5b90e93d421853 100644 (file)
@@ -871,7 +871,7 @@ public final class InternalWorkbook {
                 continue;
             }
             if(!(r instanceof StyleRecord)) {
-                return null;
+                continue;
             }
             StyleRecord sr = (StyleRecord)r;
             if(sr.getXFIndex() == xfIndex) {
index 7d8c27a6f4c894513288722755e1f9b481dc6bf5..293e237b0efdf9f9dbfbd823d84e5bba152e1e10 100644 (file)
@@ -22,9 +22,7 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 
 import junit.framework.AssertionFailedError;
 
@@ -1837,4 +1835,28 @@ if(1==2) {
        assertEquals("Testing 2", wb.getCellStyleAt((short)22).getUserStyleName());
        assertEquals("Testing 3", wb.getCellStyleAt((short)23).getUserStyleName());
     }
+
+    public void test49751() {
+        HSSFWorkbook wb = openSample("49751.xls");
+        short numCellStyles = wb.getNumCellStyles();
+        List<String> namedStyles = Arrays.asList(
+                "20% - Accent1", "20% - Accent2", "20% - Accent3", "20% - Accent4", "20% - Accent5",
+                "20% - Accent6", "40% - Accent1", "40% - Accent2", "40% - Accent3", "40% - Accent4", 
+                "40% - Accent5", "40% - Accent6", "60% - Accent1", "60% - Accent2", "60% - Accent3",
+                "60% - Accent4", "60% - Accent5", "60% - Accent6", "Accent1", "Accent2", "Accent3",
+                "Accent4", "Accent5", "Accent6", "Bad", "Calculation", "Check Cell", "Explanatory Text",
+                "Good", "Heading 1", "Heading 2", "Heading 3", "Heading 4", "Input", "Linked Cell",
+                "Neutral", "Note", "Output", "Title", "Total", "Warning Text");
+
+        List<String> collecteddStyles = new ArrayList<String>();
+        for (short i = 0; i < numCellStyles; i++) {
+            HSSFCellStyle cellStyle = wb.getCellStyleAt(i);
+            String styleName = cellStyle.getUserStyleName();
+            if (styleName != null) {
+                collecteddStyles.add(styleName);
+            }
+        }
+        assertTrue(namedStyles.containsAll(collecteddStyles));
+
+    }    
 }
diff --git a/test-data/spreadsheet/49751.xls b/test-data/spreadsheet/49751.xls
new file mode 100644 (file)
index 0000000..09eaede
Binary files /dev/null and b/test-data/spreadsheet/49751.xls differ