appendFile 与 writeFile 的区别
目录结构
excel文件结构
要xlsx写入到index.txt中
完整代码
// @see https://www.npmjs.com/package/node-xlsx
const xlsx = require('node-xlsx').default;
const fs = require('fs');
const excelPath = `${__dirname}/source/公司IP地址登记.xlsx`
// Parse a buffer
const workSheetsFromBuffer = xlsx.parse(fs.readFileSync(excelPath));
const data = workSheetsFromBuffer[0].data
const writePath = `${__dirname}/source/index.txt`
data.forEach(item => {
const str = `${item[0]} --- ${item[1]} \n`
fs.appendFile(writePath, str, (err) => {
if (err) throw err;
console.log('文件已被保存');
});
})