3

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.

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')
}
livibetter
  • 18,532
  • 3
  • 38
  • 40
user3325770
  • 31
  • 1
  • 1
  • 3
  • You cannot copy to the clipboard programmatically in JS due to security reasons. You may select the content to copy and prompt the user to do 'CTRL+C' – MarcoL Apr 16 '15 at 21:47
  • What is the other application? – jmunsch Apr 16 '15 at 21:49
  • Excel - I am using Google sheets to download web data and transferring this data to excell for processing - excell is not as efficient as Google getting data from websites and Google spreadsheet size limitations prevent me from using it as it is very slow - but getting the data across is a bit cumbersome so I want to streamline the process – user3325770 Apr 17 '15 at 18:51

1 Answers1

0

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 question suggest this aproach:

There is not way around, you have to use flash. There is a JQuery plugin called jquery.copy that 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 ;)

Community
  • 1
  • 1
Thijs
  • 2,805
  • 4
  • 29
  • 51
  • After I download the j.query plugin how do I reference it in google sheets script? I'd like to activate the script from a cell (say A1) - what I'd love to do is by selecting cell A1 this would run a script that selects column A to V and places them on the clipboard. After that I would just paste the copied range into my excel sheet for processing. Would you be able to give an example - also do you have a link where I can download the j.query plugin? – user3325770 Apr 24 '15 at 21:18
  • Just add a link to the jQuery scripts using a `script`-tag. Load the plugin using the same way. I guess to get the values of multiple cells, you need to write a script to get those data and copy that to the clipboard. I'm not sure but I don't think you can read data from the clipboard. This would raise security issues. https://stackoverflow.com/questions/7060109/why-is-writing-to-the-clipboard-in-js-considered-a-security-hole – Thijs Apr 27 '15 at 07:08