-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feature: index entries #137
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
Comments
Hi Walter, not presently unfortunately. This is part of the fields capability if I'm not mistaken and hasn't been implemented yet. I'll leave this issue open as a feature request for it. |
With Steve's excellent help, I got it all working. Here is the relevant piece of code for marking index entries: from docx.oxml import OxmlElement
from docx.oxml.ns import qn
def MarkIndexEntry(entry,paragraph):
run = paragraph.add_run()
r = run._r
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'begin')
r.append(fldChar)
run = paragraph.add_run()
r = run._r
instrText = OxmlElement('w:instrText')
instrText.set(qn('xml:space'), 'preserve')
instrText.text = ' XE "%s" '%(entry)
r.append(instrText)
run = paragraph.add_run()
r = run._r
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'end')
r.append(fldChar) Thank you so much, Steve! |
Glad to hear you got it working Walter :) |
Would be great if you could explain how to use the function for images or tables for a newbie. document.add_picture('test.png', width=Inches(5.25))
paragraph = document.paragraphs[-1]
MarkIndexEntry("Test Caption",paragraph) |
@hannesharms Please use the mailing list for support questions: |
Thank you so much for sharing the code @wfb |
I copied your code into my python program and it worked first time. Thanks very much, @wfb |
This discussion is very valuable, thank you! Figure 1: [some figure caption], how can you refer back to this figure in the text, such as "Figure 1 states that..."? |
I am creating a large (200+ pages) document using python-docx, and I need to create an index of all names in the document. I understand that Word marks index entries a using special XE (Index Entry) field that includes the marked main entry, e.g. { XE indexed-name }. Is it possible to do this using python-docx? I would be happy to create the actual index manually at the end, as long as the index entries are generated automatically.
The text was updated successfully, but these errors were encountered: