寫入資料
function myFunction() {
//Logger.log("Hello World");
var url = "https://docs.google.com/spreadsheets/d/1TSFg5mocDvsaYOxHjClSAKhOJKtN4sc_gxDpQTkzNGc/edit#gid=0";
var ss = SpreadsheetApp.openByUrl(url);//打開試算表
var name = "聯絡我們";//工作表
var ws = ss.getSheetByName(name);//取得工作表
//姓名、電話、email、聯絡內容
var row = ["姓名","電話","email","聯絡內容"];
ws.appendRow(row);//寫入資料
}
練習["name","tel","email","content"] 寫入
function myFunction() {
//Logger.log("Hello World");
var url = "https://docs.google.com/spreadsheets/d/1TSFg5mocDvsaYOxHjClSAKhOJKtN4sc_gxDpQTkzNGc/edit#gid=0";
var ss = SpreadsheetApp.openByUrl(url);//打開試算表
var name = "聯絡我們";//工作表
var ws = ss.getSheetByName(name);//取得工作表
//姓名、電話、email、聯絡內容
//var row = ["姓名","電話","email","聯絡內容"];
//ws.appendRow(row);//寫入資料
//寫入資料另一種方法
//name、tel、email、content
var row = ["name","tel","email","content"];
var lastRow = ws.getLastRow()+1; // 得到最新列指標
// getRange(row位置, col位置, row數量, col數量)
ws.getRange(lastRow, 1, 1, row.length).setValues([row]);
}