Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Org mode spreadsheet programmatic remote references

I keep my budget in org-mode and have been pleased with how simple it is. The simplicity fails, however, as I am performing formulas on many cells; for instance, my year summary table that performs the same grab-and-calculate formulas for each month. I end up with a massive line in my +TBLFM. This would be dramatically shorter if I could programmatically pass arguments to the formula. I'm looking for something like this, but working:

| SEPT   |
| #ERROR |
#+TBLFM: @2$1=remote(@1,$tf)

Elsewhere I have a table named SEPT and it has field named "tf". This function works if I replace "@1" with "SEPT" but this would cause me to need a new entry in the formula for every column.

Is there a way to get this working, where the table itself can specify what remote table to call (such as the SEPT in my example)?

like image 928
WorldsEndless Avatar asked Dec 02 '12 21:12

WorldsEndless


2 Answers

Yes, you can't do this with built-in remote and you need to use org-table-get-remote-range. Hopefully this better suits your needs than the answer given by artscan (I used his/her example):

| testname1 | testname2 |
|-----------+-----------|
|         1 |         2 |
#+TBLFM: @2='(org-table-get-remote-range @<$0 (string ?@ ?1 ?$ ?1))

#+TBLNAME: testname1
|    1 |

#+TBLNAME: testname2
|    2 |

Note the (string ?@ ?1 ?$ ?1): this is necessary because before evaluating table formulae, all substitutions will be done first. If you use "@1$1" directly, it would have triggered the substitution mechanism and be substituted by the contents of the first cell in this table.

like image 175
kccqzy Avatar answered Nov 06 '22 07:11

kccqzy


There is some ugly hack for same effect without using remote:

1) it needs named variable for remote address

(setq eab/test-remote "@1$1")

2) it uses elisp expression (from org-table.el) instead remote(tablename,@1$1)

(defun eab/test-remote (x)
  `(car (read
     (org-table-make-reference
      (org-table-get-remote-range ,x eab/test-remote)
      't 't nil))))

3) worked example

| testname1 | testname2 |
|-----------+-----------|
|           |           |
#+TBLFM: @2='(eval (eab/test-remote @1))

#+TBLNAME: testname1
|    1 |

#+TBLNAME: testname2
|    2 |

4) result

| testname1 | testname2 |
|-----------+-----------|
|         1 |         2 |
like image 29
artscan Avatar answered Nov 06 '22 06:11

artscan