Aim of the puzzle: Use Apps Script to access a spreadsheet in Sheets and print some of its data.
Walk through of the solution: Apps Script has custom code functions that connect to Sheets. One example is SpreadsheetApp.openById()
, which works just like DocumentApp.openById()
. It takes an id and gets the matching spreadsheet from Sheets.
Another is .getRange().getValues()
, which selects a range of cells on a spreadsheet and returns their values as a nested array.
To complete the puzzle, change the string inside the parentheses of .getRange()
from 'A3:B6
’ to 'A2:B6'
.
Sample code solution:
let id = '1QE4pZs8efMoHKGOEHyXGT_nPZf1b_Sw7ssFCk2J2ueo';
let sheet = SpreadsheetApp.openById(id);
let values = sheet.getRange("A2:B6").getValues();
console.log(values[0][0]);
JavaScript concepts: Variables, Strings, Nested Arrays
Apps Script concepts: SpreadsheetApp
, .openById()
, .getRange().getValues()