1
votes

I'm having trouble to extract values from an excel file with the office.js add in I'm writing.

The add in shall help my colleagues to prepare report sheets for each teacher. It is supposed to filter the corresponding courses from the master table and send the data to the next processing step (create word files for each teacher).

I've tried filtering ranges with autofilter and creating a table with the data, but it seems that no code is executed after return context.sync()

I've read the official tutorial and some of the code on buildingofficeaddins.com but my function never executes the code after "return context.sync()"

function mselectTeacher(teachers) {
  Excel.run(function (context) {
    var sheet = context.workbook.worksheets.getActiveWorksheet();
    var lfv = sheet.tables.add("A1:M211", true);
    var wsy = lfv.columns.getItem("WS/SS");
    var studium = lfv.columns.getItem("Studium");
    // some more colums

    wsy.load("values");
    studium.load("values");

    return context.sync()
      .then(function () {

//I actually want to filter the rows by teacher, 
//this is only for testing
        for (var i = 1; i < 20; i++) {
          console.log(wsy[i] + "," + studium[i]);
        }
    });
  });
}

Is the problem, that I'm calling Excel.run from within another function?

2

2 Answers

0
votes

Could you try this?

function mselectTeacher(teachers) {
  Excel.run(function (context) {
    var sheet = context.workbook.worksheets.getActiveWorksheet();
    var lfv = sheet.tables.add("A1:M211", true);
    var wsy = lfv.columns.getItem("WS/SS");
    var studium = lfv.columns.getItem("Studium");
    // some more colums

    wsy.load("values");
    studium.load("values");

   context.sync()

//I actually want to filter the rows by teacher, 
//this is only for testing
        for (var i = 1; i < 20; i++) {
          console.log(wsy[i] + "," + studium[i]);
        }

  });
}
0
votes

I tried your code in ScriptLab on excel web and saw "The requested resource doesn't exist"error in F12

I think it's due to no columns named "WS/SS" "Studium" in your new added table. It works after i changed the columns name with "WS/SS" "Studium"