Title1

Title2

Title3

8-5 JS class 靜態方法 - 取得「資料列」

取得資料列


class Sheet{
  //取得工作表
  static getWs(sheet){
    return SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet);//取得工作表
  }

  //取得標題列
  static getHead(sheet){
    let ws = this.getWs(sheet);
    let data = ws.getSheetValues(1,1,1,ws.getLastColumn())[0];
    return data;
  }

  //取得資料列
  static getData(sheet){
    let ws = this.getWs(sheet);
    let data = ws.getSheetValues(2,1,ws.getLastRow()-1 ,ws.getLastColumn());
    return data;
  }
}


function ex3(){
  // let ws = Sheet.getWs('工作表1');

  //取得標題列
  // let head = Sheet.getHead('工作表1');
  // console.log(head);

  //取得資料列
  let data = Sheet.getData('工作表1');
  console.log(data);

}