]> source.dussan.org Git - poi.git/commitdiff
Patch from Jon Scharff from bug #57826 - If a XSSF shape has a buFont but no bullet...
authorNick Burch <nick@apache.org>
Wed, 29 Apr 2015 19:21:37 +0000 (19:21 +0000)
committerNick Burch <nick@apache.org>
Wed, 29 Apr 2015 19:21:37 +0000 (19:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1676831 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
test-data/spreadsheet/57826.xlsx [new file with mode: 0644]

index c89d0cdb30e93aafd90af4d7cddc5d31dbfd681d..6500c1603c69c3bbb2e983ca4489c4a7d61d0e5a 100644 (file)
@@ -709,13 +709,19 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
     public boolean isBullet() {
         ParagraphPropertyFetcher<Boolean> fetcher = new ParagraphPropertyFetcher<Boolean>(getLevel()){
             public boolean fetch(CTTextParagraphProperties props){
-                if(props.isSetBuNone()) {
+                if (props.isSetBuNone()) {
                     setValue(false);
                     return true;
                 }
-                if(props.isSetBuFont() || props.isSetBuChar() || props.isSetBuAutoNum()){
-                    setValue(true);
-                    return true;
+                if (props.isSetBuFont()) {
+                    if (props.isSetBuChar() || props.isSetBuAutoNum()) {
+                        setValue(true);
+                        return true;
+                    } else {
+                        // Excel treats text with buFont but no char/autonum
+                        //  as not bulleted
+                        // Possibly the font is just used if bullets turned on again?
+                    }
                 }
                 return false;
             }
index 71e008485f737fff3281dd0409c948160587a05e..003666958a2957e6f27b3c7e10373d2b93d4290a 100644 (file)
@@ -2369,6 +2369,34 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
         checkStyle(styleBack);
     }
 
+    /**
+     * Paragraph with property BuFont but none of the properties 
+     *  BuNone, BuChar, and BuAutoNum, used to trigger a NPE
+     * Excel treats this as not-bulleted, so now do we
+     */
+    @Test
+    public void testBug57826() {
+        XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("57826.xlsx");
+
+        assertTrue("no sheets in workbook", workbook.getNumberOfSheets() >= 1);
+        XSSFSheet sheet = workbook.getSheetAt(0);
+
+        XSSFDrawing drawing = sheet.getDrawingPatriarch();
+        assertNotNull(drawing);
+
+        List<XSSFShape> shapes = drawing.getShapes();
+        assertEquals(1, shapes.size());
+        assertTrue(shapes.get(0) instanceof XSSFSimpleShape);
+
+        XSSFSimpleShape shape = (XSSFSimpleShape)shapes.get(0);
+
+        // Used to throw a NPE
+        String text = shape.getText();
+
+        // No bulleting info included
+        assertEquals("test ok", text);
+    }
+
        private void checkStyle(XSSFCellStyle cellStyle) {
                assertNotNull(cellStyle);
         assertEquals(0, cellStyle.getFillForegroundColor());
diff --git a/test-data/spreadsheet/57826.xlsx b/test-data/spreadsheet/57826.xlsx
new file mode 100644 (file)
index 0000000..ccf2dc3
Binary files /dev/null and b/test-data/spreadsheet/57826.xlsx differ