I've got a spreadsheet accessed regularly by a team of non-techies and it would speed up our workflow if I could have clickable buttons auto-generated on certain rows (depending on the row's contents) that launch Google Apps Scripts.
An elegant solution (HTML Service or UI Service) would be nice, but I don't mind using Drawings. The problem is, I don't know how to generate them programmatically.
Am I missing something really obvious, or maybe Google Sheets really just wants you to keep UI stuff in dialogs/sidebars?
No, you can't put a button into a cell of a Google Sheet. You can put an image of a button into a spreadsheet, with a script attached to it. As far as embedding something into a cell, all you can do is to put a hyperlink into a cell. The link can launch a stand alone Apps Script. And you can programmatically put a link into a cell. There are three other options, have a custom menu, dialog box or sidebar open automatically when the spreadsheet opens.
A hyperlink is a formula, and you can add a formula with code:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("B5");
cell.setFormula("=hyperlink("www.google.com", "search the web");
Google Documentation - Set Formula
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With