2013-12-14 2 views
0

나는 수백 개의 행이있는 스프레드 시트를 가지고 있고 A 열은 고유 레코드 번호입니다.주어진 값의 조회 셀 참조

입력 된 고유 레코드 번호를 기반으로 셀 참조를 찾을 수있는 방법을 배우고 싶습니다.

예를 들어 통화 A1에서 값 11을 입력하면 Google 스크립트를 사용하여 셀 행 (예 : 17)을 검색 할 수 있습니다.

당신은 귀하의 첫 번째 열에서 "검색"수행하고 발견 된 세포 (전체 행) 활성화 간단하고 작은 UI를 구축 할 수 있습니다 도움

Taizoon

답변

0

주셔서 감사합니다. 아래에 예가 나와 있습니다. 반복적으로 (지금처럼) 사용하거나 한 줄의 코드 만 변경하여 한 번만 사용하는 옵션이 있습니다. 처리기 함수 끝에있는 주석을 참조하십시오. :

function showInSheet() { 
    var app = UiApp.createApplication().setTitle('Search and Select').setWidth(250).setHeight(60); 
    var panel = app.createVerticalPanel(); 
    var searchHandler = app.createServerHandler('searchRow').addCallbackElement(panel); 
    var Hpanel = app.createHorizontalPanel(); 
    var search = app.createTextBox().setName('search').setId('search').setWidth('70').addKeyUpHandler(searchHandler); 
    var warning = app.createHTML('incomplete or invalid entry').setId('warning').setStyleAttributes({'padding-left':'10px','background':'yellow','fontSize':'8pt'}).setVisible(false); 
    app.add(panel.add(Hpanel.add(search).add(warning))); 
    SpreadsheetApp.getActive().show(app); 
} 

function searchRow(e){ 
    var app = UiApp.getActiveApplication(); 
    var item = e.parameter.search; 
    var sh = SpreadsheetApp.getActiveSheet(); 
    var data = sh.getRange(1,1,sh.getLastRow(),1).getValues().join().split(',');// the 2D array is "flattened" and splitted to get a 1D array 
    Logger.log(data.length); 
    var idx = data.indexOf(item);// in a "simple" array we can use this array function more easily to seach in it ;-) 
    Logger.log(idx); 
    if(idx>data.length || idx==-1){app.getElementById('warning').setVisible(true) ; return app}; 
    idx++;// increment because rows count from 1 instead of 0 in arrays 
    var itemRange = sh.getRange(idx,1,1,sh.getMaxColumns()); 
    sh.setActiveSelection(itemRange); 
// return app.close();// can be replace by next line (uncommented) 
    app.getElementById('search').setText('');app.getElementById('warning').setVisible(false);return app; 
} 
+0

고맙습니다.이 예제를 실행하고 내 열을 검색하는 Ui를 만듭니다. 도움을 주셔서 대단히 감사합니다. – Taizooooon