javascriptoffice-jsjexcelapi

Couldn't load cell value for more than 12000 rows in Excel using Office js Excel API


We have created an Excel addin using office js API. In our extension we have a module where we fetch data from excel sheet and then process it. The implementation works fine upto 12000 rows after which the API returns 500 internal server error. I tried finding out the limitation of the excel range API but couldn't find any appropriate links. Please find the reference code below.

await Excel.run(async context => {
          let sheet;
          sheet = context.workbook.worksheets.getItem('Sheet 1');
          let range = sheet.getRange('A1:O12000');
  ​        range.load("values");
          await context.sync();
          console.log("Excel data", range.values);
}

Can anyone let me know in case of any limitation. I do have a work arround idea, which is to split the range into chunks of 12000 rows and load the data. But still just want to make sure if the API has a data size limitation. Thank you in advance.

When I add a try catch to my code I see that I get the following error in my catch block. ( When the range is A1:O13000 )

await Excel.run(async context => {
          try {
          let sheet;
          sheet = context.workbook.worksheets.getItem('Sheet 1');
          let range = sheet.getRange('A1:O13000');
  ​        range.load("values");
          await context.sync();
          console.log("Excel data", range.values);
          } catch (e){
             console.error(e);
          }

}

The error I get enter image description here


Solution

  • Thanks naveen for your question. we have 2 limitations: a) Excel Online has payload size limit which is 5MB, b)A range is limited to 5 million cells.

    According on your sample, it is less than these limits. I also tried your code with Script Lab, it runs OK. here is my gist: https://gist.github.com/lumine2008/633f3967d0a55a7f2993c81c472e88a8

    The document can be found at https://learn.microsoft.com/en-us/office/dev/add-ins/develop/common-coding-issues#excel-range-limits