简体   繁体   中英

Google Spreadsheets and sheets

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?
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM