emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Question] Getting cell value and use it in table formula


From: tomas
Subject: Re: [Question] Getting cell value and use it in table formula
Date: Tue, 1 Oct 2024 17:04:10 +0200

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: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]