Skip to content

feature: process bookmarks #109

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

Open
timcking opened this issue Nov 25, 2014 · 2 comments
Open

feature: process bookmarks #109

timcking opened this issue Nov 25, 2014 · 2 comments

Comments

@timcking
Copy link

Add ability to recognize, search, and replace Microsoft Word bookmark names. A typical VBA implementation would be:

With Wrd.ActiveDocument.Bookmarks
.Item("Checklist").Range.Text = sChecklist
.Item("Reference").Range.Text = sReference
.Item("SQM3").Range.Text = sSqm3
End With

@scanny scanny changed the title Feature Request: Processing of Word bookmarks feature: process bookmarks Dec 18, 2014
@scanny scanny added this to the later milestone Dec 18, 2014
@scanny scanny removed this from the later milestone Apr 9, 2016
@JustMe85
Copy link

For future reference, this is what I used to insert bookmarks.

from docx import Document
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
from docx.text.run import Run

# Configure
style = 'Figure'              # Can be 'Figure', 'Table' or 'Equation'
num = 1

# Initialize
d = Document()
p = d.add_paragraph()

# Insert caption
elem = p._element
r = OxmlElement('w:r')
elem.append(r)
Run(r, p).text = style + ' '

# Insert caption number   
pCaption = OxmlElement('w:fldSimple')
pCaption.set(qn('w:instr'), r' SEQ {style} \* ARABIC '.format(style=style))
elem.append(pCaption)

r = OxmlElement('w:r')
pCaption.append(r)

rPr = OxmlElement('w:rPr')
r.append(rPr)

rPr.append(OxmlElement('w:noProof'))

Run(r, p).text = str(num)

@scanny
Copy link
Contributor

scanny commented Apr 11, 2016

Awesome, thanks @JustMe85 :)

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

3 participants