From mboxrd@z Thu Jan 1 00:00:00 1970 From: James Harkins Subject: Re: Use babel to import table data from OpenDocument spreadsheets? Date: Thu, 18 Jul 2013 17:32:37 -0400 Message-ID: <8738rbv9je.wl%jamshark70@dewdrop-world.net> References: <87k3l9kq78.wl%jamshark70@dewdrop-world.net> <878v1pvybk.fsf@gmail.com> <87y59p591f.wl%jamshark70@dewdrop-world.net> <87y59p80b3.fsf@gmail.com> <87vc4s5q0o.wl%jamshark70@dewdrop-world.net> <87ip0j5f8q.wl%jamshark70@dewdrop-world.net> <87a9lv9ipq.fsf@gmail.com> <874nbszmfw.wl%jamshark70@dewdrop-world.net> <87a9lkns2z.fsf@gmail.com> <8738rbzxgn.wl%jamshark70@dewdrop-world.net> <87r4evzo6j.fsf@gmail.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uzvoi-0005J2-3j for emacs-orgmode@gnu.org; Thu, 18 Jul 2013 17:32:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uzvog-0008Jn-5V for emacs-orgmode@gnu.org; Thu, 18 Jul 2013 17:32:52 -0400 Received: from mail-oa0-x22d.google.com ([2607:f8b0:4003:c02::22d]:33428) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uzvog-0008Jg-0l for emacs-orgmode@gnu.org; Thu, 18 Jul 2013 17:32:50 -0400 Received: by mail-oa0-f45.google.com with SMTP id j1so4824075oag.18 for ; Thu, 18 Jul 2013 14:32:49 -0700 (PDT) In-Reply-To: <87r4evzo6j.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Jambunathan K Cc: orgmode 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