Cas*_*sio 26
我正在使用此包将 XLSX 转换为 CSV:https : //www.npmjs.com/package/xlsx
XLSX = require('xlsx');
const workBook = XLSX.readFile(inputFilename);
XLSX.writeFile(workBook, outputFilename, { bookType: "csv" });
Run Code Online (Sandbox Code Playgroud)
hei*_*nst 21
没有我知道的库,但您可以使用node-xlsx来解析excel文件,获取行并自己创建CSV.这是一个例子:
var xlsx = require('node-xlsx');
var fs = require('fs');
var obj = xlsx.parse(__dirname + '/test.xls'); // parses a file
var rows = [];
var writeStr = "";
//looping through all sheets
for(var i = 0; i < obj.length; i++)
{
var sheet = obj[i];
//loop through all rows in the sheet
for(var j = 0; j < sheet['data'].length; j++)
{
//add the row to the rows array
rows.push(sheet['data'][j]);
}
}
//creates the csv string to write it to a file
for(var i = 0; i < rows.length; i++)
{
writeStr += rows[i].join(",") + "\n";
}
//writes to a file, but you will presumably send the csv as a
//response instead
fs.writeFile(__dirname + "/test.csv", writeStr, function(err) {
if(err) {
return console.log(err);
}
console.log("test.csv was saved in the current directory!");
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16063 次 |
最近记录: |