Skip to content
Advertisement

Google Sheets API Insert Row at a Row Position

I am using the Google API to add rows to a Google Sheet. This is all working well, but the new rows are being added to the end (using the append method).

I would like to insert the row at the top, below the heading, in my case Row 2.

This is my working code for adding to the end. How can I specify where I want to insert the row at a given position.

JavaScript

Advertisement

Answer

You are using values.append which by definition appends values to the first empty row

If you want to insert your values in a range that is not the first empty row of the sheet, you need to use instead the method values.batchUpdate

Sample:

JavaScript

UPDATE

  • I you want to insert a row with with data rather than pasting data into an already existing row – you need to create the additional row first.

This can be done with a InsertDimensionRequest.

Sample:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement