💾app.sheetByName()

GASappmethods ⟩ sheetByName()

  // 🔸 app.sheetByName()
  sheetByName(name) {

    const ss = app.spreadsheet;
    let sheet = ss.getSheetByName(name);

    // if no such sheet, append a new one.
    if(sheet === null){ 
      let i = ss.getNumSheets();          // 目前的有幾頁
      sheet = ss.insertSheet(name, i);    // 插入最後面 (⭐️ will activate automatically)
    }

    sheet.activate();                     // ⭐️ activate before returning        
    sheet.__proto__ = app.sheetPrototype; // ⭐️ extend sheet 
    return sheet;
  },

Last updated