function doGet() {
return HtmlService.createHtmlOutput(`
<!DOCTYPE html>
<html>
<head>
<title>Apps Script 與 HTML</title>
</head>
<body>
<h1>歡迎來到我的網頁!</h1>
<button onclick="google.script.run.showAlert()">點擊我</button>
<script>
function showAlert() {
alert("你好!這是一個動態訊息。");
}
</script>
</body>
</html>
`);
}
步驟:
function doGet() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const data = sheet.getRange(1, 1).getValue(); // 取得第一行第一列的值
return HtmlService.createHtmlOutput(`
<!DOCTYPE html>
<html>
<head>
<title>顯示試算表數據</title>
</head>
<body>
<h1>從試算表讀取的數據是:</h1>
<p>` + data + `</p>
</body>
</html>
`);
}
步驟: