[Apps Script] 시트id값을 활용하여 시트 내용 카피하기

sonhm·2021년 5월 12일
0

구글 스프레드 시트에서도 id값을 이용하면, 관계형 데이터 베이스처럼 활용할 수 있다. 보통 importrange 수식을 활용해서 구축하지만, copyto를 활용하면 복사한 값 자체가 동기화하여 시트의 부하를 줄일 수 있게 된다.

결과

변경 전

변경 후

코드

function LearnBasics() {
  var source = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = source.getSheets()[1]; //2번째 탭을 복사할 시트로 지정
  var destination = SpreadsheetApp.openById('18surAZTrk4jTYb__pHCR3Gtgm3MtNOa5_6CR2g9PAes');
  sheet.copyTo(destination); //destination 변수에 복사할 시트를 copy & paste
}

구글 문서의 id 값 찾는 방법

Opens the spreadsheet with the given ID. A spreadsheet ID can be extracted from its URL. For example, the spreadsheet ID in the URL https://docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 is "abc1234567".


구글스프레드시트의 id값을 파악하는 방법 : d/부터 다음 /까지가 구글스프레드 시트의 id값이다.

// The code below opens a spreadsheet using its ID and logs the name for it.
// Note that the spreadsheet is NOT physically opened on the client side.
// It is opened on the server only (for modification by the script).
var ss = SpreadsheetApp.openById("abc1234567");
Logger.log(ss.getName());

참고자료

apps script 공식문서

profile
기발한 기발자

0개의 댓글