I want to insert a new row at line 2 in a table (preferably using TBLFM), and I want it to be prefilled with the current date (col 1) and time (col 2).

How do I insert a new row (something like #+TBLFM: @2..@-1=@#-1?) ?

Here is my current table:

| date             | start |   end | lunch |    total | expected |    + time |
|------------------+-------+-------+-------+----------+----------+-----------|
| [2016-08-02 Tue] | 08:58 | 17:00 |  0:15 | 07:47:00 | 07:30:00 |  00:17:00 |
| [2016-08-01 Mon] | 08:37 | 16:12 |  0:15 | 07:20:00 | 07:30:00 | -00:10:00 |
|------------------+-------+-------+-------+----------+----------+-----------|
|                  |       |       |       |          |          |  00:07:00 |
#+TBLFM: @2$5..@-1$5=$3-$2-$4;T::@2$7..@-1$7=$5-$6;T::@>$7=vsum(@2$7..@-1$7);T

The following line inserts a new row, but with the content of cell 1 "#ERROR".

#+TBLFM: @2$1='(let ((org-table-fix-formulas-confirm 0)) (org-table-insert-row))

The part with setting org-table-fix-formulas-confirm to 0 is so that it doesn't update all the indices in the formulae.

So using two formulae, the following works:

| date             | start |   end |
|------------------+-------+-------|
| [2016-08-01 Mon] | 08:00 | 16:00 |
|------------------+-------+-------|
#+TBLFM: @2$1='(let ((org-table-fix-formulas-confirm 0)) (org-table-insert-row))
#+TBLFM: @2$1='(format-time-string "[%Y-%m-%d %a]")::@2$2='(format-time-string "%H:%M")
#+TBLFM: @2$3='(format-time-string "%H:%M")

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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