Esben Stien <b...@esben-stien.name> writes:

> I'm trying to figure out how to get the number of rows in an org-table,
> but I can't find this in the documentation. 
>
> Anyone have an idea?

As always, there might be some Org function for this, but otherwise here
is a starting point:

#+begin_src emacs-lisp
  (defun tj/count-tbl-rows (&optional tbl-as-lisp)
    "Return number of tbl rows for tbl at point."
    (interactive)
    (let ((rows (if tbl-as-lisp
                    (length tbl-as-lisp)
                  (length (org-table-to-lisp)))))
      (message "Table has %d Rows" rows)
      rows))
#+end_src

#+results:
: tj/count-tbl-rows

#+NAME: nice-tbl
| pretty | impressive | table |
| pretty | impressive | table |
| pretty | impressive | table |
| pretty | impressive | table |
| pretty | impressive | table |
| pretty | impressive | table |

#+header: :var data=nice-tbl
#+begin_src emacs-lisp 
(tj/count-tbl-rows data)
#+end_src

#+results:
: 6

-- 
cheers,
Thorsten


Reply via email to