Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you programmatically generate buttons in Google Sheets cells?

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?

like image 663
Legume Duprix Avatar asked Oct 11 '25 14:10

Legume Duprix


1 Answers

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

like image 52
Alan Wells Avatar answered Oct 15 '25 09:10

Alan Wells