0

From the lack of discussions on this, I'm not sure I've missed the point here but...

If I have users using and viewing a spreadsheet via custom menus, and I need to deploy this app as a webapp in order to manage protection settings and implement the APIs (Visualization Query etc), what does the architecture need to look like? From what I read here, menus won't be shown, so how do I get everything I need to work under 1 roof?

Extend Google Spreadsheets UI with a Google Web App

Community
  • 1
  • 1
Tim
  • 756
  • 1
  • 7
  • 12

2 Answers2

1

You can have a script that deploys a menu as well as work as a web app. You deploy the menu in your onOpen function of the spreadsheet. And you have a doGet function to write your web app code (typically the UI). The web app is accessed through the service URL and not the spreadsheet.

EDIT: To display the web app UI within the spreadsheet, you can generate the same UI in a different function and call that function from your custom menu. You might want to change the dimensions of your UI to suit that of your web app

function onOpen(){
   var menu = [{name: 'Show UI', functionName: 'showUI'}];
   ss.addMenu('Show Custom UI', menu);
}

/* If you are using HtmlService to build a web app UI */
function showUI() {
  var ss = SpreadsheetApp.getActiveSpreadsheet(); 
  var html = HtmlService.createHtmlOutputFromFile('index'); // index.html houses your web app's UI code.
  ss.show(html);
}

/* If you are using UIApp to build a web app UI */
function showUI() {
  var ss = SpreadsheetApp.getActiveSpreadsheet(); 
  var app = UiApp.createApplication();

  /* Build UI here */

  ss.show(app);
}
Srik
  • 7,907
  • 2
  • 20
  • 29
  • Thanks for your suggestion Srik, and that was my first assumption. However I'm not bad at finding stuff with Google, but I failed to find any examples of how to open a URL from a custom menu. All I found were people saying that (for security reasons) it was impossible to do anything except use the menu to show the URL in a form or pop up for the user to follow manually. Is there another less mickey-mouse approach? – Tim Sep 01 '13 at 10:30
  • I think you should reword your question to state (explicitly) that you want to open a web app from a custom menu. Yes, you're right that you can't open a browser window from a custom menu. But you can have a large popup and put in your doGet code to show the UI but not more :( – Srik Sep 02 '13 at 03:42
  • Well maybe I don't need to launch a new browser window, do you know if the custom menu could load the webapp UI in the active spreadsheet window? – Tim Sep 02 '13 at 05:26
  • Sorry, I'm still not sure - you have 2 solutions there, but the UiApp one appears to be building the UiApp from scratch which will not allow it to access the API since it is not published as a WebApp. Have I understood this correctly? – Tim Sep 02 '13 at 07:06
  • Can you include more details in your question. The UI, a spreadsheet menu item and a web app are all independent of each other although they are typically used together. Include details of what exactly you're trying to achieve and some code. – Srik Sep 02 '13 at 08:14
  • I'm not sure how much more I can say about it than I did in my opening post. Components are: 1. Spreadsheet visible to users 2. Menu driven code to launch UiApp 3. UiApp making API calls - how do we fit these together into a single interface for the users, specifically, how do we use custom menus to launch code which can implement the API? – Tim Sep 02 '13 at 08:46
1

After piecing together a lot of different resources by diligent hunting about on Google, I've discovered you can actually launch a WebApp from a SpreadsheetApp custom menu, and it's not that hard at all.

All you do it deploy the WebApp as normal, and use the script's 'Project properties' File menu option to retrieve the 'Project key'. This you simply copy/paste into your client SpreadsheetApp's 'Find a library' box as described here

Once the library is installed, you can add a custom menu to invoke the Library's doGet() & return the app object to show in your client SpreadsheetApp:

function Shoo() {

  var app = FooManShoo.doGet();
  SpreadsheetApp.getActiveSpreadsheet().show(app);

}

function onOpen() {

  var entries = [{name : 'man', functionName : 'Shoo'}];
  SpreadsheetApp.getActiveSpreadsheet().addMenu('foo', entries);                   

}

Hope this helps someone else! :)

Tim
  • 756
  • 1
  • 7
  • 12