2014-09-29 116 views
0

我正在嘗試學習UI服務以構建我自己的窗體(面板)。我試圖複製和運行示例面板,但我無法使其工作(代碼如下)。面板不會彈出。我必須在瀏覽器中設置某些內容嗎?請幫忙。無法讓UI工作

function doGet() { 
// A script with a user interface that is published as a web app 
// must contain a doGet(e) function. 

// Create the UiInstance object myapp and set the title text 
var myapp = UiApp.createApplication().setTitle('Here is the title bar'); 

// Create a button called mybutton and set the button text 
var mybutton = myapp.createButton('Here is a button'); 

// Create a vertical panel called mypanel and add it to myapp 
var mypanel = myapp.createVerticalPanel(); 

// Add mybutton to mypanel 
mypanel.add(mybutton); 

// Add my panel to myapp 
myapp.add(mypanel); 

// return myapp to display the UiInstance object and all elements associated with it. 
return myapp; 

} 
+0

你是怎麼試這個代碼?你是否已經完成了版本/部署要求? – 2014-09-29 19:18:21

+0

您必須從發佈的URL訪問您的腳本,它不會在手動運行時彈出。 – 2014-09-29 19:22:21

+0

請閱讀此處的文檔https://developers.google.com/apps-script/guides/web?hl=fr-FR – 2014-09-29 19:25:07

回答

0

doGet()功能運行時,你的應用程序的網址可能首先在瀏覽器中加載,刷新頁面在瀏覽器中。如果您的應用程序是獨立版應用程序(未附加到工作表或文檔),那麼您將在Google雲端硬盤中擁有與該應用程序關聯的文件。 Apps腳本文件圖標是一個藍色方塊,右邊有一個白色箭頭。

Apps Script File in Drive

如果您雙擊該文件,它應該在你的瀏覽器中打開並運行doGet()功能。您還可以提供該應用程序的URL作爲鏈接。

但首先您需要部署它。

點擊雲圖標與它一個向上的箭頭:

Apps Script Code Editor

你會問,如果你沒有這樣做,已經給項目命名。然後,你會得到一個彈出,看起來像這樣:

Deploy As Web App

點擊部署

你會得到另一個彈出。 。 。點擊'最新代碼'。您的應用將在瀏覽器中打開。

您提供的代碼在標有'Here is a Button'的窗口中放置一個按鈕。