Adding a link to a bookmark in MS Word using python docx library

后端 未结 1 987
醉话见心
醉话见心 2021-01-26 18:11

I\'ve used the code from an earlier question to create a hyperlink: Adding an hyperlink in MSWord by using python-docx

I now want to create a link to a bookmark within

相关标签:
1条回答
  • 2021-01-26 18:17

    Never mind. Found a way, thanks to neilbilly at github: feature: Paragraph.add_hyperlink() #74 def add_link(paragraph, link_to, text): hyperlink = docx.oxml.shared.OxmlElement('w:hyperlink') hyperlink.set(docx.oxml.shared.qn('w:anchor'), link_to, ) new_run = docx.oxml.shared.OxmlElement('w:r') rPr = docx.oxml.shared.OxmlElement('w:rPr') new_run.append(rPr) new_run.text = text hyperlink.append(new_run) r = paragraph.add_run () r._r.append (hyperlink) r.font.name = "Calibri" r.font.color.theme_color = MSO_THEME_COLOR_INDEX.HYPERLINK r.font.underline = True

    0 讨论(0)
提交回复
热议问题