nodejs读取excel文件内容

 

首先 npm install exceljs

const ExcelJS = require('exceljs');



 

(async () => {

    const workbook = new ExcelJS.Workbook();

    await workbook.xlsx.readFile(__dirname + "/nihao.xlsx");

    const sheet = workbook.worksheets[0];

    console.log(sheet.rowCount)

    sheet.eachRow(function (row, rowNumber) {

        // console.log(row.values.length)

        // console.log('Row ' + rowNumber + ' = ' + JSON.stringify(row.values));

        let user = { name: row.values[1], married: row.values[2], age: row.values[3] };

        console.log(user)

    });

})()

执行 node demo01.js

PS H:\nodetest\np\excel> node .\demo01.js
2
{ name: 'jialiu', married: 'yihun', age: 38 }
{ name: 'zhaoale', married: 'yihun', age: 34 }