appendFile writeFile 的区别

目录结构

image.png

excel文件结构

image.png
要xlsx写入到index.txt中
image.png

完整代码

  1. // @see https://www.npmjs.com/package/node-xlsx
  2. const xlsx = require('node-xlsx').default;
  3. const fs = require('fs');
  4. const excelPath = `${__dirname}/source/公司IP地址登记.xlsx`
  5. // Parse a buffer
  6. const workSheetsFromBuffer = xlsx.parse(fs.readFileSync(excelPath));
  7. const data = workSheetsFromBuffer[0].data
  8. const writePath = `${__dirname}/source/index.txt`
  9. data.forEach(item => {
  10. const str = `${item[0]} --- ${item[1]} \n`
  11. fs.appendFile(writePath, str, (err) => {
  12. if (err) throw err;
  13. console.log('文件已被保存');
  14. });
  15. })

https://www.npmjs.com/package/node-xlsx