Google Sheets IMPORTDATA with encoding

Viewed 257

I have a file URL in the following format:

http://.../exchangerate.txt

I cannot use IMPORTDATA because the file is in encoding:

UTF-16

it gives me bad data:

�n�u�l�l�

How to resolve this?

1 Answers

Please try the script:

function importwithencoding(url, encoding, delim) {
  if (delim === "tab") { delim = '\t'; }
  var data = UrlFetchApp.fetch(url);
  var csv = data.getContentText(encoding); 
  return Utilities.parseCsv(csv, delim);
}

Use it as a custom formula in a sheet:

=importwithencoding("http://.../exchangerate.txt", "UTF-16", "tab")

Related