3

I have an org document with two different-sized tables table1 and table2.

#+TBLNAME: table1
|   |   |   |   |   |   |   |
|---+---+---+---+---+---+---|
|   |   | x | x | x | x | x |
|   |   | x | x | x | x | x |
|   |   | x | x | x | x | x |
|   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |
#+TBLFM: @2$3..@4$7=x

#+TBLNAME: table2
|   |   |   |   |   |   |   |   |   |   |
|---+---+---+---+---+---+---+---+---+---|
|   |   |   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |   |   |
|   |   |   |   | y | y | y | y | y |   |
|   |   |   |   | y | y | y | y | y |   |
|   |   |   |   | y | y | y | y | y |   |
|   |   |   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |   |   |
#+TBLFM: @6$5..@8$9=y

The region in table1 marked with x's and the region in table2 marked with y's are both arrays with three rows and four columns. I want to import the information in the indicated region of table2 into the indicated region of table1.

Reading through the org documentation it appears that something like

#+TBLFM: @2$3..@4$7='(identity remote(table2, <STUFF>))

might work, but I can't figure out what <STUFF> should be. Any ideas?

  • Technically, <STUFF> should be the range, i.e. @6$5..@8$9, but I'm afraid that importing rectangle won't work. At least I remember having problems specifying something more complex than a single value for all cell. But suppose you were to use Calc (rather than Lisp), the way I'd approach this is by trying remote(table2, @6$5..@8$9)_(@#, $#) i.e. Calc way of indexing a matrix. – wvxvw Sep 22 '15 at 23:48
  • So are you saying this is possible using calc? I'm having trouble seeing how. – Brian Fitzpatrick Sep 23 '15 at 0:43
4

Here you go. The key was to recombine the rows back (for some reason when Org copies a rectangle area it flattens it).

#+TBLNAME: table1
|   |   |   |   |   |   |   |
|---+---+---+---+---+---+---|
|   |   |   |   |   |   |   |
|   |   | a | a | a | a | a |
|   |   | b | b | b | b | b |
|   |   | c | c | c | c | c |
|   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |
#+TBLFM: @3$3..@5$7=arrange(remote(table2, @6$5..@8$9), 5)_(@# - 2)_($# - 2)

#+TBLNAME: table2
|   |   |   |   |   |   |   |   |   |   |
|---+---+---+---+---+---+---+---+---+---|
|   |   |   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |   |   |
|   |   |   |   | a | a | a | a | a |   |
|   |   |   |   | b | b | b | b | b |   |
|   |   |   |   | c | c | c | c | c |   |
|   |   |   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |   |   |
#+TBLFM: @6$5..@6$9=a::@7$5..@7$9=b::@8$5..@8$9=c
3

To supplement wvxvw's answer, you can also do this interactively by copying with org-table-copy-region and pasting with org-paste-rectangle. I bind those two like this:

;; table copy paste (C-c M-w is bound to `org-copy' by default)
(org-defkey org-mode-map (kbd "C-c M-w") 'org-table-copy-region)
(org-defkey org-mode-map (kbd "C-c M-y") 'org-table-paste-rectangle)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.