javascriptexceljavascript-api-for-office

JavaScript API for Office getRange method


Is there a way to get a range by row, column, numRows, numColumns?

For example:

Excel.run(function (ctx) {
    var sheet = ctx.workbook.worksheets.getActiveWorksheet();
    var range = sheet.getRange(1, 2, 3, 4).load("values");
    ...
});

Solution

  • In the next release of ExcelAPI 1.7 we will have worksheet.getRangeByIndexes which is exactly what you are looking for.

    In the meantime you can achieve the same by doing the following:

    var range = sheet.getCell(1,2).getResizedRange(3,4);
    

    -Philip, Software Engineer on the Office Extensibility team