A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/apps-script/reference/spreadsheet/selection below:

Class Selection | Apps Script

Class Selection

Stay organized with collections Save and categorize content based on your preferences.

Selection

Access the current active selection in the active sheet. A selection is the set of cells the user has highlighted in the sheet, which can be non-adjacent ranges. One cell in the selection is the current cell, where the user's current focus is. The current cell is highlighted with a darker border in the Google Sheets UI.

const activeSheet = SpreadsheetApp.getActiveSheet();
const rangeList = activeSheet.getRangeList(['A1:B4', 'D1:E4']);
rangeList.activate();

const selection = activeSheet.getSelection();
// Current Cell: D1
console.log(`Current Cell: ${selection.getCurrentCell().getA1Notation()}`);
// Active Range: D1:E4
console.log(`Active Range: ${selection.getActiveRange().getA1Notation()}`);
// Active Ranges: A1:B4, D1:E4
const ranges = selection.getActiveRangeList().getRanges();
for (let i = 0; i < ranges.length; i++) {
  console.log(`Active Ranges: ${ranges[i].getA1Notation()}`);
}
console.log(`Active Sheet: ${selection.getActiveSheet().getName()}`);
Detailed documentation getActiveRange()

Returns the selected range in the active sheet, or null if there is no active range. If multiple ranges are selected this method returns only the last selected range.

const selection = SpreadsheetApp.getActiveSpreadsheet().getSelection();
const activeRange = selection.getActiveRange();
Return

Range — The active range.

Scripts that use this method require authorization with one or more of the following scopes:

getActiveRangeList()

Returns the list of active ranges in the active sheet or null if there are no active ranges.

If there is a single range selected, this behaves as a getActiveRange() call.

const sheet = SpreadsheetApp.getActiveSheet();
// Returns the list of active ranges.
const activeRangeList = sheet.getActiveRangeList();
Return

RangeList — The list of active ranges.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

getActiveSheet()

Returns the active sheet in the spreadsheet.

const selection = SpreadsheetApp.getActiveSpreadsheet().getSelection();
const activeSheet = selection.getActiveSheet();
Return

Sheet — The active sheet in the spreadsheet.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

getCurrentCell()

Returns the current (highlighted) cell that is selected in one of the active ranges or null if there is no current cell.

const selection = SpreadsheetApp.getActiveSpreadsheet().getSelection();
// Returns the current highlighted cell in the one of the active ranges.
const currentCell = selection.getCurrentCell();
Return

Range — The current cell.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

getNextDataRange(direction)

Starting from the current cell and active range 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 while still covering the current cell. If the active range is unbounded along the dimension of the direction, the original active range is returned. If there is no current cell or active range, null is returned. This is equivalent to selecting a range in the editor and hitting Ctrl+Shift+[arrow key].

// Assume the active spreadsheet is blank.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = 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(),
);
Parameters Name Type Description direction Direction The direction in which to find the next data region edge cell. Return

Range — The adjusted range that includes the data cell, or null if there is no selection.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-12-02 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-02 UTC."],[[["Access and manipulate the active selection, which includes the highlighted cells and the current cell within a Google Sheet."],["Utilize methods like `getActiveRange()`, `getCurrentCell()`, and `getActiveRangeList()` to retrieve specific parts of the selection."],["The `getNextDataRange()` method allows for expanding the selection to encompass adjacent data cells."],["Each of these methods requires specific authorization scopes for access to spreadsheet data."],["A selection can include non-adjacent ranges and provides programmatic control over user interactions with the sheet's data."]]],["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"]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4