我正在使用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
如果要调整它,请使用replace-regex
.
以下是将表格导出为制表符或逗号分隔值的步骤:
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 中会很棒,因为我认为很多人会使用它。