메뉴 건너뛰기

app

[GAS] 다른 시트의 내용 가져오기

lispro062014.07.24 01:30조회 수 1857댓글 0

    • 글자 크기


namedRange로 내용을 가져오는 방법을 사용했었는데, 이렇게 되면, 범위를 정의해야하는 번거로움이 있다.


  var range = ss.getSheets()[0].getRange("A1:F100"); 로 하면, 범위 정의 없이, 정해진 범위의 내용을 다 가져올 수 있다.


var ret_arr=selected_getOuterRangeValues(row,"sms");

  ral=ret_arr.length;


게 하여 호출하면, 내용이 있는 만큼만 배열로 가져와 범위가 100개라도 내용이 존재하는 배열 크기로 한정한다.

아래는 여러 시트를 참조하고자할 때, 정의한 switch 문이 사용된 함수이다.


  var ss_y=SpreadsheetApp.openById("시트iD");

  var ss_r=SpreadsheetApp.openById("시트iD");

  var ss_s=SpreadsheetApp.openById("시트iD");

  var ss_c=SpreadsheetApp.openById("시트iD");



function selected_getOuterRangeValues(k,s) {


  switch(s){

    case "reserve":

      var range_values = getOuterRangeValues(ss_y);

      break;

    case "remedy":

      var range_values = getOuterRangeValues(ss_r);

      break;

    case "sms":

      var range_values = getOuterRangeValues(ss_s);

      break;

    case "cosm":

      var range_values = getOuterRangeValues(ss_c);

      break;

  }

  if(k==null)

    k=1;

    var rl=range_values.length;

    var rv = new Array;

    var active_spreadsheet = SpreadsheetApp.getActiveSheet();

    var vl=active_spreadsheet.getRange(1, 1, 6, 4).getValues();

    var j=0;

  for(i=1;i<rl;i++){

    if(range_values[i][0]==vl[k][0] && range_values[i][1]==vl[k][1]){

      if(range_values[i][0])

        rv[j++]=range_values[i]; //존재하는 row 만큼 배열로 저장

    }

  }

      Logger.log(rv);

      return(rv);

}


// Return an array containing the values in the range name argument.

// Passing a non-existent range name raises the following error:

// TypeError: Cannot call method "getValues" of null. (line 0).

function getOuterRangeValues ( ss ) {

    // Create an spreadsheet object.

    // Create the range object.

    var range = ss.getSheets()[0].getRange("A1:F100");

  

    // Call the getValues() range object method to create an array 

    // containing the values for the cells in that named range.

    var range_values = range.getValues();

    Logger.log(ss.getName());

    // Return the array

    return range_values;

  

}

lispro06 (비회원)
    • 글자 크기
[XE] widget 짧은 팁 (by lispro06) [GAS] 구글 폼 에서 동적 선택 목록 구현 (by lispro06)

댓글 달기

lispro06
2015.05.15 조회 1632
lispro06
2015.05.15 조회 1600
lispro06
2015.05.15 조회 2492
lispro06
2014.08.16 조회 1739
lispro06
2014.02.08 조회 3979
lispro06
2013.12.11 조회 1648
lispro06
2013.12.10 조회 2953
suritam9
2013.12.06 조회 2249
suritam9
2013.12.02 조회 3423
suritam9
2013.11.30 조회 2139
suritam9
2013.11.26 조회 1626
suritam9
2013.08.23 조회 7291
suritam9
2013.08.23 조회 1826
suritam9
2013.06.28 조회 2313
첨부 (0)
위로