我使用C-c |
將區域轉換爲表格。如何將組織模式錶轉換爲原始選項卡式格式?
有沒有辦法扭轉這個過程,比如轉換後做一些編輯並返回到原始格式(製表符分隔的值會這樣)?
我知道我可以通過org-table-export
來做,但這太麻煩了。
我使用C-c |
將區域轉換爲表格。如何將組織模式錶轉換爲原始選項卡式格式?
有沒有辦法扭轉這個過程,比如轉換後做一些編輯並返回到原始格式(製表符分隔的值會這樣)?
我知道我可以通過org-table-export
來做,但這太麻煩了。
如果你想調整它,使用replace-regex
。
嘗試用於製表符分隔值的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
下面是使用該表導出爲標籤或逗號分隔值的步驟:
M-x 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)
這將會是巨大的,如果這引起了加入組織模式正確因爲我認爲很多人會使用它。
是的,這應該工作,但有沒有包含'orgtbl'命令來做到這一點?正如OP所問,類似於「C-c |」的反義詞。 – quazgar
聰明的解決方案,謝謝! –