title | description | ms.date | ms.localizationpriority |
---|---|---|---|
Insert ranges using the Excel JavaScript API |
Learn how to insert a range of cells with the Excel JavaScript API. |
02/17/2022 |
medium |
This article provides a code sample that inserts a range of cells with the Excel JavaScript API. For the complete list of properties and methods that the Range
object supports, see the Excel.Range class.
[!includeExcel cells and ranges note]
The following code sample inserts a range of cells in location B4:E4 and shifts other cells down to provide space for the new cells.
await Excel.run(async (context) => {
let sheet = context.workbook.worksheets.getItem("Sample");
let range = sheet.getRange("B4:E4");
range.insert(Excel.InsertShiftDirection.down);
await context.sync();
});