nodejs读取excel文件内容

nodejs读取excel文件内容_第1张图片

 

首先 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 }

你可能感兴趣的:(javascript,html,vue.js)