Search code examples
google-sheetsgoogle-apps-scriptgoogle-sheets-api

Getting Sheet to Modify It with Apps Script


I want to delete a row from my sheet via Apps Script. I've been searching for answers. The documentation here uses getActiveSpreadsheet() method, but it always returns null to me. I don't understand how 'active spreadsheet' and 'non-active spreadsheet' work. Is there any way that I can get my spreadsheet by ID instead? Or do you have any other solution? I read in some parts that there is 'bound script' but I don't know how it works.

P.S. I used to use these methods to append and update my sheet. Could have it been expired so that I can't find the official documentation?

Sheets.Spreadsheets.Values.append(resource,spreadsheetId,range,optionalArgs);
Sheets.Spreadsheets.Values.update(resource,spreadsheetId,range,optionalArgs);

Solution

  • This will delete the first row.

    SpreadsheetApp.openById('Id').getSheetByName('SheetName').deleteRow(1);