Home » excel » r – Hyperlink in Excel from csv both in english and french

r – Hyperlink in Excel from csv both in english and french

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m building a table in R which I save in a csv file. That table is made for some user that will actually open it with Excel. That table have a field with an hyperlink. I want Excel to detect the link and allow the user to click on it directly to open it in their browser. That is normally pretty easy, this link explains you just have to add '=HYPERLINK(' before your string. This however doesn’t work in all languages. Excel as the weird behaviour of coding differently in French or English. In my case, the users can have both French or English Excel making this solution not working.

Here is a reproductive example:

# prepare the data
field1 <- 1:4
link <- c("www.google.com", "www.duckduckgo.com", "www.yahoo.com", "www.altavista.com")

# English solution
dd_en <- data.frame(field1, link = paste0('=HYPERLINK("', link, '")'))
write.table(dd_en, "Y:/temp/tb_link_en.csv", quote=F, sep=";", col.names = T, row.names = F)

If I open in a French Excel, I get:
enter image description here

# french solution
dd_fr <- data.frame(field1, link = paste0('=LIEN_HYPERTEXTE("', link, '")'))
write.table(dd_fr, "Y:/temp/tb_link_fr.csv", quote=F, sep=";", col.names = T, row.names = F)

This time, in a french Excel I get:
enter image description here

Is there a way to have a universal solution?

How to&Answers:
  • Universal solution 1 – build two csv files – one for French version, one for English. Then it will be ok.

  • Universal solution 2 – build one csv file only in one language. Open the file in Excel, supporting this language. Then send the Excel file (not the CSV) to the people, using the other language. It will work, because Excel will take care of translating the formulas to the local language.

Answer:

You could programmatically determine the system language and then use the appropriate functions.

One way would be to retrieve the exact language of Excel (since multiple language packs can be installed) by (within Excel) retrieving the value of:

Application.LanguageSettings.LanguageID(msoLanguageIDUI)

…for example, English is 1033.

Or, you could retrieve the Windows LCID (a few ways).

Important related links:

Edit:

I’m not sure whether this add-in would be of any use but I figured I’ll pass it along too.

Multilingual Formula Translator Addin

A localized Excel addin that translates formulas and functions in several languages. You have an French version of Excel and your colleague or friend has Dutch?
No more problems with this elegant & simple auto-detecting add-in.

Currently supports 12 languages: (English, Dutch, German, French, Italian, Spanish, Portuguese, Danish, Swedish, Norwegian, Finnish and Russian). Supports 99,9% of all Excel Functions and (macro) commands, including those of the Analysis Toolpak.

It’s hasn’t been updated since 2005 so it might be outdated but you can check it out at the source here.