emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Bug: Revert orgtbl-create-or-convert-from-region [6.33x]


From: Thorsten Jolitz
Subject: Re: [O] Bug: Revert orgtbl-create-or-convert-from-region [6.33x]
Date: Mon, 05 Aug 2013 16:07:49 +0200
User-agent: Gnus/5.130002 (Ma Gnus v0.2) Emacs/24.3 (gnu/linux)

Thorsten Jolitz <address@hidden> writes:

> Or use something like this:
>
> #+begin_src emacs-lisp
>   (defun tj/insert-exported-table (&optional insertion-point file)
>     (let ((tmp-file (or file (make-temp-file "foo")))
>           (insert-point (or insertion-point (1+ (org-table-end)))))
>       (org-table-export tmp-file "orgtbl-to-csv")
>       (goto-char insert-point)
>       (insert-file-contents tmp-file)))
> #+end_src

actually, to make it more useful, it should be expanded to something like:

#+begin_src emacs-lisp
  (defun tj/insert-exported-table (&optional insertion-point format file)
    "Insert table exportet to FILE with function FORMAT.
  Insertion position is either below the exportet table or INSERTION-POINT."
    (interactive
     (cond
      ((equal current-prefix-arg nil) nil)
      ((equal current-prefix-arg '(4))
       (list
        (read-number "Insertion Point: ")))
      ((equal current-prefix-arg '(16))
       (list
        (read-number "Insertion Point: ")
        ;; enter without double quotes
        (read-string "Format: ")))
      (t
       (list
        (read-number "Insertion Point: ")
        (read-string "Format: ")
        (ido-read-file-name "File: ")))))
    (let ((tmp-file (or file (make-temp-file "foo")))
          (insert-point (or insertion-point (1+ (org-table-end))))
          (fmt (or format "orgtbl-to-csv")))
      (org-table-export tmp-file fmt)
      (save-excursion
        (goto-char insert-point)
        (insert-file-contents tmp-file))))
#+end_src

#+results:
: tj/insert-exported-table

do 'M-x tj/insert-exported-table' on this table:

| header 1 | header 2 | header 3 |
|----------+----------+----------|
| label1   |        3 |       99 |
| label2   |        2 |       66 |
| label3   |        7 |      231 |

header 1,header 2,header 3
label1,3,99
label2,2,66
label3,7,231

-- 
cheers,
Thorsten




reply via email to

[Prev in Thread] Current Thread [Next in Thread]