function readSpreadsheet() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const data = sheet.getRange(1, 1).getValue(); // 讀取第一行第一列
Logger.log("讀取的數據是:" + data);
}
步驟:
function writeSpreadsheet() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.getRange(2, 2).setValue("新數據"); // 修改第二行第二列
}
步驟:
function readMultipleCells() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const rangeData = sheet.getRange(1, 1, 3, 3).getValues(); // 讀取範圍
Logger.log("範圍內的數據是:" + JSON.stringify(rangeData));
}
步驟: