Reading Excel file using node.js

前端 未结 6 1433
遥遥无期
遥遥无期 2020-11-28 05:38

Okay so i am using the FileUploader module to upload my file from angular to my REST API:

var uploader = $scope.uploader = new File         


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 06:22

    There are a few different libraries doing parsing of Excel files (.xlsx). I will list two projects I find interesting and worth looking into.

    Node-xlsx

    Excel parser and builder. It's kind of a wrapper for a popular project JS-XLSX, which is a pure javascript implementation from the Office Open XML spec.

    node-xlsx project page

    Example for parsing file

    var xlsx = require('node-xlsx');
    
    var obj = xlsx.parse(__dirname + '/myFile.xlsx'); // parses a file
    
    var obj = xlsx.parse(fs.readFileSync(__dirname + '/myFile.xlsx')); // parses a buffer
    

    ExcelJS

    Read, manipulate and write spreadsheet data and styles to XLSX and JSON. It's an active project. At the time of writing the latest commit was 9 hours ago. I haven't tested this myself, but the api looks extensive with a lot of possibilites.

    exceljs project page

    Code example:

    // read from a file
    var workbook = new Excel.Workbook();
    workbook.xlsx.readFile(filename)
        .then(function() {
            // use workbook
        });
    
    // pipe from stream
    var workbook = new Excel.Workbook();
    stream.pipe(workbook.xlsx.createInputStream());
    

提交回复
热议问题