From 2009e394a7b3996fa29b53cf13e782ca76e914b1 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 21 Sep 2010 11:33:21 +0000 Subject: [PATCH] Apply patch+test from bug #48325 - If a HSSF header or footer lacks left/right/centre information, assume it is a centre one git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@999320 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../poi/hssf/usermodel/HeaderFooter.java | 10 +++++++++- .../apache/poi/hssf/usermodel/TestBugs.java | 18 ++++++++++++++++++ test-data/spreadsheet/48325.xls | Bin 0 -> 4096 bytes 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test-data/spreadsheet/48325.xls diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 81a4a3beab..7fd203917a 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 48325 - If a HSSF header or footer lacks left/right/centre information, assume it is a centre one 49966 - Correctly remove calcChain entries for XSSF cells that stop holding formulas 47582 - XSSFCellStyle support for creating a style in one workbook based on a style from a different one 49931 - Avoid concurrency problems when re-ordering multiple HSSF header records for a PageSettingsBlock diff --git a/src/java/org/apache/poi/hssf/usermodel/HeaderFooter.java b/src/java/org/apache/poi/hssf/usermodel/HeaderFooter.java index 4fd7c89cc0..94a4e3b318 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HeaderFooter.java +++ b/src/java/org/apache/poi/hssf/usermodel/HeaderFooter.java @@ -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, }; diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index b92a3d5f6d..7c83d0b4a1 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -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 index 0000000000000000000000000000000000000000..8b8c926fa8d12535dcf52e8bc50629a0c7c16eec GIT binary patch literal 4096 zcmeHK&1(};5dZCV(RsM2o zhfi^jTaq6YcF;#w?=I%wDJ*9?iFKZ=FJKl^;>T7X7vXJ> zRMK$Iza9JAHdIC7ckKrQ^dQ&!@G-pNA0rzamNlq&sx1=-J`<%e&(Hd)>`Xp4r~jEY zELooDx#fL$71UNrJ1>1$9*97KIzaL&O!l z5S>qg45AHhN#44C-$`O0#ujEK=XP+RN9&>}b^yi!BbJQC1~T#Cbgw%}$9uH>6#cG} z^@|hP=}VJS1j%B9M7b3~6Jfg?bMT}kM!XU;U;D?mCv>;T4L zgZ$3)j%LV8KjQQwRj*z`_bMgy5{(p+7%DYppP zOE$SJe2Hp>LdN-c3L!})>71;PqFtyJQVPz|3LR4o31SN{A5o)tF0a#3S+Q9+9i`45 zI(tb>yzk1|`0q!6?}l@YuZpvWQ=aeAPsBMLB;s6dAZjFPBH{#SCgMzv5Jibvi0q65 k+G$MhIqW6sB;x-EwYEDWz<1-lf1bOvJ3X#>wUZI}0X_g2p#T5? literal 0 HcmV?d00001 -- 2.39.5