From: James Harkins <jamshark70@gmail.com>
To: Jambunathan K <kjambunathan@gmail.com>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: Use babel to import table data from OpenDocument spreadsheets?
Date: Thu, 18 Jul 2013 17:32:37 -0400 [thread overview]
Message-ID: <8738rbv9je.wl%jamshark70@dewdrop-world.net> (raw)
In-Reply-To: <87r4evzo6j.fsf@gmail.com>
At Fri, 19 Jul 2013 00:32:44 +0530,
Jambunathan K wrote:
> I don't want to venture in to Babel.
>
> I don't want to experiment with unoconv either. I have a non-official
> libreoffice installed. Pulling in official unoconv will interfere with
> my working installation.
Fair enough.
> For your purposes, just soffice will do.
Except that I tried using soffice --headless, but I could never get it to write any output file.
> (defun org-table-import-ods (&optional file-name)
> (interactive "fFile: ")
> (let ((csv-file (org-odt-convert file-name "csv"))
> (pos (point)))
> (save-excursion
> (insert (with-temp-buffer
> (insert-file-contents csv-file)
> (org-table-convert-region (point-min) (point-max) '(4))
> (buffer-string))))))
Wow, thanks, this is great! I never would have guessed the stuff about with-temp-buffer.
This snippet didn't handle the part about deleting the old table contents, but I was actually able to figure that out on my own (below).
And... using it in a src block as below... works! I don't see the change in table contents in the original org buffer, but the new contents definitely show up in the HTML export. That's all I need, and I'd agree that this behavior -- protecting the org file from side effects -- is safer.
Next, parameterize the file name and table name.
So this is really pretty f'''... sweet. I'm thrilled! Thanks to Jambunathan for the crucial info that got me over the part I just couldn't figure out on my own.
hjh
#+name: gettable1
#+begin_src emacs-lisp :exports results
(defun org-table-import-ods (&optional file-name)
(interactive "fFile: ")
(let ((csv-path (concat (file-name-sans-extension file-name) ".csv"))
(pos (point)))
(shell-command (concat "unoconv -f csv -i 9,34,system,1,1/5/2/1/3/1/4/1 " file-name))
(save-excursion
(let ((table-begin
(funcall (lambda ()
(search-forward "#+name: table1")
(search-forward-regexp "^|")
(beginning-of-line)
(point))))
(table-end
(funcall (lambda ()
(search-forward "# end table")
(beginning-of-line)
(point)))))
(delete-region table-begin table-end)
(goto-char table-begin)
(insert (with-temp-buffer
(insert-file-contents csv-path)
(org-table-convert-region (point-min) (point-max) '(16))
(buffer-string)))
(goto-char table-begin)
(org-table-insert-hline)))))
(org-table-import-ods "html-table.ods")
#+end_src
next prev parent reply other threads:[~2013-07-18 21:32 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-02 14:10 Use babel to import table data from OpenDocument spreadsheets? James Harkins
2013-07-02 14:19 ` Jambunathan K
2013-07-02 14:30 ` James Harkins
2013-07-02 15:10 ` Jambunathan K
2013-07-03 2:35 ` James Harkins
2013-07-03 3:05 ` Jambunathan K
2013-07-10 2:19 ` James Harkins
2013-07-10 3:50 ` Jambunathan K
2013-07-18 1:28 ` James Harkins
2013-07-18 9:19 ` Jambunathan K
2013-07-18 15:42 ` James Harkins
2013-07-18 19:02 ` Jambunathan K
2013-07-18 19:05 ` Jambunathan K
2013-07-18 21:32 ` James Harkins [this message]
2013-07-10 21:31 ` Andreas Leha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8738rbv9je.wl%jamshark70@dewdrop-world.net \
--to=jamshark70@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=kjambunathan@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).