0
votes

I know with google scripts I can do both of the following:

  1. Create a new spreadsheet
  2. Create a custom menu in an existing spreadsheet

What I don't know if I can do or not is both at the same time. Here is the use case:

I have a form that will create a new spreadsheet upon submission. I need each of those programmatically created spreadsheets to also have a custom menu object created as well upon the creation of the spreadsheet. I can't find any documentation on this.

1
Perhaps instead of creating a new spreadsheet, you could create a copy of existing template spreadsheet? If not, perhaps this could help. I am not sure though. - Konstant

1 Answers

0
votes

Not sure this is what you are looking for but to programmatically create menu items, you would use code that looks something like this:

where data_range is a range, walkrow and walkcol are effectively counters, etc.

 // Adding a menu through UI 
 var ui = SpreadsheetApp.getUi();  
 var custommenu = ui.createMenu('My Shortcut Menu') 

 var menuitem = data_range.getCell(walkrow, walkcol).getValue();
 var menufunction = data_range.getCell(walkrow, 2).getValue();

 for ( ; walkrow <= rowcount;  walkrow++ ) {    
   menuitem = data_range.getCell(walkrow, walkcol).getValue();
   menufunction = data_range.getCell(walkrow, 2).getValue();   
      custommenu.addItem(menuitem, menufunction);
      custommenu.addSeparator();
      Logger.log("menu item name is " + menuitem + " and function name is " +menufunction);
 }

 Logger.log("*******"); 
 custommenu.addToUi();