将showModalDialog()的内容添加到剪贴板Google脚本 [英] Add content of showModalDialog() to the clipboard Google Script

本文介绍了将showModalDialog()的内容添加到剪贴板Google脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击按钮时,我已将格式化的数据添加到模态对话框"中

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

我也想在单击按钮时将showModalDialog()的内容自动添加到剪贴板中

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

模态是使用下面的代码生成的,temp是我要添加到剪贴板的输出

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');

编辑;好的,我想也许Modal Dialog可能就在现场,而正确的问题可能是如何将格式化后的字符串temp添加到剪贴板

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

谢谢

推荐答案

您可以在html中创建textarea,然后使用html中的按钮将其中的数据复制到剪贴板.

You can create a textarea in html and copy data in it to clipboard using a button inside 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');

要阅读:

  • 与剪贴板交互
  • HTML模板
  • To Read:

    • Interact with clipboard
    • HTML Template
    • 这篇关于将showModalDialog()的内容添加到剪贴板Google脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆