1

I want to export (not sure if that's the right word) a single column of an org-table as text, with the elements separated by commas. Eg if the table is

| x  | y  |
|----+----|
|  0 |  1 |
|  2 |  3 |
|  4 |  5 |
|  6 |  7 |
|  8 |  9 |

I want to get the result 0,2,4,6,8.

In this case I want the first column, but I'd like a solution that allows me to export any single column.

2

You can make a function to get the desired column and create a string with all the values. For example:

#+name: tbl
| x  | y  |
|----+----|
|  0 |  1 |
|  2 |  3 |
|  4 |  5 |
|  6 |  7 |
|  8 |  9 |

#+begin_src elisp :var x=tbl col=0
(mapconcat (lambda (r) (number-to-string (nth col r))) x ",")
#+end_src

#+RESULTS:
: 0,2,4,6,8

nth selects the desired column for a row. In order to concatenate all into a string, the number must be converted to a string with number-to-string.

Finally, the above operation is passed to mapconcat, which will form the string with the desired delimiter.

If you don't want the actual table in the exported output, wrap it inside a COMMENT block.

  • Neat! So x is bound to the table, as a sequence, but what kind exactly (list of list ?) – JeanPierre Feb 11 '17 at 8:30
  • Yes. List of (list or hline) – Juancho Feb 12 '17 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.