Load sidebar onOpen google Sheets

别说谁变了你拦得住时间么 提交于 2020-06-29 13:36:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!