From: "Nicolas Richard" <email@example.com>
Subject: Converting csv (with new lines) to org-mode.
Date: Thu, 31 Jan 2013 13:25:45 +0100 [thread overview]
Message-ID: <firstname.lastname@example.org> (raw)
A csv table can include newlines in its fields, which confuses the csv
parser contained in org-table-convert-region. Since I had no time to
patch the current implementation of org-table-convert-region, I decided
to use an already existing csv parser found in marmalade. You find below
the code I used (requires pcsv, a csv parser) if anyone is interested.
It's very simple : pcsv does the work of transforming the csv into a
list of list, then I mapconcat those using " | " as separator.
(defun yf/lisp-table-to-org-table (table &optional function)
"Convert a lisp table to `org-mode' syntax, applying FUNCTION to each of its elements.
The elements should not have any more newlines in them after
applying FUNCTION ; the default converts them to spaces. Return
value is a string containg the unaligned `org-mode' table."
(unless (functionp function)
(setq function (lambda (x) (replace-regexp-in-string "\n" " " x))))
(mapconcat (lambda (x) ; x is a line.
(concat "| " (mapconcat function x " | ") " |"))
(defun yf/csv-to-table (beg end)
"Convert a csv file to an `org-mode' table."
(insert (yf/lisp-table-to-org-table (pcsv-parse-region beg end)))
(delete-region beg end)
next reply other threads:[~2013-01-31 12:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-31 12:25 Nicolas Richard [this message]
2013-02-15 21:29 ` Converting csv (with new lines) to org-mode Bastien
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:
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
* 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
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).