我正在使用一个区域转换为一个表C-c |.
有没有办法扭转这个过程,比如转换后做一些编辑并回到原始格式(制表符分隔值会做什么)?
我知道我可以通过这样做,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)
Run Code Online (Sandbox Code Playgroud)
如果将其添加到适当的组织模式中那就太好了,因为我认为很多人都会使用它。
尝试使用orgtbl-to-tsv获取制表符分隔的值。
也有orgtbl-to-csv用于逗号分隔的值。
例如:
* Some heading
#+name: foo
| a | b | c |
|---+---+---|
| 1 | 2 | 3 |
| 4 | 5 | 6 |
#+BEGIN_SRC elisp :var x=foo
(orgtbl-to-csv x nil)
#+END_SRC
#+RESULTS:
: 1,2,3
: 4,5,6
Run Code Online (Sandbox Code Playgroud)
以下是将表导出为制表符或逗号分隔值的步骤:
M-x org-table-export这些是一些可以使用的格式: