Defining Constant Values from Remote Org-Table Cell for Use in
Create Named Table, e.g.
| S | M | T | W | H | F | S |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
Method 1 - Dynamically Define
SRC Block Results
In this example, the programming language used is elisp but
org-mode can be configured to run source blocks in over 30 programming languages so pick another language you like, if you don't don't want to use elisp.
The only requirements for
SRC block are:
#+RESULTS: must provide valid
#+CONSTANTS: declaration, e.g.
:results drawer or
:results raw headers to
SRC block so that
org-mode can interpret the
#+RESULTS: as org syntax.
- The constant value must be fetched from cell in named table, e.g.
In this specific example, I used Indexable Variable Values syntax, i.e.
constant-value=other-table-name[2,4], to fetch constant value from a specific cell in table.
#+BEGIN_SRC elisp :var constant-name="HOURS" :var constant-value=other-table-name[2,4] :results drawer
(format "#+CONSTANTS: %s=%s" constant-name constant-value)
| Value of $HOURS from CONSTANTS generated by SRC Block | 4 |
Method 2 - Use
org-table Advanced features syntax to create local table constant with value fetched using
| # | Value of $hours fetched from other-table-name | 4 |
| $ | | hours=4 |
#+TBLFM: @1$3=$hours::@2$3='(format "hours=%s" remote(other-table-name, @>$5))
Thank you for asking your question!
The code in this answer was validated using the following:
emacs version: GNU Emacs 27.1
org-mode version: 9.3.7