emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Thomas von Dein <tom@vondein.org>
To: emacs-orgmode@gnu.org
Subject: [feature-request] make org-quote-csv-field customizable
Date: Wed, 2 Aug 2017 12:26:35 +0200	[thread overview]
Message-ID: <20170802102635.GS76265@r4> (raw)

Hello,

currently when exporting a table to CSV, fields are quoted automatically
if they contain a comma or a quote character. The regexp for this
determination is hard-coded in 'org-quote-csv-field.

This is good for most use cases. However, if you want to import such a
CSV with MS Excel then some unquoted fields will be automatically
converted by Excel into another format.

An example is a field containing 192.168.10.233. 'org-quote-csv-field
doesn't quote it, but Excel - for reasons I cannot fathom - considers
this a number (it doesn't do this when the last octet is below 233
though) and converts it to 19216810233 - which is wrong.

I wrote the following code to circumvent this Excel bug:

(defun tvd-org-quote-csv-field (s)
  "Quote every field and precede it with = to disable excel automatisms."
  (if (string-match "." s)
      (concat "=\"" (mapconcat 'identity
                               (split-string s "\"") "\"\"") "\"")
    s))

(defun table-to-excel ()
  "export current org table to CSV format suitable for MS Excel."
  (interactive)
  ;; quote everything, map temporarily 'org-quote-csv-field
  ;; to my version
  (cl-letf (((symbol-function 'org-quote-csv-field)
             #'tvd-org-quote-csv-field))
           (org-table-export "/tmp/ex.csv" "orgtbl-to-csv")))

To make this customizable, it would be good to have a variable which
contains the regex to determine what to quote. A parameter to
org-table-export would be an even better solution.


best regards, and thanks for this great module!
Tom

             reply	other threads:[~2017-08-02 10:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-02 10:26 Thomas von Dein [this message]
2017-08-03 22:13 ` [feature-request] make org-quote-csv-field customizable Nicolas Goaziou
2017-08-03 23:19   ` Tim Cross

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=20170802102635.GS76265@r4 \
    --to=tom@vondein.org \
    --cc=emacs-orgmode@gnu.org \
    /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).