CURRENTLY
I have a .txt
file which contains some data:
Z Financial
Company name of the tax subject :
I have a google script file to get the data from the .txt
and convert into JSON format to paste into Google Sheet (like a manual import in Google Sheets would do)
Snippet:
let files = folder.getFiles();
var file = files.next();
var raw = file.getBlob().getDataAsString();
console.log(raw);
var data = Utilities.parseCsv(raw)
ISSUE
console.log(raw)
is returning:
data
variable the returns as array of length 1 with value: ��
and nothing else.
From the .txt
snippet above, I would (roughly) expect an array of length = 3, with lines as follows:
NOTES
QUESTION
What am I missing to get the txt parsed as a CSV?
The code is not setting a charset. Try using the correct charset.
var charset = 'ISO-8859-1'; // This is just a suggestion to try first
var raw = file.getBlob().getDataAsString(charset);
NOTE: The OP mentioned in a comment that the charset used by their file is UTF-16
.
Reference
Related
Google Apps Script Utilities.parseCsv() and replacement character - � (read this first)
diamond character(�) appeared after fetch url in google script
How to find out the character set of a text file (from Super User)
How to detect the encoding of a file? (from Software Engineering)