在打开的Google表格上加载边栏 [英] Load sidebar onOpen google Sheets
本文介绍了在打开的Google表格上加载边栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在页面打开时加载侧栏.我有重要的信息可供我随时查看.打开页面时如何加载侧栏?如果需要的话,我也可以做onEdit.
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);
}
还是这样?
function OnEdit() {
var html = HtmlService.createHtmlOutputFromFile('Changelog')
.setTitle('Changelog')
.setWidth(300);
SpreadsheetApp.getUi()
.showSidebar(html);
}
推荐答案
尝试一下:
function anOnOpen(){
SpreadsheetApp.getUi().createMenu('My Tools')
.addItem('Sidebar', 'loadSidebar')
.addToUi();
loadSidebar();
}
function loadSidebar(){
var ui=HtmlService.createHtmlOutputFromFile('simplesidebar');
SpreadsheetApp.getUi().showSidebar(ui);
}
您可以使用getElementById和innerHTML在html中添加所需的任何内容.我经常使用JQuery ready函数来调用和应用脚本,该脚本返回所需的html内容.或者,您可以使用HTML模板.就个人而言,我从不使用模板.
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.
这篇关于在打开的Google表格上加载边栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文