]> source.dussan.org Git - poi.git/commitdiff
Apply patch+test from bug #48325 - If a HSSF header or footer lacks left/right/centre...
authorNick Burch <nick@apache.org>
Tue, 21 Sep 2010 11:33:21 +0000 (11:33 +0000)
committerNick Burch <nick@apache.org>
Tue, 21 Sep 2010 11:33:21 +0000 (11:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@999320 13f79535-47bb-0310-9956-ffa450edef68

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

index 81a4a3beaba67a346db73acbdf209db361b950c5..7fd203917af75b6ac85fec30d439025dea8f3774 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta3" date="2010-??-??">
+           <action dev="poi-developers" type="fix">48325 - If a HSSF header or footer lacks left/right/centre information, assume it is a centre one</action>
            <action dev="poi-developers" type="fix">49966 - Correctly remove calcChain entries for XSSF cells that stop holding formulas</action>
            <action dev="poi-developers" type="add">47582 - XSSFCellStyle support for creating a style in one workbook based on a style from a different one</action>
            <action dev="poi-developers" type="fix">49931 - Avoid concurrency problems when re-ordering multiple HSSF header records for a PageSettingsBlock</action>
index 4fd7c89cc04d2649a9702ad319f3bff44d72917d..94a4e3b318f5cd7892c0c43121e104647df8428f 100644 (file)
@@ -40,7 +40,13 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header
                String _center = "";
                String _right = "";
 
+outer:
                while (text.length() > 1) {
+                       if (text.charAt(0) != '&') {
+                               // Mimics the behaviour of Excel, which would put it in the center.
+                               _center = text;
+                               break;
+                       }
                        int pos = text.length();
                        switch (text.charAt(1)) {
                        case 'L':
@@ -74,7 +80,9 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header
                                text = text.substring(pos);
                                break;
                        default:
-                               throw new IllegalStateException("bad text '" + getRawText() + "'.");
+                               // Mimics the behaviour of Excel, which would put it in the center.
+                               _center = text;
+                               break outer;
                        }
                }
                return new String[] { _left, _center, _right, };
index b92a3d5f6dac1baa6b6d67fddce6453751985b68..7c83d0b4a146c6c70d8a8d82b788375434220f9d 100644 (file)
@@ -1868,4 +1868,22 @@ if(1==2) {
        assertEquals(1, wb.getNumberOfSheets());
        assertEquals("Foo", wb.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().toString());
     }
+    
+    /**
+     * Missing left/right/centre options on a footer
+     */
+    public void test48325() throws Exception {
+       HSSFWorkbook wb = openSample("48325.xls");
+       HSSFSheet sh = wb.getSheetAt(0);
+       HSSFFooter f = sh.getFooter();
+
+       // Will show as the centre, as that is what excel does
+       //  with an invalid footer lacking left/right/centre details
+       assertEquals("Left text should be empty", "", f.getLeft());
+       assertEquals("Right text should be empty", "", f.getRight());
+       assertEquals(
+             "Center text should contain the illegal value", 
+             "BlahBlah blah blah  ", f.getCenter()
+       );
+    }
 }
diff --git a/test-data/spreadsheet/48325.xls b/test-data/spreadsheet/48325.xls
new file mode 100644 (file)
index 0000000..8b8c926
Binary files /dev/null and b/test-data/spreadsheet/48325.xls differ