问题
I am brand new to Google Script and I am trying to create a Google Sheet to manage the creation of Quotes....I have created a form that will capture the Quote details and I want the user to be able to click on a Menu item at the top of the Sheet to "Create New Quote" which will open the Form.
What command can I use in place of the following when creating the Menu Item so that is will Open the Form....do I need to refer to the Form ID anywhere ?
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Quote Generator Menu')
.addItem('Create New Quote', 'menuItem1')
.addItem('Update Lists', 'updateLists')
.addSeparator()
.addSubMenu(ui.createMenu('Reporting')
.addItem('Dashboard', 'menuItem2'))
.addToUi();
}
function menuItem1() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.alert('You clicked Create New Quote');
}
function menuItem2() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.alert('You clicked Dashboard');
}
回答1:
One quick and dirty way. Upon menu click:
- Create a UI app.
- Create a hyperlink to the published form, instructing user to click link to add a new quote.
- Add link to UI app.
- Display UI app.
Example:
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Quote Generator Menu')
.addItem('Create New Quote', 'showUrl')
.addToUi();
}
// http://stackoverflow.com/questions/26815296
function showUrl(){
var FORM_URL = "ENTER_FORM_URL_HERE";
var app = UiApp.createApplication().setHeight(50).setWidth(200);
app.setTitle("Submit New Quote");
var link = app.createAnchor('Click to here to submit a new quote', FORM_URL);
app.add(link);
var doc = SpreadsheetApp.getActive();
doc.show(app);
}
Screenshot of UI prompt that pops up after clicking the menu:
来源:https://stackoverflow.com/questions/26815296/how-do-you-open-a-google-form-from-a-custom-menu-item