Add content of showModalDialog() to the clipboard Google Script

You can create a textarea in html and copy data in it to clipboard using a button inside html.

Snippet:

copy.html:

<textarea id="copy"><?=temp?></textarea>
<button>Copy</button>
<script type="text/javascript">
  let t = document.getElementById('copy');
  let copy = () => {
    t.select();
    document.execCommand('copy');
  };
  copy();//try copying without user click 
  let bt = document.querySelector('button');
  bt.addEventListener('click', copy);
</script>

code.gs

//Output to Html
var template = HtmlService.createTemplateFromFile('copy');
template.temp = temp;
var htmlOutput = template.evaluate();
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Filter OptionList Maker');

To Read:

Leave a Comment