javascript 在 Google 表格中复制到剪贴板功能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29686324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy to clipboard function in Google sheets
提问by user3325770
I want to write a simple Google function to copy columns A
to V
of a Google Sheets to the clipboard to use in another application.
我想编写一个简单的谷歌功能列复制A
到V
谷歌的表到剪贴板使用其他应用程序。
I have the following code so far, but I need to get the contents to the clipboard, what command would I use?
到目前为止,我有以下代码,但我需要将内容保存到剪贴板,我将使用什么命令?
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Custom Menu')
.addItem('Copy Col A to V', 'copycolsAtoV')
.addToUi();
}
function copycolsAtoV() {
var ss = SpreadsheetApp.getActiveSheet();
ss.getRange('A:V')
}
回答by Thijs
Most websites handle a copy to the clipboard using a bit of Flash since this can't be done using JavaScript. An answer on a similar questionsuggest this aproach:
大多数网站使用一点 Flash 处理剪贴板的副本,因为这无法使用 JavaScript 完成。对类似问题的回答提出了这种方法:
There is not way around, you have to use flash. There is a JQuery plugin called jquery.copythat provided cross browser copy and paste by using a flash (swf) file. This is similar to how the syntax highlighter on my blog works.
Once you reference the jquery.copy.js file all you need to do to push data into the clipboard is run the following:
$.copy("some text to copy");
Nice and easy ;)
没有办法,你必须使用闪光灯。有一个名为 jquery.copy的JQuery 插件,它通过使用 flash (swf) 文件提供跨浏览器复制和粘贴。这类似于我博客上的语法高亮器的工作方式。
引用 jquery.copy.js 文件后,将数据推送到剪贴板所需要做的就是运行以下命令:
$.copy("some text to copy");
好,易于 ;)