From abe22ef8f75df2213b41b986c4201835bdd55fe3 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 24 Sep 2021 15:05:10 +0000 Subject: [PATCH] [bug-65595] Strip colour formatting in headers and footers git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1893599 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/usermodel/TestXSSFSheet.java | 21 ++++++++++++++++++ .../poi/hssf/usermodel/HeaderFooter.java | 4 +++- .../HeaderFooterComplexFormats.xlsx | Bin 0 -> 9543 bytes 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test-data/spreadsheet/HeaderFooterComplexFormats.xlsx diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java index 54229938e4..5c6f1670f1 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java @@ -158,6 +158,26 @@ public final class TestXSSFSheet extends BaseTestXSheet { } } + @Test + void headerFooterWithFormat() throws IOException { + try (XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("HeaderFooterComplexFormats.xlsx")) { + XSSFOddHeader hdr; + XSSFOddFooter ftr; + + XSSFSheet s1 = wb1.getSheetAt(0); + assertNotNull(s1.getHeader()); + assertNotNull(s1.getFooter()); + hdr = (XSSFOddHeader) s1.getHeader(); + ftr = (XSSFOddFooter) s1.getFooter(); + + // The following is how the header/footer appear in Excel (with formatting removed) + hdr.setAreFieldsStripped(true); + assertEquals("Header Bold RedUnderlined Bolditalics", hdr.getCenter()); + ftr.setAreFieldsStripped(true); + assertEquals("Footer ArialBlue TahomaBoldGreen", ftr.getCenter()); + } + } + @Test void getAllHeadersFooters() throws IOException { try (XSSFWorkbook workbook = new XSSFWorkbook()) { @@ -2015,4 +2035,5 @@ public final class TestXSSFSheet extends BaseTestXSheet { assertEquals("/xl/drawings/vmlDrawing2.vml", vml2.getPackagePart().getPartName().getName()); } } + } diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HeaderFooter.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HeaderFooter.java index 90b9556923..5bd1b3d0be 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HeaderFooter.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HeaderFooter.java @@ -295,9 +295,11 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header } // Now do the tricky, dynamic ones - // These are things like font sizes and font names + // These are things like font sizes, font names and colours text = text.replaceAll("\\&\\d+", ""); text = text.replaceAll("\\&\".*?,.*?\"", ""); + text = text.replaceAll("\\&K[\\dA-F]{6}", ""); + text = text.replaceAll("\\&K[\\d]{2}[+][\\d]{3}", ""); // All done return text; diff --git a/test-data/spreadsheet/HeaderFooterComplexFormats.xlsx b/test-data/spreadsheet/HeaderFooterComplexFormats.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..337f425440abb3d0b41951a9abb82a5246b7d541 GIT binary patch literal 9543 zcmeHtWmr^e+x7s`jUY%jNXHP;=?owZ(#;UkFbqmbcQ?|hbT^12B?<^40z*opNGlEB z=(C^Cz1cqR@&0=MJbV3^b*$r_>sMji8ySZnkd56cjEcZnN30xhza+>?(9Q`aaDEm?WoS0kb(6?=1Vd94E@ z6_+eXD3no{BVCP7M$0U%6!0}#arpi1Ff3&&beX1MIpF=69hqLZ#_OUXtXmzjEoB1L zj9c&kKP0S6VaG>`M8c(9v}w~PPnfHQ2r&a1n*+$zI*27fYaeqJ=n|fR zLbeZ0DugHO%^4!B%@-;M{7)qlLF!(MaG4;RX8TdlRDDiKkqeSxS665NjlamWNtci5 z8*=16QiZrknVPvn96fk>e*FF;&;Mdg{^`+UlHRHH@Zt6EfIH<^&OSSXu?k8$?t?oR zbZB2PZ__o!7BR~leGfqkQns2I`@a58+Gu`z&0dF&+LBkT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