Reading Excel file using node.js

前端 未结 6 1436
遥遥无期
遥遥无期 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:20

    install exceljs and use the following code,

    var Excel = require('exceljs');
    
    var wb = new Excel.Workbook();
    var path = require('path');
    var filePath = path.resolve(__dirname,'sample.xlsx');
    
    wb.xlsx.readFile(filePath).then(function(){
    
        var sh = wb.getWorksheet("Sheet1");
    
        sh.getRow(1).getCell(2).value = 32;
        wb.xlsx.writeFile("sample2.xlsx");
        console.log("Row-3 | Cell-2 - "+sh.getRow(3).getCell(2).value);
    
        console.log(sh.rowCount);
        //Get all the rows data [1st and 2nd column]
        for (i = 1; i <= sh.rowCount; i++) {
            console.log(sh.getRow(i).getCell(1).value);
            console.log(sh.getRow(i).getCell(2).value);
        }
    });
    

提交回复
热议问题