Guides/Clipboard

From J Wiki
Jump to navigation Jump to search

Access to the OS clipboard can be very useful when working with other programs.


General Usage Scenario

You want to copy data from excel or the web browser into J environment. There are a couple of sophisticated ways to move data, but sometimes you feel its too complicated to do a simple job. In that case,

1. You select the area you want to copy from excel or browser and copy it to clipboard, for exmaple by clicking ctrl-c in windows. 1. Read it into the J environment as a string 1. Transform it into the original tabular format using J boxes (usually the field seperator is TAB and row separator LF) 1. Convert the data format appropriately

The following example is ran on J6:

   NB. Suppose you have selected the section you want to copy from an excel sheet and ctrl-c'ed
   NB. Read in the clipboard
   t=.wdclipread ''
   load 'format'
   NB. Transform it into the tabular form
   t=.clipunfmt t
   NB. Then you do conversion and etc on the data
   NB. After all the manipulation, you may want to write back to excel
   t=.clipfmt t
   wdclipwrite t
   NB. Then you go to excel and paste the clipboard by ctrl-v

J Version Specific Method

J6 and under

  • Read: wdclipread ''
  • Write: wdclipwrite 'string to paste'

J7 jgtk

  • Read: clipread ''
  • Write: clipwrite 'string to paste'

Since J7, the format script's location is changed and you have to : load '~addons/general/misc/format.ijs'

JHS

On windows, you may use Scripts/WindowsClipboard.

On the other platforms, ...

J8 jqt

  • Read: wd 'clippaste'
  • Write: wd 'clipcopy *','string to paste'

Contributed by June Kim