0
votes

It seems like in the documentation that Google Spreadsheets and Google Sheets both have methods such as getActiveCell() which leads to confusion what the difference between the "Spreadsheet" object and the "Sheet" object. I assume that a spreadsheet is a collection of sheets. Suppose that I want to open a file with the following code where my Spreadsheet only has 1 sheet (see question in commented lines and assume I want to then do operations on the first sheet of both files):

function OpenFile(FileName) {
  var FileToGetIterator = DriveApp.getFilesByName(FileName);
  var FileToGet = FileToGetIterator.next();
  var SpreadSheets = SpreadsheetApp.open(FileToGet);
  var SpreadSheet1 = SpreadSheets.getSheets()[0]; // is this line necessary??
}

Similarly for creating a file

function CreateFile(SpreadSheetName) {
  var NewSpreadSheets = SpreadsheetApp.Create(SpreadSheetName); 
  var NewSpreadSheet = NewSpreadSheets.getSheets()[0]; // is this line necessary?
}
1

1 Answers

1
votes

when you create a spreadsheet or you open a spreadsheet it automatically open the first sheet of the spreadsheet,so no it's not necessary. nevertheless the opened sheet is opened as the "activesheet" and you've got less methods than if you specifically open a particular sheet with your method