Bug 65595 - [PATCH] Strip colour formatting in headers and footers created by Excel
Summary: [PATCH] Strip colour formatting in headers and footers created by Excel
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 5.0.x-dev
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2021-09-24 14:08 UTC by Viru
Modified: 2021-10-03 13:28 UTC (History)
0 users

Patch (7.37 KB, application/gzip)
2021-09-24 14:10 UTC, Viru

Note You need to log in before you can comment on or make changes to this bug.
Description Viru 2021-09-24 14:08:49 UTC
Excel allows the colour of header and footer text to be 
specified. A header displaying "test test test" with the
middle "test" in red will be stored as follows:
test &KFF0000test&K01+000 test

org.apache.poi.hssf.usermodel.HeaderFooter.stripFields() removes 
formatting tags from headers and footers, but this is missed.

This patch removes these colour formatting tags by adding the 
following new regexes after the existing ones
        text = text.replaceAll("\\&K[\\dA-F]{6}", "");
        text = text.replaceAll("\\&K[\\d]{2}[+][\\d]{3}", "");

An example of an Excel file with this an other formatting is 
used for a unit test
Comment 1 Viru 2021-09-24 14:10:59 UTC
Created attachment 38047 [details]

This patch is a gzipped tar containing the subversion diff and a test file used for the unit test
Comment 2 PJ Fanning 2021-09-24 15:05:36 UTC
Thanks - committed with r1893599