[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
This commit is contained in:
PJ Fanning 2021-09-24 15:05:10 +00:00
parent 0ca10663c6
commit abe22ef8f7
3 changed files with 24 additions and 1 deletions

View File

@ -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());
}
}
}

View File

@ -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;

Binary file not shown.