从工作表访问数据
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;
}