활성 시트에서 현재 활성 선택에 액세스합니다. 선택은 사용자가 시트에서 강조 표시한 셀의 집합으로, 인접하지 않은 범위일 수 있습니다. 선택한 셀 중 하나는 사용자의 현재 포커스가 있는 현재 셀입니다. 현재 셀은 Google Sheets UI에서 더 어두운 테두리로 강조표시됩니다.
constactiveSheet=SpreadsheetApp.getActiveSheet();constrangeList=activeSheet.getRangeList(['A1:B4','D1:E4']);rangeList.activate();constselection=activeSheet.getSelection();// Current Cell: D1console.log(`Current Cell: ${selection.getCurrentCell().getA1Notation()}`);// Active Range: D1:E4console.log(`Active Range: ${selection.getActiveRange().getA1Notation()}`);// Active Ranges: A1:B4, D1:E4constranges=selection.getActiveRangeList().getRanges();for(leti=0;i < ranges.length;i++){console.log(`Active Ranges: ${ranges[i].getA1Notation()}`);}console.log(`Active Sheet: ${selection.getActiveSheet().getName()}`);
활성 범위 중 하나에서 선택된 현재 (강조 표시된) 셀을 반환하거나 현재 셀이 없는 경우 null을 반환합니다.
constselection=SpreadsheetApp.getActiveSpreadsheet().getSelection();// Returns the current highlighted cell in the one of the active ranges.constcurrentCell=selection.getCurrentCell();
current cell 및 active range에서 시작하여 지정된 방향으로 이동하면서 현재 셀을 계속 덮으면서 next data cell를 덮을 수 있도록 범위의 적절한 가장자리가 이동된 조정된 범위를 반환합니다. 활성 범위가 방향의 dimension를 따라 제한되지 않으면 원래 활성 범위가 반환됩니다. 현재 셀이나 활성 범위가 없으면 null이 반환됩니다. 이는 편집기에서 범위를 선택하고 Ctrl+Shift+[arrow key]를 누르는 것과 같습니다.
// Assume the active spreadsheet is blank.constss=SpreadsheetApp.getActiveSpreadsheet();constsheet=ss.getSheets()[0];// Makes C3 the current cell and C3:E5 the active range.sheet.getRange('C3:E5').activate();// Logs 'C1:E3'console.log(SpreadsheetApp.getSelection().getNextDataRange(SpreadsheetApp.Direction.UP).getA1Notation(),);
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003eAccess and manipulate the active selection, which includes the highlighted cells and the current cell within a Google Sheet.\u003c/p\u003e\n"],["\u003cp\u003eUtilize methods like \u003ccode\u003egetActiveRange()\u003c/code\u003e, \u003ccode\u003egetCurrentCell()\u003c/code\u003e, and \u003ccode\u003egetActiveRangeList()\u003c/code\u003e to retrieve specific parts of the selection.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egetNextDataRange()\u003c/code\u003e method allows for expanding the selection to encompass adjacent data cells.\u003c/p\u003e\n"],["\u003cp\u003eEach of these methods requires specific authorization scopes for access to spreadsheet data.\u003c/p\u003e\n"],["\u003cp\u003eA selection can include non-adjacent ranges and provides programmatic control over user interactions with the sheet's data.\u003c/p\u003e\n"]]],["The content describes how to interact with cell selections in Google Sheets using Apps Script. Key actions include retrieving the `active range` (last selected range), `active range list` (all selected ranges), `current cell` (user's focus), and `active sheet`. The `getNextDataRange` method adjusts the active range to include the next data cell in a specified direction. These operations require authorization scopes related to spreadsheets. The script provided an example to retrieve all of those key elements from the selection.\n"],null,["Selection\n\nAccess the current active selection in the active sheet. A selection is the set of cells the user\nhas highlighted in the sheet, which can be non-adjacent ranges. One cell in the selection is the\n*current cell*, where the user's current focus is. The current cell is highlighted with a\ndarker border in the Google Sheets UI.\n\n```javascript\nconst activeSheet = SpreadsheetApp.getActiveSheet();\nconst rangeList = activeSheet.getRangeList(['A1:B4', 'D1:E4']);\nrangeList.activate();\n\nconst selection = activeSheet.getSelection();\n// Current Cell: D1\nconsole.log(`Current Cell: ${selection.getCurrentCell().getA1Notation()}`);\n// Active Range: D1:E4\nconsole.log(`Active Range: ${selection.getActiveRange().getA1Notation()}`);\n// Active Ranges: A1:B4, D1:E4\nconst ranges = selection.getActiveRangeList().getRanges();\nfor (let i = 0; i \u003c ranges.length; i++) {\n console.log(`Active Ranges: ${ranges[i].getA1Notation()}`);\n}\nconsole.log(`Active Sheet: ${selection.getActiveSheet().getName()}`);\n``` \n\nMethods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------------------|------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [getActiveRange()](#getActiveRange()) | [Range](/apps-script/reference/spreadsheet/range) | Returns the selected range in the active sheet, or `null` if there is no active range. |\n| [getActiveRangeList()](#getActiveRangeList()) | [RangeList](/apps-script/reference/spreadsheet/range-list) | Returns the list of active ranges in the active sheet or `null` if there are no active ranges. |\n| [getActiveSheet()](#getActiveSheet()) | [Sheet](/apps-script/reference/spreadsheet/sheet) | Returns the active sheet in the spreadsheet. |\n| [getCurrentCell()](#getCurrentCell()) | [Range](/apps-script/reference/spreadsheet/range) | Returns the current (highlighted) cell that is selected in one of the active ranges or `null` if there is no current cell. |\n| [getNextDataRange(direction)](#getNextDataRange(Direction)) | [Range](/apps-script/reference/spreadsheet/range) | Starting from the [current cell](#getCurrentCell()) and [active range](#getActiveRange()) and moving in the given direction, returns an adjusted range where the appropriate edge of the range has been shifted to cover the [next data cell](/apps-script/reference/spreadsheet/range#getNextDataCell(Direction)) while still covering the current cell. |\n\nDetailed documentation \n\n`get``Active``Range()` \nReturns the selected range in the active sheet, or `null` if there is no active range. If\nmultiple ranges are selected this method returns only the last selected range.\n\n```javascript\nconst selection = SpreadsheetApp.getActiveSpreadsheet().getSelection();\nconst activeRange = selection.getActiveRange();\n```\n\nReturn\n\n\n[Range](/apps-script/reference/spreadsheet/range) --- The active range.\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n`get``Active``Range``List()` \nReturns the list of active ranges in the active sheet or `null` if there are no active\nranges.\n\nIf there is a single range selected, this behaves as a [getActiveRange()](#getActiveRange()) call.\n\n```javascript\nconst sheet = SpreadsheetApp.getActiveSheet();\n// Returns the list of active ranges.\nconst activeRangeList = sheet.getActiveRangeList();\n```\n\nReturn\n\n\n[RangeList](/apps-script/reference/spreadsheet/range-list) --- The list of active ranges.\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n`get``Active``Sheet()` \nReturns the active sheet in the spreadsheet.\n\n```javascript\nconst selection = SpreadsheetApp.getActiveSpreadsheet().getSelection();\nconst activeSheet = selection.getActiveSheet();\n```\n\nReturn\n\n\n[Sheet](/apps-script/reference/spreadsheet/sheet) --- The active sheet in the spreadsheet.\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n`get``Current``Cell()` \nReturns the current (highlighted) cell that is selected in one of the active ranges or `null` if there is no current cell.\n\n```javascript\nconst selection = SpreadsheetApp.getActiveSpreadsheet().getSelection();\n// Returns the current highlighted cell in the one of the active ranges.\nconst currentCell = selection.getCurrentCell();\n```\n\nReturn\n\n\n[Range](/apps-script/reference/spreadsheet/range) --- The current cell.\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n`get``Next``Data``Range(direction)` \nStarting from the [current cell](#getCurrentCell()) and [active range](#getActiveRange())\nand moving in the given direction, returns an adjusted range where the appropriate edge of the\nrange has been shifted to cover the [next data cell](/apps-script/reference/spreadsheet/range#getNextDataCell(Direction)) while still\ncovering the current cell. If the active range is unbounded along the [dimension](/apps-script/reference/spreadsheet/dimension) of the direction, the original active range is returned. If there is no current cell\nor active range, `null` is returned. This is equivalent to selecting a range in the\neditor and hitting `Ctrl+Shift+[arrow key]`.\n\n```javascript\n// Assume the active spreadsheet is blank.\nconst ss = SpreadsheetApp.getActiveSpreadsheet();\nconst sheet = ss.getSheets()[0];\n\n// Makes C3 the current cell and C3:E5 the active range.\nsheet.getRange('C3:E5').activate();\n// Logs 'C1:E3'\nconsole.log(\n SpreadsheetApp.getSelection()\n .getNextDataRange(SpreadsheetApp.Direction.UP)\n .getA1Notation(),\n);\n```\n\nParameters\n\n| Name | Type | Description |\n|-------------|-----------------------------------------------------------|----------------------------------------------------------------|\n| `direction` | [Direction](/apps-script/reference/spreadsheet/direction) | The direction in which to find the next data region edge cell. |\n\nReturn\n\n\n[Range](/apps-script/reference/spreadsheet/range) --- The adjusted range that includes the data cell, or `null` if there is no\nselection.\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`"]]