0

Kind of a noob question. Sorry for that.

I have a string path

W:\documents\files

Is it possible to create an hyperlink from that and store it in a csv so that when a click it in Excel it opens the file ?

3 Answers 3

1

How about this?

from pathlib import Path
link = Path('W:\\documents\\files\\sample.txt').as_uri()

It should return "file:///W:/documents/files/sample.txt"

Sign up to request clarification or add additional context in comments.

Comments

1

I'm guessing you want something like this:

import csv
with open('my_csv_file.csv', 'w', newline='') as file:
    writer = csv.writer(file)
    writer.writerow(["file:///W:/documents/files"])

the csv module lets you read and write to csv files. Adding file:/// before your file path will let you link to it. Note that this code will write the text to a csv file but it won't become a hyperlink until you put the cursor in front of it and hit enter.

Comments

0

I don't know exactly what you said.

I think maybe you want to write hyperlink path in csv.

That is just use "".

like this. function("W:\documents\files")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.