尝试使用 iconv-lite
库 iconv.encode(str, 'GBK')
进行GBK编码不起作用。
求问如何解决啊~~
大家讲道理2017-04-17 15:33:20
I can do this, but then I found that the difference seems to be iconv.decode?
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;
黄舟2017-04-17 15:33:20
My solution is to output utf-8 directly without GBK encoding, but I need to add a BOM header. new Buffer('xEFxBBxBF','binary') + utf-8字符串