我在其中一个应用程序中有此代码。
const readStream= fs.createReadStream('xlsx file path here');
readStream.on('header', (header) => {
console.log('header event');
console.log(header);
})
.on('data', function(file) {
console.log('data event');
});
此代码在其他应用程序中可以正常工作,但是当我将相同的代码复制到另一个应用程序中时,不会触发“标头”事件。但是“数据”事件正在触发。尝试使用相同的xlsx文件。
我认为您对库,内置流(例如fs.createReadStream
没有标题事件)感到困惑。
csv-parser最有可能
fs.createReadStream('data.csv')
.pipe(csv())
.on('headers', (headers) => {
console.log(`First header: ${headers[0]}`)
})