apps-script-utils 2.1.1 Help

prependRows

function prependRows( target: GoogleAppsScript.Spreadsheet.Sheet | GoogleAppsScript.Spreadsheet.Range, values: unknown, options: PrependRowsOptions | null | undefined = {} ): GoogleAppsScript.Spreadsheet.Sheet;

Room is made first and the values are written into it, so nothing already on the sheet is overwritten. Given a sheet the rows go to its top; given a range they go above the range's first row and the values are written on its columns.

A cell whose text starts with = is written as a formula, not as text — the same rule the editor follows.

A failure inside the write — the service unavailable, the sheet gone — comes back as the error the service raised, with its stack. The document lock is released either way.

Parameters

Parameter

Type

Description

target

GoogleAppsScript.Spreadsheet.Sheet \| GoogleAppsScript.Spreadsheet.Range

The sheet to insert into, or the range to insert at.

values

unknown

A matrix of rows: one array per row, all of the same length.

options (optional) = {}

PrependRowsOptions \| null \| undefined

afterFrozenRows inserts below the frozen rows instead of at the very top. A range decides the position itself, so the option does nothing there.

Returns

GoogleAppsScript.Spreadsheet.Sheet — the sheet, so calls can be chained.

Throws

Exception

Condition

IllegalArgumentException

no argument is passed.

InvalidSheetException

the first argument is neither a sheet nor a range.

TypeError

the values are not a matrix with rows of equal length.

Examples

Inserting at the top of a sheet

const sheet = SpreadsheetApp.getActiveSheet(); prependRows(sheet, [ ["Name", "Email"], ["Ada", "ada@example.com"] ]);

Inserting at a range

const sheet = SpreadsheetApp.getActiveSheet(); prependRows(sheet.getRange("B4:C13"), [["Name", "Email"]]);

See also

Source

src/appsscript/sheet/prependRows.ts

23 September 2026

This documentation was generated with AI (Claude) from the library's source code.