一、常用
//必須由試算表建立指令碼編輯器 var ss = SpreadsheetApp.getActiveSpreadsheet();
//設定試算表 id
SCRIPT_PROP.setProperty("id", ss.getId());
//1. Run > setup
var SCRIPT_PROP = PropertiesService.getScriptProperties(); // new property service
//將試算表id 寫入屬性
function setup() {
//必須由試算表建立指令碼編輯器
var ss = SpreadsheetApp.getActiveSpreadsheet();
//設定試算表 id
SCRIPT_PROP.setProperty("id", ss.getId());
//管理員email
SCRIPT_PROP.setProperty("adminEmail", Session.getActiveUser().getEmail());
//取得全域變數(試算表有異動,請執行 setup())
var ws = ss.getSheetByName("全域變數");
//取得「全域變數」陣列
var global = ws.getSheetValues(2,1,ws.getLastRow()-1,ws.getLastColumn());
var colName = global.map(function(r){ return r[1] });//欄位名稱
var colValue = global.map(function(r){ return r[3] });//值
for(i in colName){
SCRIPT_PROP.setProperty(colName[i], colValue[i]);
}
}
二、getRange()
三、取得資料
getSheetValues(startRow, startColumn, numRows, numColumns):
getLastColumn():取得最後有資料的欄座標
getLastRow():取得最後有資料的列座標
四、設定資料
五、取得訪客的gmail
六、寫入資料
/* 在最後一列寫入(1) */
/* 109021 A123456809 林暗十一 60 85 90 60 59 */
var rowIndex = ws.getLastRow() + 1;
var row = ["109021", "A123456809", "林暗十一", 60, 85, 90, 60, 59];
var values = [row];
/* 寫入一列的某範圍,欄數與values的數量要批配 */
ws.getRange(rowIndex, 1, 1, ws.getLastColumn()).setValues(values);
/* 在最後一列寫入(2) */
/* 109021 A123456809 林暗十一 60 85 90 60 59 */
//var row = ["109021", "A123456809", "林暗十一", 60, 85, 90, 60, 59];
//ws.appendRow(row);
/* 寫入某一儲存格 */
//ws.getRange("A22").setValue("'" + "109021");
七、