From: <tomas@tuxteam.de>
To: emacs-orgmode@gnu.org
Subject: Re: [Question] Getting cell value and use it in table formula
Date: Tue, 1 Oct 2024 17:04:10 +0200 [thread overview]
Message-ID: <ZvwPas2cGNS94aGM@tuxteam.de> (raw)
In-Reply-To: <87jzerriv0.fsf@city17.xyz>
[-- 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 --]
next prev parent reply other threads:[~2024-10-01 16:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-01 14:35 [Question] Getting cell value and use it in table formula jman
2024-10-01 15:04 ` tomas [this message]
2024-10-01 20:01 ` jman
2024-10-02 4:16 ` tomas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZvwPas2cGNS94aGM@tuxteam.de \
--to=tomas@tuxteam.de \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).