1
votes

I am trying to iterate through tables in Excel using office js

Here is the code sample(same as one in the docs here https://github.com/OfficeDev/office-js-docs/blob/master/reference/excel/tablecollection.md):

Excel.run(function (ctx) { 
    var tables = ctx.workbook.tables;
    tables.load('items');
    return ctx.sync().then(function() {
        console.log("tables Count: " + tables.count);
        for (var i = 0; i < tables.items.length; i++)
        {
            console.log(tables.items[i].name);
        }
    });
}).catch(function(error) {
        console.log("Error: " + error);
        if (error instanceof OfficeExtension.Error) {
            console.log("Debug info: " + JSON.stringify(error.debugInfo));
        }
});

Get the number of tables.

Excel.run(function (ctx) { 
    var tables = ctx.workbook.tables;
    tables.load('count');
    return ctx.sync().then(function() {
        console.log(tables.count);
    });
}).catch(function(error) {
        console.log("Error: " + error);
        if (error instanceof OfficeExtension.Error) {
            console.log("Debug info: " + JSON.stringify(error.debugInfo));
        }
});

The code works correctly on windows Excel 2016 but on Mac Excel 2016 both code samples throw an error of type: "General Exception", and error location: "TableCollection.count"

1

1 Answers

0
votes

We tried to repro the issue, but are not getting the "General Exception". We are getting an error in the first example of "PropertyNotLoaded", though that's understandable in the sense that the sample is slightly incorrect, the load statement should be tables.load('name, count') instead of tables.load('items'). But that still doesn't explain the error. And the second samples should work just fine.

Are you running this on an existing document? Is there something special about that document? If you ran this code against a completely new document with a couple of tables in it, would it work then? Also, what version number is your version of Office for Mac?