简体   繁体   English

如何从 src 块中的多个表访问数据

[英]How to access data from many tables in src blocks

In my org document, I have several tables named (with #+name: ) t1, t2, etc. I want to pass all of the tables to some lisp code.在我的组织文档中,我有几个表(用#+name: )命名为 t1、t2 等。我想将所有表传递给一些 lisp 代码。 This is what I have so far:这是我到目前为止:

#+name: process-tables
#+header: :var t1=t1 t2=t2 t3=t3 t4=t4 t5=t5 t6=t6 t7=t7 t8=t8 t9=t9 t10=t10 t11=t11 t12=t12 t13=t13 t14=t14
#+BEGIN_SRC emacs-lisp
    (process (append t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14))
#+END_SRC

This seems very clumsy.这看起来非常笨拙。 Is there a better way?有没有更好的办法? I do not want to merge the tables in the org document.我不想合并组织文档中的表格。

You can try the org-table-map-tables and org-table-to-lisp functions to create a list of all tables in the buffer.您可以尝试使用org-table-map-tablesorg-table-to-lisp函数来创建缓冲区中所有表的列表。 This avoids having to invoke table names individually.这避免了必须单独调用表名。

(defun org-tables-to-list ()
  (let (tbls)
    (org-table-map-tables
     (lambda ()
       (push (org-table-to-lisp) tbls))
     t)
    (apply #'append (nreverse tbls))))

For example:例如:

#+name: t1
| 0 | 1 |

#+name: t2
| 2 | 3 |

#+name: process-tables
#+BEGIN_SRC emacs-lisp :results value verbatim
(org-tables-to-list)
#+END_SRC

#+RESULTS: process-tables
: (("0" "1") ("2" "3"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM