2
votes

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.

2
Do you see anything under "error.debugInfo"? Also, what is the contents of your workbook (i.e., what's a good repro state to be in when running this code?)Michael Zlatkovsky - Microsoft
The stack trace from error.debug shows: Home.js:113 Error: GeneralException: An internal error has occurred. (anonymous) @ Home.js:113 Promise rejected (async) Line 113 in Home.js is the console.error catch. Unfortunately, these do not tell me what is actually causing the issue. Contents are (tab delimited, fictional data): Name Street City, State ZIP Code Mr. & Mrs. Barry Hernandez 1919 Empire Ave. Anaheim, CA 92806 Billy Dane & Tony Harris 400 Carol Stream Portland, OR 97211 Dr. Deborah Spencer-Clark 567 Moulton Ave. Atlanta, GA 30318RickInLosAngeles

2 Answers

2
votes

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.

1
votes

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.