Dear J Forum:
I'd like to transfer a rank-2 boxed array from J to an Excel worksheet.  The
boxes of the J array may contain numeric, character, and empty data, e.g.:
JArray =. 2 3 $ 0; 'word'; ] a:, 'abc'; _4; 3.14
Apparently 'jcmd' and the various 'get' functions do not allow for mixed
types of data, nor for empty boxes.  I've managed to create the following
VBA subroutine that transfers the array one cell at a time, but it is very
slow.  Moreover, if the Excel range is being overwritten, the aces will not
clear what's already in the cells.  Is there a better solution?
Sub GetJTable(Jvar As String, r As Integer, c As Integer)
'A J Table is a boxed array of rank 2
'Writes the array to the current worksheet beginning at cell r,c
Dim i, ridx, j, cidx, m, n As Integer
js.Do "TableDim =. 2 {.  (,& 1 1) $" & Jvar
js.Do "table =. TableDim $ ," & Jvar
m = jcmd("0{TableDim"): n = jcmd("1{TableDim")
js.Do "tblsel =. {&table"
ridx = r - 1
For i = 0 To m - 1
ridx = ridx + 1: cidx = c - 1
js.Do "rowsel =. { & (tblsel " & i & ")"
For j = 0 To n - 1
cidx = cidx + 1
js.Do "x =. > rowsel " & j
js.GetB "x", v
ActiveSheet.Cells(ridx, cidx).Value = v
Next j: Next i
End Sub
Would the solution be simpler if, except for column headings in the first
row, each column were exclusively numeric or character (with aces allowed)?
Thanks for helping.
Sincerely,
Leigh
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to