[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Use babel to import table data from OpenDocument spreadsheets?
From: |
James Harkins |
Subject: |
Re: [O] Use babel to import table data from OpenDocument spreadsheets? |
Date: |
Thu, 18 Jul 2013 17:32:37 -0400 |
User-agent: |
Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (Gojō) APEL/10.8 Emacs/23.3 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) |
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
- Re: [O] Use babel to import table data from OpenDocument spreadsheets?, (continued)
- Re: [O] Use babel to import table data from OpenDocument spreadsheets?, James Harkins, 2013/07/02
- Re: [O] Use babel to import table data from OpenDocument spreadsheets?, Jambunathan K, 2013/07/02
- Re: [O] Use babel to import table data from OpenDocument spreadsheets?, James Harkins, 2013/07/02
- Re: [O] Use babel to import table data from OpenDocument spreadsheets?, Jambunathan K, 2013/07/03
- Re: [O] Use babel to import table data from OpenDocument spreadsheets?, James Harkins, 2013/07/09
- Re: [O] Use babel to import table data from OpenDocument spreadsheets?, Jambunathan K, 2013/07/09
- Re: [O] Use babel to import table data from OpenDocument spreadsheets?, James Harkins, 2013/07/17
- Re: [O] Use babel to import table data from OpenDocument spreadsheets?, Jambunathan K, 2013/07/19
- Re: [O] Use babel to import table data from OpenDocument spreadsheets?, James Harkins, 2013/07/18
- Re: [O] Use babel to import table data from OpenDocument spreadsheets?, Jambunathan K, 2013/07/19
- Re: [O] Use babel to import table data from OpenDocument spreadsheets?,
James Harkins <=
- Re: [O] Use babel to import table data from OpenDocument spreadsheets?, Jambunathan K, 2013/07/19
- Re: [O] Use babel to import table data from OpenDocument spreadsheets?, Andreas Leha, 2013/07/10