gpt4 book ai didi

jquery - 风 sails :How can i read excel file data into json format

转载 作者:太空宇宙 更新时间:2023-11-03 23:36:04 27 4
gpt4 key购买 nike

上传 Excel 文件后,我尝试读取本地文件夹中的 Excel 文件。

var fs = require('fs');
uploadFile.upload
({
// don't allow the total upload size to exceed ~10MB
maxBytes: 10000000, saveAs: function(uploadFile, cb) {cb(null,Date.now()+uploadFile.filename ); },dirname: '../../assets/uploads'
},function whenDone(err, uploadedFiles) {
if (err)
{
console.log("error");
return res.negotiate(err);
}
// If no files were uploaded, respond with an error.
if (uploadedFiles.length === 0)
{
return res.badRequest('No file was uploaded');
}
else
{
var fd = uploadedFiles[0].fd;
console.log(fd);
fs.readFile(fd, 'utf8', function (err, data)
{
console.log(data);


});
}

如果是文本文件,则意味着我将成功读取,但对于 Excel 文件,我无法读取 Excel 数据。

我还需要将这个excel文件数据转换为json格式

最佳答案

尝试xlsx-rows

简单又容易:)

var fd = uploadedFiles[0].fd;
var rows = require('xlsx-rows')(fd);
rows = rows.slice(1);
rows.forEach(function(obj){
// do something....
});

关于jquery - 风 sails :How can i read excel file data into json format,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32202289/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com