Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: "Different First Page" Header and Footer #454

Open
pixelrebel opened this issue Jul 14, 2017 · 10 comments
Open

Feature request: "Different First Page" Header and Footer #454

pixelrebel opened this issue Jul 14, 2017 · 10 comments

Comments

@pixelrebel
Copy link

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)
@pixelrebel
Copy link
Author

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>&amp;CSuccessive Headers</oddHeader>
<firstHeader>&amp;CMy First Page Header</firstHeader>
</headerFooter>

@pixelrebel
Copy link
Author

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.

@pixelrebel
Copy link
Author

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!

@jmcnamara
Copy link
Owner

I'm traveling at the moment. I'll take a look next week.

@pixelrebel
Copy link
Author

Would you have some time soon to take a look at my branch to see if anything glaringly wrong stands out to you?

@jmcnamara
Copy link
Owner

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.

@pixelrebel
Copy link
Author

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.

@keyrea1
Copy link

keyrea1 commented May 10, 2021

Guys, any new on this feature?
I don't see this branch already.
Was it merged?

@jmcnamara
Copy link
Owner

@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.

@The-Johnson
Copy link

The-Johnson commented Dec 5, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants