주셔서 감사합니다. 아래에 예가 나와 있습니다. 반복적으로 (지금처럼) 사용하거나 한 줄의 코드 만 변경하여 한 번만 사용하는 옵션이 있습니다. 처리기 함수 끝에있는 주석을 참조하십시오. :
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;
}
고맙습니다.이 예제를 실행하고 내 열을 검색하는 Ui를 만듭니다. 도움을 주셔서 대단히 감사합니다. – Taizooooon