var result = [];
var bin = fs.readFileSync(file);
var data = iconv.decode(bin, 'gbk');
data = data.replace(/\t/g, "");
data = data.replace(/\"([^\"]*)\"/g, function (a) {
return a.replace(/,|"/g, "")
})
var lines = data.split("\r\n");
for (let i in lines) {
var rows = lines[i].split(",");
for (let j in rows) {
rows[j] = rows[j].trim();
}
result.push(rows)
}
this.xlsxData = result;
我这个可以,然后发现区别好像是iconv.decode?
我的解决办法是不进行GBK编码,直接输出utf-8,但是需要加BOM头。
new Buffer('xEFxBBxBF','binary') + utf-8字符串