Is there a way to use radio buttons in a Google Sh

2019-08-18 05:53发布

问题:

My goal, simply put, is to highlight a cell range on one google sheet (the 'source') and move it to another, different google sheet document (the 'target'). The Target has multiple sheets(tabs?) and new ones are added often.

IMPORTANT: To be clear, I am NOT copying from one sheet to another sheet, in the same document. I am copying from one google sheet document, to a complexity different google sheet document.

Currently, I have code that allows users to:

  1. Highlight a cell range in the SOURCE google sheet.
  2. Select the custom menu option.
  3. Upon selecting the custom menu option, the data in the highlighted cell range is copied to the TARGET google sheet.

Currently, the the "Target" is hardcoded.

What I want to do is to build a Radio Button list. One Radio Button for every Sheet that exists in the TARGET google sheet. Allow the user to choose one, then move the data to that specific Sheet, when they press the "OK" button.

I've searched for a while, but I'm unable to find anything about even putting radio buttons in a google sheets dialog, let alone build the radio button list based on sheets that exist in another google sheet document.

回答1:

Here's a simple example of a radio dialog:

function radiosOnADialog() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getActiveSheet();
  var html='<html><head><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"><script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script></head>';
  for(var i=0;i<10;i++) {
    html+=Utilities.formatString('<br /><input type="radio" name="rgroup" id="%s" value="%s" onChange="getSelected();" />%s','id'+ Number(i+1),'radio' + Number(i+1),' radio' + Number(i+1));
  }
  html+='<body><br /><input type="button" value="close" onClick="google.script.host.close()" /><div id="msgdiv"></div>';
  html+='<script>function getSelected(){ var selected=document.querySelector(\'input[name="rgroup"]:checked\').value;document.getElementById("msgdiv").innerHTML="<br />You selected " + selected  + ".<br />";}</script></body></html>'; 
  var ui=HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModelessDialog(ui, 'A Radio Dialog');
}
  • Radio Buttons

The Dialog:



回答2:

Closing this question, as I now know HTML needs to be used.