Excel 可以将 CSV 中的 URL 解释为超链接吗?

Excel 可以将 CSV 中的 URL 解释为超链接吗? 如果可以,如何解释?

53228 次浏览

Yes, but it's not possible to link them automatically. CSV files are just text files - whatever opens and reads them is responsible for allowing you to click the link.


As to how Excel seems to handle CSV files - everything between commas is interpreted as if it already had been typed into the cell. Therefore, the CSV file containing ="http://google.com",=A1 will display as http://google.com,http://google.com in Excel. It's important to note, however, that hyperlinks in Excel are metadata, and not the result of anything in the actual cell (ie, a hyperlinked cell to Google still contains http://google.com not <a>http://google.com</a> or anything of that sort.)

Since that's the case, and all metadata is lost when converting to a CSV, it's impossible to tell Excel you wish for something to be hyperlinked merely by changing the cell value. Normally, Excel interprets your input when you hit 'Enter' and links URLs then, but since CSV data is not being entered, but rather already exists, this does not happen.

Your best bet is to write some sort of addon or macro to run when you open up a CSV which parses every cell and hyperlinks them if they match a URL format.

You can actually do this and have Excel show a clickable link. Use this format in the CSV file:

=HYPERLINK("URL")

So the CSV would look like:

1,23.4,=HYPERLINK("http://www.google.com")

However, I'm trying to get some links with commas in them to work properly and it doesn't look like there's a way to escape them and still have Excel make the link clickable.

Does anyone know how?

With embedding the hyperlink function you need to watch the quotes. Below is an example of a CSV file created that lists an error and a link to view the documentation on the method that failed. (Bit esoteric but that's what I am working on)

"Details","Failing Method (click to view)"
"Method failed","=HYPERLINK(""http://some_url_with_documentation"",""Method_name"")"

you can URL Encode your commas inside the URL so the URL is not split across multiple cells.

Just replace commas with %2c

http://www.xyz.com/file,comma.pdf

becomes

=hyperlink("http://www.xyz.com/file%2ccomma.pdf")

I read all of these answers and some others but it still took a while to work it out in Excel 2014.

The result in the csv should look like this

"=HYPERLINK(""http://www.Google.com"",""Google"")"

Note: If you are trying to set this from MSSQL server then

'"=HYPERLINK(""http://www.' + baseurl + '.com"",""' + baseurl + '"")"' AS url

Use this format:

=HYPERLINK(""<URL>"";""<LABEL>"")

e.g.:

=HYPERLINK(""http://stackoverflow.com"";""I love stackoverflow!"")

P.S. The same format works in LibreOffice Calc as well.

The issue here for me was that because a .CSV by it's nature is Comma separated, any commas in the text file are interpreted as separators. It worked for me by using tab characters as separators, saving it as a .TXT file so that when opened in EXCEL you choose the TAB character rather than ','.

In the text file …

## ensure that the file is TAB separated Item 1 A file Name data.txt
Item 2 Col 2 =HYPERLINK("http:\www.ilexuk.com","ILEX")

"ILEX" then is shown in the cell and "http:\www.ilexuk.com" is the hyperlink for the cell.

"=HYPERLINK(\"\" " + "http://www.mywebsite.com"+ "\"\")" use this format before writing to CSV.

As described above, "=HYPERLINK(""http://www.google.com"", ""Google"")" is what worked for me.

However, In Excel Version 2204 Click to Run, I couldn't have leading white space.

For example;

FirstName, "=HYPERLINK(""http://www.google.com"", ""Google"")" fails FirstName,"=HYPERLINK(""http://www.google.com"", ""Google"")" success