【发布时间】:2020-08-22 10:18:58
【问题描述】:
我想用超链接替换段落中的一个单词。我看到了可以用超链接创建一个新单词的函数,但这不是我想要的。例如我想做这样的事情:
mydoc = docx.Document()
text = "a stackoverflow question"
parag = mydoc.add_paragraph(text)
parag.add_hyperlink(the word that will be changed to the hyperlink (in that case
that can be "stackoverflow"), link('https://stackoverflow.com'))
对于这个add_hyperlink 函数,stackoverflow 词必须是超链接。
有没有办法做到这一点?
【问题讨论】:
-
您可以按照@scanny here提出的解决方案进行操作!
-
它不起作用,它需要字符串,但我的是超链接,所以我收到了这个错误
TypeError: 'in <string>' requires string as left operand, not CT_R
标签: python ms-word docx python-docx