/** * Creates a Sheets API service object and prints the names and majors of * students in a sample spreadsheet: * https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get */functionlogNamesAndMajors(){constspreadsheetId='1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms';constrangeName='ClassData!A2:E';try{// Get the values from the spreadsheet using spreadsheetId and range.constvalues=Sheets.Spreadsheets.Values.get(spreadsheetId,rangeName).values;// Print the values from spreadsheet if values are available.if(!values){console.log('Nodatafound.');return;}console.log('Name,Major:');for(constrowinvalues){// Print columns A and E, which correspond to indices 0 and 4.console.log('-%s,%s',values[row][0],values[row][4]);}}catch(err){// TODO (developer) - Handle Values.get() exception from Sheet APIconsole.log(err.message);}}
[null,null,["最后更新时间 (UTC):2024-12-21。"],[[["This quickstart demonstrates how to use Google Apps Script to connect to and retrieve data from the Google Sheets API."],["You will need a Google Account and access to Google Drive to complete the setup."],["The process involves creating a script, enabling the Google Sheets API, and authorizing access for the script to interact with your spreadsheets."],["Upon successful execution, the script will print data from a sample spreadsheet to the execution log."],["For production environments, further exploration of authentication, authorization, and credential management is recommended."]]],["This document outlines setting up and running a Google Apps Script that interacts with the Google Sheets API. Key actions include: configuring the environment, creating a script, enabling the Sheets API service, and running the script. The script accesses a sample spreadsheet, retrieves student names and majors, and logs them. Authentication authorization is required initially. Client libraries for API are recommended. It also provides links for advanced learning, troubleshooting and bug reporting.\n"]]