Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org mode spreadsheet formula for the number of lines in a cell

I am looking at a org-mode spreadsheet formula to get the number of non-empty lines in a cell. Example :

| col1 | col2 |
|------+------|
| a    |  3   |
| b    |      |
| c    |      |
|      |      |
|------+------|
| a    |  1   |
|      |      |
|------+------|
| a    |  2   |
| b    |      |
|      |      |
|------+------|

I have "col1" as input, and would like to fill "col2" automatically (the values can be anything, not just a b c).

like image 298
nha Avatar asked Dec 28 '25 18:12

nha


1 Answers

Note that what you call "cell" is actually a group of cells delimited by horizontal separators (hlines).

The following example uses calc's vlen function to get the size of the vector of cells on column 1, and rows between the previous (@-I) and next (@+I) hlines.

| col1 | col2 |
|------+------|
| a    | 3    |
| b    |      |
| c    |      |
|      |      |
|------+------|
#+TBLFM: @2$2=vlen(@-I$1..@+I$1)

You have to apply this same formula for all row groups.

like image 154
Juancho Avatar answered Dec 31 '25 19:12

Juancho