2014-09-29 113 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'的窗口中放置一个按钮。