问题
I am trying to load the sidebar when the page opens. I have important information that i was readily available for them to see. How can i load the sidebar when page is opened? I also could do onEdit if need be.
function onOpen(){
var ui = SpreadsheetApp.getUi()
.createAddonMenu()
.addItem('Show sidebar', 'showSidebar')
.addItem('Show dialog', 'showDialog')
.addSeparator()
.addToUi();
// Display sidebar if auto-sidebar is enabled
showSidebar();
SpreadsheetApp.getUi().createMenu('Information')
.addItem('Help', 'showPicker')
.addToUi();
SpreadsheetApp.getUi().createMenu('Changelog')
.addItem('Changelog', 'changeLog')
.addItem('Show sidebar', 'showSidebar')
.addToUi();
////Get user name and
var name = SpreadsheetApp.getActive().getSheetByName('Discovery Sheet');
var email = Session.getActiveUser().getEmail();
Logger.log(email);
name.getRange('a38').setValue(email);
}
Or like this one?
function OnEdit() {
var html = HtmlService.createHtmlOutputFromFile('Changelog')
.setTitle('Changelog')
.setWidth(300);
SpreadsheetApp.getUi()
.showSidebar(html);
}
回答1:
Try this:
function anOnOpen(){
SpreadsheetApp.getUi().createMenu('My Tools')
.addItem('Sidebar', 'loadSidebar')
.addToUi();
loadSidebar();
}
function loadSidebar(){
var ui=HtmlService.createHtmlOutputFromFile('simplesidebar');
SpreadsheetApp.getUi().showSidebar(ui);
}
You can add anything you want in the html with getElementById and innerHTML. I often use the JQuery ready function to call and apps script which returns the desired html contents. Or you can use an HTML Template. Personally, I never use templates.
来源:https://stackoverflow.com/questions/49308282/load-sidebar-onopen-google-sheets