Google Apps Script: when to use getActiveSpreadsheet ()

I am trying to figure out when to use getActiveSpreadsheet() .

I have seen numerous examples:

 var ss = SpreadsheetApp.getActiveSheet(); 

But I also saw:

 var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); 

Is an active spreadsheet in some circumstances?

+5
source share
2 answers

Yes, that’s implied. reference for SpreadsheetApp:

getActiveSheet ()

Gets the active worksheet in a spreadsheet. An active sheet in a spreadsheet is a sheet that appears in a spreadsheet. User interface.

The inclusion of getActiveSpreadsheet () is probably often done because getting a spreadsheet is necessary for other sheets and methods, and it maintains a consistent flow of commands when done everywhere.

+4
source

getActiveSheet () is useful when you are working with a single sheet in an active spreadsheet.

You should use getActiveSpreadsheet () when you need to use other methods, for example getSheets () will get all the sheets and you will be able to access them as an array. Or if you want to work with a spreadsheet as opposed to the worksheet itself.

A good example is the methods available to the table class that would not be available for the class sheet

0
source

Source: https://habr.com/ru/post/1233786/


All Articles