Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Buttons To Google Sheets and Set value to Cells on clicking

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?

like image 646
Prasad Avatar asked Feb 23 '15 07:02

Prasad


3 Answers

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

like image 128
Alan Wells Avatar answered Nov 14 '22 03:11

Alan Wells


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.

like image 6
Bryan P Avatar answered Nov 14 '22 02:11

Bryan P


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.

like image 1
Dushyant Avatar answered Nov 14 '22 01:11

Dushyant