Accessing Sheet, cell, range, and offset
A Google Sheet's spreadsheet has one or more Sheets or tabs in it. Sheets are indexed from left to right starting from 0. For example, the left-most Sheet is referred to by the index 0, the next one by 1, and so on. In GAS, we can refer to a Sheet by its index or by its name.
For example:
- The
getSheets()
method returns an array of Sheet objects. From the array, we can refer to an individual Sheet by its index. - The
getSheetByName("Contacts")
function returns a Sheet object with the nameContacts
.
In Google Sheets, column label starts from the letter A, and is counted in a programmatic point of view, from left to right starting with the number 1. For example, column A is 1, B is 2, and so on. Rows are identified by their respective label numbers. In GAS, we can reference a cell or a range of cells by A1 notation or by separate row and column numbers.
For example:
- The
getRange('D1:F10')
method returns aRange
object referencing the...