11

I'm wondering whether it's possible to display the result of calculations performed on table data, outside of a table.

For example, suppose I have a table of with a list of names. Is it possible to have plain text that says something like "This below list contains [ ] names." and have [ ] contain the result of counting the table?

Malabarba
  • 22,878
  • 6
  • 78
  • 163
Chris
  • 699
  • 3
  • 13

1 Answers1

10

You can use an inline babel code block and the lisp function org-table-get-remote-range for getting access to table ranges like in the following example (the number 3 after the source block is what it produced when C-c C-c is executed on it)

  #+TBLNAME: table1
  | Name    | Points |
  |---------+--------|
  | Andreas |      5 |
  | Barbara |      8 |
  | Carl    |      7 |
  |---------+--------|
  | Total   |     20 |
  #+TBLFM: @5$2=vsum(@I..@II)

  Now I insert in the text the number of names in the above table: 
  src_emacs-lisp[:results raw]{(length (org-table-get-remote-range "table1" "@I$1..@II$1" ))} 3
dfeich
  • 1,844
  • 16
  • 16
  • In my Emacs settings, [:results raw] does not show the results, [:results value raw] succeeded. However every time I C-c C-c, or C-c C-v C-b, redundant same result is repeated. I don't know why and I don't have a solution for the redundant results. – RUserPassingBy Jun 26 '15 at 03:52
  • 1
    `value` should be the default setting, but your making it explicit is certainly more correct. In regard to the repetition of the insertion of the results with every subsequent execution of `C-c C-c`, this is an inherent problem, since the result is not wrapped in any kind of markers which would enable Org to determine the limits. One would have to cook up some solution using in-text markers that are invisible on export. The current situation is not optimal, I agree. – dfeich Jun 27 '15 at 07:40
  • Thank you for your precise explanation, I understand. I will keep in mind the inherent problem. Your solution in-line block is great! – RUserPassingBy Jun 27 '15 at 08:12