구글 스프레드 시트에 데이터 쓰기

 

3번째 예제

function doGet(e) { Logger.log(e); return HtmlService.createHtmlOutputFromFile('page'); } function userClicked(name){ //스프레드 시트의 url 그대로 사용 var url = 'https://docs.google.com/spreadsheets/d/1kxYWuU7DKuCACpklifgq_t53EGx2dY9nByXSREoo61c/edit#gid=0' var ss = SpreadsheetApp.openByUrl(url); var ws = ss.getSheetByName("data"); ws.appendRow([name]); Logger.log(name + 'hello world!'); }
<!DOCTYPE html> <html> <head> <base target="_top"> </head> <body> <h1>hello</h1> <label for="username">name : </label> <input type="text" id="username"> <button id="btn">Run</button> <script> document.getElementById('btn').addEventListener('click', doStuff); function doStuff(){ var uname = document.getElementById('username').value; google.script.run.userClicked(uname); document.getElementById('username').value = ''; } </script> </body> </html>
  • 한글도 잘 들어감
  • 리스트 안에 있는 값을 변경해주면 아래처럼 다른 컬럼에 값이 들어가게 됨
    • ws.appendRow([name, name + 'hello']);
  • 아래와 같이 날짜 추가 가능
    • ws.appendRow([name, new Data()]);
notion imagenotion image
 
notion imagenotion image
 

css와 js 파일 분리
 
notion imagenotion image
 
notion imagenotion image
 
notion imagenotion image
 
변수선언
 
notion imagenotion image