I have a python app and I'm using xlwings to write to an Excel file. I am trying to create a link to another file. For now, I am trying to link to an Excel file. I am using the code:
ws.range(15, 8).value = '=HYPERLINK("C:\\file.xlsx")'
This creates a link but when I click the link I get the error "cannot open the specified file". The cell value is =HYPERLINK("C:\file.xlsx")
. If I create a link to the same file using the "Insert Link" button in Excel it works and both cells show the same file path. Also I will need to create a link to a non-excel file that needs to be opened with a different program. How can I do this?
CodePudding user response:
You should use the add_hyperlink
method.
Example:
ws.range(15, 8).add_hyperlink("C:\\file.xlsx")
CodePudding user response:
You need to specify a protocol - specifically, file
.
Changing your link to file:///C:/file.xlxs
would likely solve your problem. Non excel files would be opened with the default program for that file type (e.g. .txt would open notepad)