[英]How to create a hyperlink in excel to open word file in specific page by python
Here is a document(word file), and I extract some sentences from that and write into an excel file by python.这是一个文档(word文件),我从中提取了一些句子并通过python写入excel文件。
And now I want to create a hyperlink of a sentences, which links to the page where the sentences belong.现在我想创建一个句子的超链接,它链接到句子所属的页面。
For example, if there a sentence "I love python" is in page 5 in a word file, and after I extract this sentence to a cell of an excel file by python, it is possible to create a hyperlink linking back to page 5 of that word file by xlsxwriter?例如,如果一个word文件的第5页有一句话“我爱python”,我把这句话用python提取到excel文件的一个单元格后,就可以创建一个链接回到第5页的超链接xlsxwriter 的那个 word 文件?
I afraid there is no way you can hyperlink to a page in DOCS file.恐怕您无法超链接到 DOCS 文件中的页面。 You can hyperlink till file level.
您可以超链接到文件级别。
Attaching the code here.在这里附上代码。
formula = 'HYPERLINK("[{path]", "Click Here")'.format(path=<PATH TO FILE>)
value = xlwt.Formula(formula)
This is done by xlwt library.这是由 xlwt 库完成的。 Also, The Hyperlink works differently on different excel formats.
此外,超链接在不同的 excel 格式上的工作方式不同。 ie Hyperlink works on Microsoft excel will not work in Open Office Excel.
即超链接在 Microsoft excel 上工作在 Open Office Excel 中不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.