Google Apps Script: `Those rows are out of bounds.` error

google-apps-script, google-sheets

Solution

I find my mistake: row counting starts with 1 and not 0, so I should be written: `sheet.deleteRows(1, 22);`

Problem

I have this issue: I download a excell file, upload it (converting it to google spreadsheet format) and I have to adapt it to a structure with which I can use it with my scripts. To do that, I have to delete several rows and columns of the excell file (there are some pictures and extra lines in the excell header). So, I'm writing a script to automate this tasks. But when I run this script, to delete the first 22 rows: ``` function onOpen() { var menuEntries = [{name: "Format this sheet", functionName: "format"}]; var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.addMenu("My scripts", menuEntries); } function format() { var sheet = SpreadsheetApp.getActiveSheet(); sheet.deleteRows(0, 22); // sheet.deleteColumns(columnPosition, howMany) } ``` I get this error: `Those rows are out of bounds.` (the spreadsheet has more than 400 rows) How can I fix that?

Original source