I'm currently trying to implement some automations for an Excel Workbook. Part of it is to set a common header for all sheets in that workbook.
The header should look like this: Screenshot of the aimed header style and content
I found here question (52295459) how to access the headers, but i did not manage to format them. The code snippet is attached below. I read the documentation for the footerHeader class and for the references format codes. But I'm stuck.
So, these are my questions:
getItem
and their name?&5E5E5E
,&c5E5E5E
, &color5E5E5E
, E5E5E
,&K5E5E5E
, &K"5E5E5E"
- but nothing worked.
Edit: I want to change the colour of the header section.The working part of the code so far:
//An array with the names of my wokrsheets
const worksheetNames : string[] = ["Titelseite", "GewerkeModule", "Statusanzeige", "Verteilerliste"];
//Access header of each sheet individually
for (const sheet of worksheetNames) {
const headerFooter : Excel.HeaderFooter = context.workbook.worksheets
.getItem(sheet)
.pageLayout
.headersFooters.defaultForAllPages;
//Set the strings for the header sections,
// in which also the formatting should be contained (I guess)
headerFooter.centerHeader = "center";
headerFooter.leftHeader = "left";
headerFooter.rightHeader = "right"
}
Thank you already for your help! Kind regards
Update: I tried to solve my issues again, and indeed i cannot reproduce problem 3. anymore, too. I dont know why and what i have changed. And by printing out the current header string i found at least formatting for the coloring of the header.
So, to sum up, the answers to my problems:
No common solution for setting headers in all sheets - Thanks for clarifying to Rita. However: The solution with looping through all sheets seems to work (see my code above)
This sets the colour to a light grey and also include a "page X of y" part in the third line.
BUT: These shortcodes (&Z, &S, &A) have nothing to do with the format codes referenced by microsoft. I guess these are the German format codes, because my Excel installation is set to German. But that would be annoying if different codes are necessary for different language settings?
context.workbook.worksheets.getItem(sheet).pageLayout.headersFooters.defaultForAllPages.centerHeader = "&Z&M01+043Heder Line1 \nNextLine\nPage &S of &A"
&Z
centers the output ("zentrieren")
&M01+043
seems to set the font colour to light grey
\n
for line breaks
&S
current page number ("Seite")
&A
number of all pages in total
I cannot reproduce the error anymore either. Magic? It seems to be connected to the formatting...
Not implemented yet - thanks again to Rita
Thanks post the question here.
Currently it's not possible to set header and footer for all sheet with one API, this might be one new request.
var worksheet = context.workbook.worksheets.getItem("Sheet7"); var range = worksheet.getRange("A1"); range.format.font.color = "5e5e5e";
can help set color
cannot repro, tried set middle header when left and right header are set, it works good in win32, so which platform do you hit?
Sorry to let you know the image is not supported yet in api level, you can submit new request Click here!