0

Hi I am using exceljs with JavaScript for my project but all of the variable that I modify within the readFile function are not changing outside scope.

//array for pdm paths 
var arrFundPartyRole = [];

//mapping UI_id -> UI_Label 
var labelUIMap = new Map();

//xlsx parsing to get necessary data
var workbook = new Excel.Workbook();
workbook.xlsx.readFile('Veritas_Full_082819.xlsx')
  .then(function() {

    //getting the worksheet and necessary columns 
    var worksheet = workbook.getWorksheet('VT_FULL');
    var pdmPath = worksheet.getColumn(18);
    var idUI = worksheet.getColumn(24);
    var labelUI = worksheet.getColumn(27);

    //iterate over all pdm paths by column
    pdmPath.eachCell(function(cell, rowNumber) {
      var path = cell.value;

      if (path != null) {
        //splitting the path
        var pathElts = path.split(".");
        if (pathElts[0] == 'FundPartyRole') {
          arrFundPartyRole.push(pathElts);
        }
      }
    });

    //iterate over the UI_id column and find corresponding label
    //counter to skip the first 2 columns?
    var counter = 0;
    idUI.eachCell(function(cell, rowNumber) {
      if ((cell.value != null) && (counter > 1)) {
        var idAddress = cell.address;
        //address of id can be used to create address of label
        var labelAddress = idAddress.replace("X", "AA");
        var label = worksheet.getCell(labelAddress).value;
        labelUIMap.set(cell.value, label);
      }
      counter = counter + 1;
    });

    /*for (i = 0; i < arrFundPartyRole.length; i++) {
      if labelUIMap.get()
    }*/
    console.log(labelUIMap);

    });

  console.log(labelUIMap);

In this case, labelUIMap and arrFundPartyRole are blank when I print them outside scope but populated within the scope. Am I missing something?

1 Answers1

0

You have to add after the first console.log(labelUIMap):

var i = last row that you have modify: number;
worksheet.getRow(i).commit();
workbook.xlsx.writeFile('Veritas_Full_082819.xlsx').then(()=>{

      }).catch((err)=>{
        throw err;
      });
SoufH
  • 1
  • 2