EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

ExcelHeaderFooter - header text color tag not working

Open akhilHLD opened this issue 1 year ago • 1 comments
trafficstars

EPPlus usage

Noncommercial use

Environment

Windows

Epplus version

7.1.2

Spreadsheet application

Excel

Description

Create a blank worksheet and enter some data in it. Add header/footer text as present in Line 89 of this sample code When adding color tag to go with it, refer Link 1 and Link 2 The header/footer text in the created Excel file does not have the color mentioned. Additionally, the tag seems to be read as part of the text.

Please correct me on the usage of the color tag if it is incorrectly used.

Attached is the sample app.

SampleEPPlusTesting - ConsoleApp.zip

akhilHLD avatar May 22 '24 11:05 akhilHLD

The easiest way to fix this is to first do it in Excel and then pick the right string for CenteredText from the xml.

Here is an example that worked for me (replace this line in your sample app):

worksheet.HeaderFooter.OddHeader.CenteredText = "&C&\"Arial,Normal\"&14&K05+000sampleText";

What I did was the following:

  1. Create a new workbook in Excel and go to the Insert->Header & Footer menu.
  2. Add a text in the header and change to the color you want.
  3. Save the workbook to an *.xlsx file
  4. Change the file extension from xlsx to zip
  5. Inside the zip folder, go into the xl\worksheets folder
  6. Open the xml file for your worksheet.
  7. You will find the value inside the headerFooter\oddHeader element.
  8. Use this value in your code, note that EPPlus will xml-encode chars like & so change encoded characters like & back to its original value, i.e. & -> &

Hope this helps.

swmal avatar May 23 '24 14:05 swmal

It does, thanks. Might I ask about using the "&C" tag, it's not present in the documentation I listed previously.

akhilHLD avatar May 27 '24 12:05 akhilHLD

@akhilHLD "&C" means "Center section" according to this documentation: https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.evenheader?view=openxml-3.0.1.

Note that this is the documentation for EvenHeader, the OddHeader class does not have the same list of settings in these docs. But I suspect that it can be used in both cases.

swmal avatar May 28 '24 08:05 swmal

Thank you very much 👍

akhilHLD avatar May 28 '24 08:05 akhilHLD