From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas von Dein Subject: [feature-request] make org-quote-csv-field customizable Date: Wed, 2 Aug 2017 12:26:35 +0200 Message-ID: <20170802102635.GS76265@r4> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcqra-0001gn-3p for emacs-orgmode@gnu.org; Wed, 02 Aug 2017 06:26:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dcqrS-00055v-J7 for emacs-orgmode@gnu.org; Wed, 02 Aug 2017 06:26:45 -0400 Received: from mx.daemon.de ([78.47.130.37]:54293) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dcqrS-00050k-Bi for emacs-orgmode@gnu.org; Wed, 02 Aug 2017 06:26:42 -0400 Content-Disposition: inline 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" To: emacs-orgmode@gnu.org 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