16

I am new to Google Script.

I have a Google Sheet with 5 columns, on each column I need a button (with text 1,2,3,4,5).

And on each button click I need to set text of button to corresponding cell and hide the clicked button.

Is it possible?

Kos
  • 4,890
  • 9
  • 38
  • 42
Prasad
  • 191
  • 1
  • 1
  • 8
  • The buttons would be acessed by logged in Spreadsheet Editors or by Anonymous? – Kriggs Feb 23 '15 at 10:50
  • By logged in Spreadsheet .. – Prasad Feb 23 '15 at 10:53
  • 1
    You can't make various buttons inside a cell, but you can make a dropdown selection with validation or a sideBar/dialog for the buttons (both theses methods require the user to be logged in). Button just hover the cells, I guess you could make many appear programatically, but I'm not sure how to. – Kriggs Feb 23 '15 at 11:10

3 Answers3

16

You can insert an image that looks like a button. Then attach a script to the image.

  • INSERT menu
  • Image

Insert Image

You can insert any image. The image can be edited in the spreadsheet

Edit Image

Image of a Button

Image of Button

Assign a function name to an image:

Assign Function

Alan Wells
  • 30,746
  • 15
  • 104
  • 152
  • thanks for your answer..is it possible to add buttons with Google scripts – Prasad Feb 24 '15 at 10:14
  • No. There is no way to add a button to the spreadsheet with a script. You can have a dialog box pop up, or put a sidebar on the side. And the sidebar is HTML, so that can have a button. – Alan Wells Feb 24 '15 at 13:45
6

Consider building an Add-on that has an actual button and not using the outdated method of linking an image to a script function.

In the script editor, under the Help menu >> Welcome Screen >> link to Google Sheets Add-on - will give you sample code to use.

Bryan P
  • 5,031
  • 3
  • 30
  • 44
1

It is possible to insert an image in a Google Spreadsheet using Google Apps Script. However, the image should have been hosted publicly over internet. At present, it is not possible to insert private images from Google Drive.

You can use following code to insert an image through script.

  function insertImageOnSpreadsheet() {
  var SPREADSHEET_URL = 'INSERT_SPREADSHEET_URL_HERE';
  // Name of the specific sheet in the spreadsheet.
  var SHEET_NAME = 'INSERT_SHEET_NAME_HERE';

  var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var sheet = ss.getSheetByName(SHEET_NAME);

  var response = UrlFetchApp.fetch(
      'https://developers.google.com/adwords/scripts/images/reports.png');
  var binaryData = response.getContent();

  // Insert the image in cell A1.
  var blob = Utilities.newBlob(binaryData, 'image/png', 'MyImageName');
  sheet.insertImage(blob, 1, 1);
}

Above example has been copied from this link. Check noogui's reply for details.

In case you need to insert image from Google Drive, please check this link for current updates.

Dushyant
  • 11
  • 1