XlsxWriter
XlsxWriter copied to clipboard
Feature request: "Different First Page" Header and Footer
How tricky would it be to implement the "Different First Page" feature?
Perhaps something like this?
header1 = '&CMy First Page Header'
header2 = '&CSuccessive Headers'
worksheet.set_header(header1, {'first_only':True})
worksheet.set_header(header2)
I made an attempt at this feature, but it's not working. To keep it simple, I just created separate first_
versions of the header
and footer
properties and methods.
The implementation is slightly different than the original request:
header1 = '&CMy First Page Header'
header2 = '&CSuccessive Headers'
worksheet.set_first_header(header1)
worksheet.set_header(header2)
Does any have some insight into what I may be doing wrong? It seems to be creating the proper XML, but I must admit, I know nothing about OpenXML .
Here's the resulting XML from my fork:
<headerFooter differentFirst="1">
<oddHeader>&CSuccessive Headers</oddHeader>
<firstHeader>&CMy First Page Header</firstHeader>
</headerFooter>
Actually turns out I was testing with an old version of excel (2011 Mac). This works perfectly on newer versions of Excel on Windows. I'm going to test a bit further and submit a PR. Please let me know if there's anything I should add to my PR.
First page header images aren't loading. I could use a tip or hint if someone has a guess as to what I'm running up against. Thanks!
I'm traveling at the moment. I'll take a look next week.
Would you have some time soon to take a look at my branch to see if anything glaringly wrong stands out to you?
I don't see anything obvious wrong but it is hard to tell. In general, getting image ref ids right can be tricky.
When I am developing a feature like this I usually start with test cases based on Excel 2007 files like this or this and then build out the complexity in other test files from there.
I've been using my branch for a couple years now. I don't see any issues with this. However, I don't have older versions of excel to test.
Guys, any new on this feature? I don't see this branch already. Was it merged?
@keyrea1 It wasn't merged. For a feature like this I also need to implement it in the Perl and C versions if I am going to implement, or merge, it in the Python version. And there was never enough user interest to justify that.
It's curious that there isn't user interest in this, it's basically mandatory to have different first page footers if the end goal is a human readable document aimed for distribution.
For anyone like me who is just in need to have no header or footer in the title page of their doc. This is the dead simplest way to do it by just adding one line:
To have a different first page header and footer: go into worksheet.py in the XlsxWriter library Find:
def _write_header_footer(self):
# Write the <headerFooter> element.
attributes = []
# ADD THIS LINE:
attributes.append(('differentFirst', 1))
Big thanks to pixelrebel for his implementation of the full featured different first.