Folder Tree
Code
function doGet(e) {
Logger.log(e);
//console.log(e);
Logger.log(e.parameter);
return HtmlService.createHtmlOutputFromFile('index');
}
function writeData(title, content){
const url = '여러분 스프레드 시트 url';
const ss = SpreadsheetApp.openByUrl(url);
const ws = ss.getSheetByName('data');
Logger.log(title, content);
ws.appendRow([title, content]);
}
function loadData(){
const url = '여러분 스프레드 시트 url';
const ss = SpreadsheetApp.openByUrl(url);
const ws = ss.getSheetByName('data');
let data = ws.getRange(1, 1, ws.getLastRow(), 2).getValues();
console.log(data);
return data;
}
index.html 파일
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h1>hello world!!</h1>
<label for="title">title : </label>
<input type="text" id="title">
<br>
<label for="content">content : </label>
<input type="text" id="content">
<button id="btn">write</button>
<br>
<button id="loadBtn">load data</button>
<script>
document.getElementById('btn').addEventListener('click', 글작성);
document.getElementById('loadBtn').addEventListener('click', 글불러오기);
function 글작성(){
let title = document.getElementById('title').value;
let content = document.getElementById('content').value;
google.script.run.writeData(title, content);
document.getElementById('title').value = '';
document.getElementById('content').value = '';
}
function 글불러오기(){
//google.script.run.loadData();
google.script.run.withSuccessHandler(function(data){
console.log(data);
}).loadData();
}
</script>
</body>
</html>