aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java21
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/usermodel/HeaderFooter.java4
-rw-r--r--test-data/spreadsheet/HeaderFooterComplexFormats.xlsxbin0 -> 9543 bytes
3 files changed, 24 insertions, 1 deletions
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
@@ -159,6 +159,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()) {
XSSFSheet sheet = workbook.createSheet("Sheet 1");
@@ -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 0000000000..337f425440
--- /dev/null
+++ b/test-data/spreadsheet/HeaderFooterComplexFormats.xlsx
Binary files differ