【发布时间】:2013-07-18 07:41:18
【问题描述】:
我正在使用C-c | 将区域转换为表格。
有没有办法扭转这个过程,比如在转换后进行一些编辑并返回原始格式(制表符分隔值就可以了)?
我知道我可以通过org-table-export 做到这一点,但这太麻烦了。
【问题讨论】:
我正在使用C-c | 将区域转换为表格。
有没有办法扭转这个过程,比如在转换后进行一些编辑并返回原始格式(制表符分隔值就可以了)?
我知道我可以通过org-table-export 做到这一点,但这太麻烦了。
【问题讨论】:
尝试orgtbl-to-tsv 以获取制表符分隔值。
还有orgtbl-to-csv 用于逗号分隔值。
将表格与短代码块结合起来进行转换很方便。例如:
* Some heading
#+name: foo
| a | b | c |
|---+---+---|
| 1 | 2 | 3 |
| 4 | 5 | 6 |
#+name: foo-csv
#+BEGIN_SRC elisp :var x=foo :wrap example
(orgtbl-to-csv x nil)
#+END_SRC
#+RESULTS: foo-csv
#+begin_example
1,2,3
4,5,6
#+end_example
C-c C-c 在代码块上会产生显示的结果。将:colnames no 作为标题参数添加到代码块也将保留标题行:
#+name: foo-csv
#+BEGIN_SRC elisp :var x=foo :wrap example :results raw :colnames no
(orgtbl-to-csv x nil)
#+END_SRC
#+RESULTS: foo-csv
#+begin_example
a,b,c
1,2,3
4,5,6
#+end_example
【讨论】:
org-table-export,然后选择orgtbl-to-tsv。
orgtbl-to-tsv 和 org-tbl-to-csv 自 2008 年 release_6.03 起成为 Org 模式的一部分。它们可以在文件 lisp/org-table.el 中找到。它们应该可以在任何最近的 Emacs 中使用,尽管早在 2013 年 Org 模式可能还不是 Emacs 的一部分,因此必须手动安装。
如果你想调整它,请使用replace-regex。
【讨论】:
orgtbl 命令来执行此操作?正如 OP 所要求的那样,类似于逆 C-c |.
以下是将表格导出为制表符或逗号分隔值的步骤:
M-x org-table-export
以下是一些可以使用的格式:
【讨论】:
我也需要这个,只是根据 org-table-export 写了以下内容:
(defun org-table-transform-in-place ()
"Just like `ORG-TABLE-EXPORT', but instead of exporting to a
file, replace table with data formatted according to user's
choice, where the format choices are the same as
org-table-export."
(interactive)
(unless (org-at-table-p) (user-error "No table at point"))
(org-table-align)
(let* ((format
(completing-read "Transform table function: "
'("orgtbl-to-tsv" "orgtbl-to-csv" "orgtbl-to-latex"
"orgtbl-to-html" "orgtbl-to-generic"
"orgtbl-to-texinfo" "orgtbl-to-orgtbl"
"orgtbl-to-unicode")))
(curr-point (point)))
(if (string-match "\\([^ \t\r\n]+\\)\\( +.*\\)?" format)
(let ((transform (intern (match-string 1 format)))
(params (and (match-end 2)
(read (concat "(" (match-string 2 format) ")"))))
(table (org-table-to-lisp
(buffer-substring-no-properties
(org-table-begin) (org-table-end)))))
(unless (fboundp transform)
(user-error "No such transformation function %s" transform))
(save-restriction
(with-output-to-string
(delete-region (org-table-begin) (org-table-end))
(insert (funcall transform table params) "\n")))
(goto-char curr-point)
(beginning-of-line)
(message "Tranformation done."))
(user-error "Table export format invalid"))))
(define-key org-mode-map (kbd "\C-x |") 'org-table-transform-in-place)
如果将它添加到适当的 org-mode 中会很棒,因为我认为很多人会使用它。
【讨论】: