* [Question] Getting cell value and use it in table formula
@ 2024-10-01 14:35 jman
2024-10-01 15:04 ` tomas
0 siblings, 1 reply; 4+ messages in thread
From: jman @ 2024-10-01 14:35 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
Hello there,
Let's look at the following table:
----------s---------s----------
| EUR | USD | Exchange rate |
|-----+--------+---------------|
| 10 | 8.97 | 0.897 |
| 15 | 13.455 | |
#+TBLFM: $2='(* (string-to-number $1) (string-to-number (org-table-get 2 3)))
----------e---------e----------
I've tried a number of things but this is the only incantation is able to retrieve the value from
the cell "@2$3" and use it into the table formula.
Is there a cleaner way to retrieve a cell value and use it into a table formula that is a lisp
expression?
Any suggestion? Thanks.
Best,
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Question] Getting cell value and use it in table formula
2024-10-01 14:35 [Question] Getting cell value and use it in table formula jman
@ 2024-10-01 15:04 ` tomas
2024-10-01 20:01 ` jman
0 siblings, 1 reply; 4+ messages in thread
From: tomas @ 2024-10-01 15:04 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 2581 bytes --]
On Tue, Oct 01, 2024 at 04:35:47PM +0200, jman wrote:
>
> Hello there,
>
> Let's look at the following table:
>
> ----------s---------s----------
> | EUR | USD | Exchange rate |
> |-----+--------+---------------|
> | 10 | 8.97 | 0.897 |
> | 15 | 13.455 | |
> #+TBLFM: $2='(* (string-to-number $1) (string-to-number (org-table-get 2 3)))
> ----------e---------e----------
>
> I've tried a number of things but this is the only incantation is able to
> retrieve the value from the cell "@2$3" and use it into the table formula.
>
> Is there a cleaner way to retrieve a cell value and use it into a table
> formula that is a lisp expression?
I think it's in the manual (this is Org v9.7):
| 3.5.3 Emacs Lisp forms as formulas
| ----------------------------------
|
| [...]
|
| By default, references are interpolated as literal Lisp strings: the
| field content is replaced in the Lisp form stripped of leading and
| trailing white space and surrounded in double-quotes. For example:
|
| '(concat $1 $2)
|
| concatenates the content of columns 1 and column 2.
|
| When the ‘N’ flag is used, all referenced elements are parsed as
| numbers and interpolated as Lisp numbers, without quotes. Fields that
| cannot be parsed as numbers are interpolated as zeros. For example:
|
| '(+ $1 $2);N
|
| adds columns 1 and 2, equivalent to Calc’s ‘$1+$2’. Ranges are inserted
| as space-separated fields, so they can be embedded in list or vector
| syntax. For example:
|
| '(apply '+ '($1..$4));N
|
| computes the sum of columns 1 to 4, like Calc’s ‘vsum($1..$4)’.
|
| When the ‘L’ flag is used, all fields are interpolated literally: the
| cell content is replaced in the Lisp form stripped of leading and
| trailing white space and without quotes. If a reference is intended to
| be interpreted as a string by the Lisp form, the reference operator
| itself should be enclosed in double-quotes, like ‘"$3"’. The ‘L’ flag
| is useful when strings and numbers are used in the same Lisp form. For
| example:
|
| '(substring "$1" $2 $3);L
|
| extracts the part of the string in column 1 between the character
| positions specified in the integers in column 2 and 3 and it is easier
| to read than the equivalent:
|
| '(substring $1 (string-to-number $2) (string-to-number $3))
> Any suggestion? Thanks.
If everything else fails, read the manual ;-)
Cheers
--
t
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Question] Getting cell value and use it in table formula
2024-10-01 15:04 ` tomas
@ 2024-10-01 20:01 ` jman
2024-10-02 4:16 ` tomas
0 siblings, 1 reply; 4+ messages in thread
From: jman @ 2024-10-01 20:01 UTC (permalink / raw)
To: tomas; +Cc: emacs-orgmode
<tomas@tuxteam.de> writes:
> I think it's in the manual (this is Org v9.7):
>
> | 3.5.3 Emacs Lisp forms as formulas
> | ----------------------------------
For some reason, I think I got confused by the table formula modifiers
(E, N, L) and various type casting. What I wanted to achieve was simply:
----------s---------s----------
| EUR | USD | Exchange rate |
|-----+--------+---------------|
| 10 | 8.97 | 0.897 |
| 15 | 13.455 | |
#+TBLFM: $2='(* $1 @2$3);N
----------e---------e----------
Best,
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-02 4:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-01 14:35 [Question] Getting cell value and use it in table formula jman
2024-10-01 15:04 ` tomas
2024-10-01 20:01 ` jman
2024-10-02 4:16 ` tomas
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).