2

I am using office.js to create Excel add-ins. I do have requirement to make Ajax API call on task pane button click and render API response into excel cells. API response contains thousands of object which i am considering as rows like below:

dataApiResponse = [{AccName: "ABC", ID: 173, Name: "FDI",... contains 20 attributes in single object}, .... contains upto 5000 objects in array]

Using below method to render above response array into excel. "outputHeaders" is array of Headers which already rendered on excel cell and wants to render api reseponse on below each header.

    const ExcelGetData = () => {
    // below is the outputData array contains upto 10000 or 15000 objects and each object represent rows for sheet and each object contains 
    // upto 20 attributs means in sheet the column id would be from 'A - T'
    const outputData = [{AccName: "ABC", ID: 173, Name: "FDI",... contains 20 attributes in single object}, .... contains upto 10000 objects in array];
    
    let range;
    let end = 0;
    let start = 2;
    let newEndRange;
    let newStartRange;
    const endRow = start + outputData.length;
    
    Excel.run(context => {
        const app = context.workbook.application;
        const sheet = context.workbook.worksheets.getItem('sheet1');
        return context.sync().then(() => {
            app.suspendApiCalculationUntilNextSync();
            outputData
                .map(() => outputData.splice(0, 500))
                .map(response => {
                    newStartRange = `A${start}`;
                    end = start + 500 - 1;
                    if (end < endRow) {
                        start = end + 1;
                        newEndRange = `T${end}`;
                        range = sheet.getRange(
                            `${newStartRange}:${newEndRange}`,
                        );
                    } else {
                        newEndRange = `T${endRow}`;
                        range = sheet.getRange(
                            `${newStartRange}:${newEndRange}`,
                        );
                    }
                    range.values = response;
                    range.format.autofitColumns();
                    context.sync();
                    return null;
                });
            return context.sync();
        });
    }).catch(err => {
        console.log(`error occured${err}`);
    });
};

On web version of office365 below excel API is failings with below error:

https://excel.officeapps.live.com/x/_vti_bin/EwaInternalWebService.json/ExecuteRichApiRequest?waccluster=PUS1

Error:

{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}

enter image description here

Also checked enter link description here question answer and got to know excel web has payload size limitation. Can you please help to resolve this issue or how i can split this operation? It would be help full as our deliverable are blocked due to this issue.

sagar
  • 464
  • 4
  • 13
  • Not sure how big for one object, therefore could you try to limit to 1000 objects? if it doesn't work, try 500 objects? – Raymond Lu Aug 30 '20 at 14:28
  • Tried with both if try to render data more than two columns its not working. Its worked only if try to render data for two columns. As its depends on user how many columns he wants to render on sheet, he can select as many columns he wants and then its failing. And facing this issue only for WEB version. – sagar Aug 31 '20 at 09:27
  • @Raymond Lu, thanks for comment. Tried spicing response object with 100/500/1000 but still same issue. Observed its working up to two column data rendering but as soon as add one more column its not working on WEB version. Can you please help to find the solution? Thanks in advance. – sagar Aug 31 '20 at 14:21
  • Thanks, I need a local repro for this issue, would you please export a scriptlab gist ? therefore i can verify this issue in my side? https://learn.microsoft.com/en-us/office/dev/add-ins/overview/explore-with-script-lab#save-and-share-snippets – Raymond Lu Sep 01 '20 at 15:14
  • @Raymond Lu, Thanks. will check how we can share the code and let you know. – sagar Sep 02 '20 at 14:12
  • @Raymond Lu, As you requested cant share code due to security reasons but updated question with method "ExcelGetData()" which we are using to render thousands of rows object in to spread sheet. "outputData" is nothing but the array of object containing 20 attributes in each object represent 20 columns (A to T) and thousands of rows are representing thousands of rows in excel. Please let us know if requires more info. Thanks in advance. – sagar Sep 21 '20 at 13:29

0 Answers0