EPPlus
EPPlus copied to clipboard
ExcelHeaderFooter - header text color tag not working
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.
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:
- Create a new workbook in Excel and go to the Insert->Header & Footer menu.
- Add a text in the header and change to the color you want.
- Save the workbook to an *.xlsx file
- Change the file extension from xlsx to zip
- Inside the zip folder, go into the xl\worksheets folder
- Open the xml file for your worksheet.
- You will find the value inside the headerFooter\oddHeader element.
- 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.
It does, thanks. Might I ask about using the "&C" tag, it's not present in the documentation I listed previously.
@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.
Thank you very much 👍