Skip to content

Latest commit

 

History

History
41 lines (27 loc) · 1.45 KB

excel-add-ins-ranges-insert.md

File metadata and controls

41 lines (27 loc) · 1.45 KB
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

Insert a range of cells using the Excel JavaScript API

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]

Insert a range of cells

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();
});

Data before range is inserted

Data in Excel before range is inserted.

Data after range is inserted

Data in Excel after range is inserted.

See also