Get Values using getRange(sheet!range)
This post is a corrected post after AI explains the code included in the book “Google Apps Script 101: Building Work Automation For Free”. Added a strikethrough when editing what AI has written, and added color when edited by author
Table of Contents
Summary
In this blog post, we will explore how to retrieve values from a specific range in a Google Spreadsheet using Apps Script. We will use the getRange
and getValues
methods to retrieve the values in the range ‘시트2!A1:C3’ and log them using the Logger
class.
Code
1 2 3 4 5 |
function getA1C3Values_1() { const SS = SpreadsheetApp.getActiveSpreadsheet() const value = SS.getRange('시트2!A1:C3').getValues() Logger.log(value) } |
Code Explanation
The code defines a function named getA1C3Values_1
. It uses the SpreadsheetApp.getActiveSpreadsheet()
method to get the active spreadsheet, and the getRange
method to specify the range ‘시트2!A1:C3’. The getValues
method is then used to retrieve the values in that range. Finally, the Logger.log
statement is used to log the retrieved values.
Example
When the getA1C3Values_1
function is executed, the values in the range ‘시트2!A1:C3’ will be logged in the Apps Script Logger.
AI Prompt
Write a function that retrieves the values from the range ‘시트2!A1:C3’ in a Google Spreadsheet and logs them using the Logger
class.