我使用XLSX解析一个excel文件,并使用fs.appendfile将第一列值附加到文本文件,但是当我尝试console.log登出该文件时,它会一直显示“ fs.readFile(first.txt ,函数(错误,数据){ ReferenceError:首先未定义。我做错了什么?这是我的代码
const XLSX = require('xlsx');
const workbook = XLSX.readFile('test.xlsx');
const sheet_name_list = workbook.SheetNames;
const fs = require ('fs');
sheet_name_list.forEach(function(y) {
var worksheet = workbook.Sheets[y];
//console.log(worksheet)
var headers = {};
var data = [];
for(z in worksheet) {
if(z[0] === '!') continue;
//parse out the column, row, and value
var col = z.substring(0,1);
var row = parseInt(z.substring(1));
var value = worksheet[z].v;
if(row !== 1) {
fs.appendFile('first.txt', value, (err) => {
if (err) throw err;
console.log('The file were updated!');
});
}
}
fs.readFile('first.txt', function(err,data){
if (err) throw err;
console.log(data)
})
})