openxlsx
openxlsx copied to clipboard
Feature request - edit header and footer style
Expected Behavior
Hi, I wonder if it is possible to edit the appearance of headers and footers? Excel allows: font, font style, size, underline, color and effect properties to be edited Perhaps a document header and footer style is appropriate?
Actual Behavior
Steps to Reproduce the Problem
(please attach an example xlsx file if possible)
sessionInfo()
- Version of openxlsx: 4.0.17
- Version of R:
+1 here.
Even I feel the header and footer will be Printer only. I notice for most printer application, the header and footer will be simple plain text.
Putting technology aside, it would be a reasonable request from non tech stakeholder to add company logo, disclaimer which need to be highlighted as distribution material.
This may not fulfil all your requirements, but it may help people who find this thread in future: there are a number of escape sequences (starting with &) that you can use in your footer text that can change the appearance. I've only used a few, but the complete list seems to be here.
A couple of notes:
- the
&color
is a bit misleading - it seems to need&K<hex value>
- many of the formatting codes are toggles, so repeating a code will turn the effect off (see the usage of
&E
below)
Here's an example setting font, font style, size, double underline, colour and italics (I didn't look into adding a company logo, but &G
looks like it'd do that):
library(openxlsx)
sheetname <- 'Formatted footer'
wb <- createWorkbook()
addWorksheet(wb, sheetname)
# Add some data, to the sheet
writeData(wb, sheetname, iris)
setHeaderFooter(wb,
sheetname,
header = c(
NA,
'&"Courier New"&24Iris Dataset', # Set font, font size
NA
),
footer = c(
'&D &T', # Current date and time
NA,
'&KFF0000&E&F&E&K000000 - &I&A' # Red double-underlined filename, followed by italicised tabname
))
filename <- file.path(tempdir(), 'footer_sample.xlsx')
saveWorkbook(wb, filename)
print(paste('File saved to:', filename))
Has anyone had luck inserting a header logo? Tried &G as above with a file name like: '&GC:\Users\username\Pictures\logo.gif' But this just prints the path as text in the header? Any thoughts welcome!