Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
663 views
in Technique[技术] by (71.8m points)

emacs - Converting list of lists into org-table

I have a lisp data (list of lists)

(setf *table-data*
   '((1 "Team1"
        (("member 1" "data1")
         ("member 2" "data2")
         ("member 3" "data3")))
     (2 "Team2"
        (("member 1" "data1")
         ("member 2" "data2")
         ("member 3" "data3")))))

When I try to convert this list into org-table, using (princ *table-data*) I am getting the output,

| 1 | Team1 | ((member 1 data1) (member 2 data2) (member 3 data3)) |
| 2 | Team2 | ((member 1 data1) (member 2 data2) (member 3 data3)) |

org-table is considering only the outer most list elements.

But I would like to get the output as:

| 1 | Team1 | member 1 | data1 |
|   |       | member 2 | data2 |
|   |       | member 3 | data3 |
| 2 | Team2 | member 1 | data1 |
|   |       | member 2 | data2 |
|   |       | member 3 | data3 |

Is there any possibility to achieve this?

Also, I want to convert back this table into a list of lists instead of plain lists.

question from:https://stackoverflow.com/questions/65950060/converting-list-of-lists-into-org-table

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

[Partial answer only: this answer deals with the translation of a table from a lisp data structure as Org mode does it.]

The lisp representation of the table that you want to produce is as follows:

#+begin_src emacs-lisp
(setq x '((1 "Team1" "member 1" "data1")
          ("" ""     "member 2" "data2")
          ("" ""     "member 3" "data3")
          (2 "Team2" "member 1" "data1")
          ("" ""     "member 2" "data2")
          ("" ""     "member 3" "data3")))
x
#+end_src

#+RESULTS:
| 1 | Team1 | member 1 | data1 |
|   |       | member 2 | data2 |
|   |       | member 3 | data3 |
| 2 | Team2 | member 1 | data1 |
|   |       | member 2 | data2 |
|   |       | member 3 | data3 |

as you can see by evaluating the source block.

What remains to be done is to translate from your desired representation to this representation and vice-versa.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...