Nicolas Goaziou <m...@nicolasgoaziou.fr> writes:

Hello,

> The following patch implements radio tables and `orgtbl-to-...'
> functions using Org export engine. The implementation is probably not
> totally backward compatible, though.
  
funny, I just wrote `org-dp-create-table' (in
https://github.com/tj64/org-dp) a few hours ago, obviously it is not
competing with this rather complex framework of Org table creation, but
it does its job and might be useful for anybody just looking for a
simple way to create a table programmatically.

Usage is:

#+BEGIN_SRC emacs-lisp :results raw
(org-dp-create-table
 (list
   '("col1" "col2" "col3")
   'hline
   '("a" "b" "c")
   '(1 2 3)
   'hline
   '(x y z)))
#+END_SRC

#+results:
| col1 | col2 | col3 |
|------+------+------|
| a    | b    | c    |
| 1    | 2    | 3    |
|------+------+------|
| x    | y    | z    |


implementation is:

#+BEGIN_SRC emacs-lisp
(defun org-dp-create-table (row-lst)
  "Create table of type 'org'.
ROW-LST is an alist of lists with elements that are contents of a
single row's table cells, e.g.

 (list
   (list \"col1\" \"col2\" \"col3\")
   'hline
   (list 1 2 3)
   (list 'x 'y 'z))

for a table with 3 columns and 4 rows, including one horizontal
line."
  ;; table
  (org-dp-create 
   'table
   (mapconcat
    (lambda (--row-cells)
      (if (eq --row-cells 'hline)
          ;; rule rows
          (org-dp-create 'table-row nil nil nil :type 'rule)
        ;; standard rows
        (org-dp-create 'table-row
                       (mapconcat
                        (lambda (--cell-cont)
                          ;; cells
                          (org-dp-create 'table-cell
                                         (format "%s" --cell-cont)))
                        --row-cells "")
                       nil nil :type 'standard)))
    row-lst "")
   nil nil :type 'org))
#+END_SRC

-- 
cheers,
Thorsten


Reply via email to