1

I am trying to populate multiple ranges using a formula and then convert the range to values using paste as value. The Office add-in is being used on Sharepoint Excel for the web. The code usually works but once in a while I get a "Rich API: An internal error has occurred" error, due to which the formulas do not get replaced by values. After the first time, the error happens on every subsequent try it crashes with the "Rich API: Timeout" error. There are about 300 ranges of size approx 25x25.

Code:

async function loadValues() {
        //This function is exectued to fill some ranges after data is retrived from server and pasted in a bacckend table
        await Excel.run(async function main(context) {
            context.workbook.application.calculationMode = "Manual";
            let names = context.workbook.names
            context.application.suspendScreenUpdatingUntilNextSync();
            var rng = names.getItem("controlsToUse").getRange();
            rng.load("values");
            await context.sync();
            context.application.suspendScreenUpdatingUntilNextSync();
            // Controls to use contains the name of the ranges in which data has to be loaded and the ranges from which formula to load data has to be copied
            var controlsToUse = rng.values;
            for (i = 0; i < controlsToUse.length; i++) {
                // str is the range in which data has to be pasted and str1 is the range from which formula has to be copied
                var str = controlsToUse[i][0];
                var str1 = controlsToUse[i][1];
                var range1 = names.getItem(str).getRange();
                range1.copyFrom(str1, Excel.RangeCopyType.formulas);
                range1.untrack();
            }
            await context.sync();
            context.workbook.application.calculate();
            await context.sync();
            context.application.suspendScreenUpdatingUntilNextSync();
            for (i = 0; i < controlsToUse.length; i++) {
                var str = controlsToUse[i][0];
                var range1 = names.getItem(str).getRange();
                range1.copyFrom(str, Excel.RangeCopyType.values);
                range1.untrack();
            }
            await context.sync();
            context.workbook.application.calculationMode = "Automatic";
            await context.sync();
        }).catch(errorHandler)
    }

1 Answers1

0

Can you comment out context.runtime.enableEvents = false; and check if it works?

  • Hi @J.Felix Bosco I tried commenting it out but it didn't help I am still getting the error once in a while. – Abhishek Gupta Nov 02 '20 at 06:19
  • I don't see `calculate()` method in `context.workbook.application` please check the [Microsoft Docs](https://learn.microsoft.com/en-us/javascript/api/excel?view=excel-js-preview&viewFallbackFrom=word-js-preview) I think if you comment out `context.workbook.application.calculate();` it would work fine. – J.Felix Bosco Nov 02 '20 at 09:09
  • Thanks for the suggestion but the method exists in ```context.workbook.application``` you can find the documentation for it here: https://learn.microsoft.com/en-us/javascript/api/excel/excel.application?view=excel-js-preview#calculate-calculationtype- also the error is very random the code works most of the time but every once in a while it gives the RichAPI.error – Abhishek Gupta Nov 02 '20 at 14:10
  • Sorry and Thank You I didn't notice that. – J.Felix Bosco Nov 05 '20 at 02:33
  • Is it possible to share your excel example data to help repro the issue? Which browser do you use when hit the issue? – Rita Jun 22 '21 at 08:45
  • Can you still repro the issue? If yes, is it possible to share one latest reproable wacsessionid? You can get it from header from any excel online request – Rita Jun 22 '21 at 09:48