问题描述
当前
Z Financial
Company name of the tax subject :
我有一个Google脚本文件,用于从.txt
获取数据并转换为JSON格式以粘贴到Google表格中(就像在Google表格中手动导入一样)
摘要:
let files = folder.getFiles();
var file = files.next();
var raw = file.getBlob().getDataAsstring();
console.log(raw);
var data = Utilities.parseCsv(raw)
问题
data
变量返回长度为1的数组,其值为��
,除此之外没有其他值。
从上面的.txt
片段中,我(大概)希望得到一个length = 3的数组,其行如下:
- Z Financial
- 纳税主体的公司名称:
注释
问题
我缺少将txt解析为CSV的内容吗?
解决方法
该代码未设置字符集。尝试使用正确的字符集。
var charset = 'ISO-8859-1'; // This is just a suggestion to try first
var raw = file.getBlob().getDataAsString(charset);
注意:OP在评论中提到其文件使用的字符集为UTF-16
。
参考
相关