Title1

Title2

Title3

9-3 設成class的靜態方法

 



function setup(){
  let sheet = "工作表5";
  let ws = Sheet.getWs(sheet);
  if(ws == null){
    //建立工作表
    ws = SpreadsheetApp.getActiveSpreadsheet().insertSheet();
    //設定工作表名稱
    ws.setName(sheet);
    let row = ["繳費單位","繳費日期","繳費金額","備註"];
    for(i in row){
      Sheet.setCellData(sheet,1,parseInt(i)+1,row[i],'文字');
    }
  }

  // let sheet = "工作表6";
  // Sheet.createSheet(sheet);
  // let row = ["繳費單位","繳費日期","繳費金額","備註"];
  // Sheet.setHead(sheet,row);

}

class Sheet{
  // .....
  
  //建立工作表
  static createSheet(sheet){
    //取得工作表
    let ws = this.getWs(sheet);
    if(ws === null){//工作表不存在
      //建立工作表,並取得工作表
      ws = SpreadsheetApp.getActiveSpreadsheet().insertSheet();
      //設定工作表名稱
      ws.setName(sheet);
    }
  }

  //設定標題列
  static setHead(sheet,row){
    let i ;
    for(i in row){
      this.setCellData(sheet,1,parseInt(i)+1,row[i],'文字');
    }
  }

}