Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 624
craftApprentice Avatar asked Nov 30 '13 21:11

craftApprentice


People also ask

Why is my Google script not working?

There are a few possible causes for these errors: A Google server or system is temporarily unavailable. Wait for a few moments and try running the script again. There is an error in your script that doesn't have a corresponding error message.

How can you get the last row of data range in a Google Sheet using app script?

If the column has no null cells, you can retrieve the number of last row for a specific column by following script. This doesn't create a temporary sheet. var last_row = ss. getRange(1, col, ss.

How do you insert a line break in Google script?

Add a Line Break with Keyboard Shortcuts Select the cell you want to add a line break to and type in the text you want before the line break, then type CTRL+ENTER on your keyboard to insert a line break.


1 Answers

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

like image 68
craftApprentice Avatar answered Oct 11 '22 23:10

craftApprentice