使用Google Web App扩展Google Spreadsheets UI [英] Extend Google Spreadsheets UI with a Google Web App

查看:105
本文介绍了使用Google Web App扩展Google Spreadsheets UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Google Spreadsheets创建了一个脚本,该脚本只是添加了一个新的菜单项,如电子表格中的自定义菜单项。然后,我将这个脚本部署为一个Web App,我希望所有安装该应用程序的用户都能够看到新的菜单项。



据我所知,当您将脚本部署为Web应用程序时,onOpen函数会失去其意义。所以,在doGet中,我为onOpen事件创建自定义触发器,将myOnOpen处理程序附加到它并在myOnOpen中添加一个菜单项,但该项不显示。



这里是我的代码:

pre $ function doGet(){
var newSheet = SpreadsheetApp.create(new sheet);
var newId = newSheet.getId();
ScriptProperties.setProperty('newId',newId);

ScriptApp.newTrigger(myOnOpen)
.forSpreadsheet(newId)
.onOpen()
.create();
};

函数myOnOpen(){
var newId = ScriptProperties.getProperty('newId');
var sheet = SpreadsheetApp.openById(newId);

var entries = [{name:Show bingo,functionName:Bingo}];
sheet.addMenu(我的菜单,条目);
};

函数Bingo(){
Browser.msgBox(Bingo!);
};

因此,当安装应用程序的用户打开新工作表电子表格时,他看不到我的菜单。我在这里做错了什么?为什么菜单项不显示?在这一天结束时,我想创建一个Web应用程序,该应用程序通过附加菜单和对话框扩展Google Spreadsheets UI。



欢迎任何建议。当您将脚本部署为Web应用程序时,Web应用程序的用户只会看到您返回的内容,来自doGet功能。您可以使用 UiApp HtmlService 并返回此内容以在浏览器中呈现。您的新菜单项会附加到电子表格中,因此只能在用户转到电子表格本身时才能显示(激活onOpen触发器等)。

I created a script for Google Spreadsheets, this script just adds a new menu item as described here Custom Menu Items in a Spreadsheet. Then I deploy this script as a Web App and I want all users who install the app to be able to see the new menu item. And I'm stuck at this point.

As I understand, when you deploy a script as a Web App, onOpen functions looses it's meaning. So, inside doGet I create custom trigger for onOpen event, attach myOnOpen handler to it and inside myOnOpen I add a menu item, but the item doesn't show up.

Here's my code:

function doGet() {
    var newSheet = SpreadsheetApp.create("new sheet");
    var newId = newSheet.getId();
    ScriptProperties.setProperty('newId', newId); 

    ScriptApp.newTrigger("myOnOpen")
        .forSpreadsheet(newId)
        .onOpen()
        .create();
};

function myOnOpen() {
    var newId = ScriptProperties.getProperty('newId');
    var sheet = SpreadsheetApp.openById(newId);

    var entries = [ { name : "Show bingo", functionName : "Bingo" } ];
    sheet.addMenu("My Menu", entries);
};

function Bingo() {
    Browser.msgBox("Bingo!");
};

So, when a user who installed the app opens "new sheet" spreadsheet, he doesn't see the "My Menu". What am I doing wrong here? Why the menu item doesn't show up? At the end of the day I want to create a Web App which extends Google Spreadsheets UI with additional menus and dialogs.

Any advice is welcome. Thanks!

解决方案

When you deploy the script as a web app, users of the web app will only see content you "return" from the doGet function. You can create content using UiApp or HtmlService and return this content to be rendered in a browser. Your new menu items are attached to a spreadsheet, so they can only be displayed when the user goes to the spreadsheet itself (activating the onOpen trigger, etc).

这篇关于使用Google Web App扩展Google Spreadsheets UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆