Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

javascript - Add content of showModalDialog() to the clipboard Google Script

I have formatted data being added to a Modal Dialog when I click a button

I want to the content of the showModalDialog() to be automatically added to the clipboard when I click the button as well

The modal is being generated with the below code, and temp is the output I want added to the clipboard

//Output to Html
 var htmlOutput = HtmlService
              .createHtmlOutput(temp)
              .setSandboxMode(HtmlService.SandboxMode.IFRAME)
              .setWidth(600)
              .setHeight(500);
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Filter OptionList Maker');

Edit; Ok, I guess maybe the Modal Dialog might be beside-the-point and the proper question might be how to add the formatted string temp to the clipboard

Here is an example of what I mean by formatted string

filter {
  target: element;
  as: dropdown;
  padding: 5;
  summary: "Network Practice";
  default: show-all;
  multiple: true;

  option {
   label: "< 1 year";
   selector: element["NETWORK PRACTICE"="< 1 year"];
  }
  option {
   label: "1-3 years";
   selector: element["NETWORK PRACTICE"="1-3 years"];
  }
  option {
   label: "3-10 years";
   selector: element["NETWORK PRACTICE"="3-10 years"];
  }
  option {
   label: "> 10 years";
   selector: element["NETWORK PRACTICE"=">10 years"];
  }
 }

I have searched on how to do this but I have found no solution

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...