從工作表訪問資料

function getSheetData() {

  var sheet = SpreadsheetApp.getActiveSheet();

  var startRow = 2;  // First row of data to process
  var numRows = 100;   // Number of rows to process
  var startCol = 1;  //First column of data to process
  var numCols = 15;    // Number of columns to process 
  
  var dataRange = sheet.getRange(startRow, startCol, numRows, numCols);

  // Fetch values for each row in the Range.
  var data = dataRange.getValues();  

  return data;  
}

你還可以按如下方式修改上述功能,以便從工作表中的內容獲取動態資料範圍:

function getDataSheet() {

  sheet = SpreadsheetApp.getActiveSheet();
   
   //Get data range based on content
  var dataRange = sheet.getDataRange();

  // Fetch values for each row in the Range.
  var data = dataRange.getValues();  

  return data;  
}