我正在尝试在电子表格中创建菜单而不打开它。我之前在onOpen()函数中完成了它,但现在我正在尝试在正常函数中执行它。使用此脚本,我可以创建一个文件,但不会在文件中创建我的“操作”菜单。
function Frank_PersistentVariable(){
//create file ID
var ss = SpreadsheetApp.create("TEST").getId();
//clean cache of file IDs
CacheService.getPrivateCache().remove('cachedObject');
//load file ID to cache
CacheService.getPrivateCache().put('cachedObject', ss);
}
function Frank_Menu(){
//create menu
var menu = [
{name: "action1", functionName: "MyFunction1"},
{name: "action2", functionName: "MyFunction2"},
{name: "action3", functionName: "MyFunction3"},
];
//call file ID from cache
var cachedObject = CacheService.getPrivateCache().get('cachedObject');
//call file using ID
var ss = SpreadsheetApp.openById(cachedObject);
//display menu in file
ss.addMenu("actions", menu);
}
答案 0 :(得分:1)
首先,仅在运行函数Frank_Menu
时才会创建菜单。你什么时候运行这个功能?打开电子表格后是否手动运行?