我正在使用C-c |
将区域转换为表格。
有没有办法扭转这个过程,比如转换后做一些编辑并回到原始格式(制表符分隔值会做什么)?
我知道我可以通过org-table-export
来做,但这太麻烦了。
答案 0 :(得分:5)
尝试使用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
答案 1 :(得分:3)
如果您想进行调整,请使用replace-regex
。
答案 2 :(得分:3)
以下是将表格导出为制表符或逗号分隔值的步骤:
M-x org-table-export
这些是可以使用的一些格式:
答案 3 :(得分:1)
我也需要这个,只是基于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中,我认为很多人会使用它,那就太棒了。