RickInLosAngeles
RickInLosAngeles

Reputation: 189

GeneralException in Excel Add-in with Excel Online

We are using office.js and the Excel.run functionality. The objective is to click on a single cell in a sheet and capture all data in that sheet. This was successfully tested in Visual Studio 2015 running Excel 2016 and Excel API v1.3.

However, when running the same on Excel Online, an exception is created at the line return ctx.sync().then(function () {.

Exception:

GeneralException: An internal error has occurred. 
Debug info: {"code":"GeneralException","message":"An internal error has occurred."}

This issue happens in all browsers. Currently using Chrome version 63.0.3239.18 (Official Build) beta (64-bit).

We are trying to understand why it only fails in Excel Online and not Excel 2016 for Windows.

Here's the code without the Office 2013 paradigm. Unfortunately, it causes the same error. I noticed that the stack trace mentions 'Promise rejected (async)'.

Note: the code is not optimized. Just trimmed to show data access.

// read data from the sheet
function readDataExportConfirm() {

    Excel.run(function (ctx) {

        // Create a proxy object for the active worksheet
        var sheet = ctx.workbook.worksheets.getActiveWorksheet();

        // auto select entire sheet
        var range = sheet.getUsedRange();

        // fill proxy objects
        range.load('values');

        console.log("fill proxy objects");

        // sync on the request context synchronizes the state between
        // proxy objects and objects in Excel doc
        return ctx.sync().then(function () {

            var selectedData = range.values;

            console.log('data length: ' + selectedData.length + ' rows');
            console.log('for row ' + 0 + ', got: ' + selectedData[0].length + ' columns');

            // get rows
            var rows = selectedData.length;

            for (var row = 0; row < rows; row++) {

                var cols = selectedData[row].length;

                for (var col = 0; col < cols; col++) {

                    console.log('   for row ' + row + ', col ' + col
                        + ' = ' +selectedData[row][col].toString());
                }

            }

        });

    })
    .catch(function (error) {
        // Always be sure to catch any accumulated errors that bubble up from the Excel.run execution
        console.error("Error: " + error);
        console.error("Error stack: " + error.stack);
        if (error instanceof OfficeExtension.Error) {
            console.error("Debug info: " + JSON.stringify(error.debugInfo));
        }
    });

} 

Then used code from the page 'Work with Ranges using the Excel JavaScript API' at https://dev.office.com/docs/add-ins/excel/excel-add-ins-ranges in section "Get entire range" and get the same error with 'Promise rejected (async)' in the stack trace. Runs fine in Visual Studio 2015/Excel 2016.

Your help in resolving this is much appreciated.

Upvotes: 3

Views: 1232

Answers (3)

nmu
nmu

Reputation: 1519

I just wanted to add to this, because I found this error so frustrating since it's basically impossible to debug RichApi.Error: An internal error has occurred. at new n without just trying random things.

Anyway for me my issue was that, I retrieved some data from an excel sheet and didn't run await context.sync() after that. Then when I tried to update a new sheet later on, in a new Excel.run() thing, whenever I called await context.sync() I would get this very descriptive error.

However after I added the await context.sync() after fetching my data everything worked, so maybe the lesson is:

always call await context.sync() at the end of an Excel.run() function?

Or maybe it's not but this worked for me.

Upvotes: 0

RickInLosAngeles
RickInLosAngeles

Reputation: 189

After spending much time examining the code, creating a new Excel add-in using Visual Studio Enterprise 2015 version 14.0.25431 Update 3 and testing and testing in Excel online, I figured out what was causing the issue. It was one line in the manifest!

The Version was changed to Version 1.0 from 1.0.0.0 in the manifest. Changing this back resolved the problem of ‘GeneralException’. Now the add-in runs as expected in Excel online.

Upvotes: 3

Michael Zlatkovsky
Michael Zlatkovsky

Reputation: 8670

There is at least one issue with this code: you are mixing the Office 2013 paradigm ("getSelectedDataAsync") with the Office 2016+ paradigm ("Excel.run(batch)"). Your code will be more efficient if you only use the new 2016+ paradigm. And it might also fix your "GeneralException" problem (there's a chance that in mixing the two paradigms, you're having some sort of timing issue).

If that still doesn't solve your issue, please post an update.

Upvotes: 0

Related Questions