2012-06-29 2 views
2

UI 웹 앱 배포. 배포 스크립트 URL을 보려고 후 "널 (null)의"getSheets "방법을 호출 할 수 없습니다"형식 오류를 얻기 :GAS에 UI 웹 앱을 처음 배포 할 때

https://docs.google.com/spreadsheet/ccc?key=0AnJTymuE8awLdHZ6QzhNVXpjeFphM3pMV1cxU0daZ2c

스크립트 코드 :

다음

https://script.google.com/macros/s/AKfycbzuQNbkTeBpRPz75Q4dRiVLfEYtuLiuBKnWeA5CbD0/dev

하면 스프레드 시트의

// https://developers.google.com/apps-script/class_listbox - How to create listBox 
function doGet() { 
    //var ss = SpreadsheetApp.openById("0AnJTymuE8awLdHZ6QzhNVXpjeFphM3pMV1cxU0daZ2c"); 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var sheet = ss.getSheets()[1]; 
    var app = UiApp.createApplication().setTitle('App to show how ListBox data can update'); 
    var panel = app.createVerticalPanel(); 
    var lb = app.createListBox(true).setId('myLBid').setName('myLBname'); 

    // how many items to show 
    lb.setVisibleItemCount(10); 

    // get sorted names 
    var rows = sheet.getDataRange(); 
    var numRows = rows.getNumRows(); 
    var values = rows.getValues(); 

    for (var i = 0; i <= numRows - 1; i++) { 
    var row = values[i]; 
    lb.addItem(row); 
    } 

    panel.add(lb); 
    var button = app.createButton('Submit'); 
    var handler = app.createServerClickHandler('respondToSubmit').addCallbackElement(panel); 
    button.addClickHandler(handler); 
    panel.add(button); 
    app.add(panel); 
    ss.show(app); 
} 

// http://youtu.be/5VmEPo6Rkq4 - How to have sumbit write data to ss 
function respondToSubmit(e) { 
    var app = SpreadsheetApp.getActiveSpreadsheet(); 
    //reference widget name to capture what user selected 
    var listBoxValue = e.parameter.myLBname; 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var sheet = ss.getSheets()[2]; 
    var lastRow = sheet.getLastRow()+1; 
    var lastCell = sheet.getRange("A"+lastRow); 
    lastCell.setValue(listBoxValue); 
    return app.close(); 
} 

/** 
* Adds a custom menu to the active spreadsheet, containing a single menu item 
* for invoking the readRows() function specified above. 
* The onOpen() function, when defined, is automatically invoked whenever the 
* spreadsheet is opened. 
* For more information on using the Spreadsheet API, see 
* https://developers.google.com/apps-script/service_spreadsheet 
*/ 
function onOpen() { 
    var sheet = SpreadsheetApp.getActiveSpreadsheet(); 
    var entries = [{ 
    name : "Names", 
    functionName : "doGet" 
    }]; 
    sheet.addMenu("Script Menu", entries); 
}; 

편집기에서 실행하면 완벽하게 작동합니다.

웹 앱이 작동하도록 코드에서 수정해야 할 부분을 찾고 싶습니다. ss 내부에서 실행될 때처럼 스크립트 URL에 UI가 나타날 것으로 기대합니다. 그게 무슨 일이 아니야?

답변

3

편집 : Ooops, 죄송합니다. 다른 오류를 발견하지 못했습니다. differences between webApps and spreadsheet UIs에 대한 문서를보고 그 후에 내 대답을 읽어보십시오.

왜이 줄을 주석 처리하셨습니까?

SpreadsheetApp.openById("0AnJTymuE8awLdHZ6QzhNVXpjeFphM3pMV1cxU0daZ2c");

웹 애플리케이션으로 실행 당신이해야 ID로 항상 열려 스프레드 시트 활성 스프레드 시트가 없기 때문에 (더 사용자 스프레드 시트를 열 수 없습니다 스프레드 시트에서보기 만 스크립트가있다 ...)

또한 정확히 무엇을 의미합니까? "UI가 스크립트 URL에 표시 될 것으로 기대하고 있습니다"?

(그 일을 할 때 너무 그것의 버전을 저장해야하지만 아주 잘 설명한 것) 당신은 당신이 그것을 배포 할 때 생성되는 URL에 갈 때 귀하의 UI가. 독립 실행 형 응용 프로그램으로 표시됩니다

+0

내가 왜 openById를 사용했는지, 왜 내가 댓글을 남겼는지 확신 할 수 없습니다. 나는 'return app;'이 필요하다는 것을 놓쳤다. 문서에서. 감사합니다. http://goo.gl/FTIKB –

관련 문제