emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

org-tables, export only certain column (csv)


From: Uwe Brauer
Subject: org-tables, export only certain column (csv)
Date: Wed, 24 Jun 2020 13:48:43 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi

4 years ago Michael Brand provided the following nice solution, which as
far as I know is still not in master.

(add-hook 'org-export-before-processing-hook 'f-ox-filter-table-column-del)

(defun f-ox-filter-table-column-del (back-end)
   "Delete the columns $2 to $> marked as \"/\" on a row with \"/\" in $1.
 If you want a non-empty column $1 to be deleted make it $2 by
 inserting an empty column before or rearrange column order in
 some other way. Make sure \"/\" is in $1 again after that."
   (while (re-search-forward
           "^[ \t]*| +/ +|\\(.*?|\\)?? +\\(/\\) +|" nil t)
     (goto-char (match-beginning 2))
     (org-table-delete-column)
     (beginning-of-line)))

What is  this code does can be best explained with the following example
table

| / | <>         |          <> | <>          |          <> | <>          | <>   
       | /          | /       | <>           |
|   | Title      |           L | M           |           X | J           | V    
       | Obligation | Balance | Past Balance |
|---+------------+-------------+-------------+-------------+-------------+-------------+------------+---------+--------------|
|   | Statistics | 11:00-12:00 | 12:00-13:00 | 12:00-12:00 | 12:00-13:00 |      
       |            |         |              |
|   | PDE        | 12:30-13:30 |             | 13:00-14:15 |             | 
12:30-13:30 |            |         |              |
|---+------------+-------------+-------------+-------------+-------------+-------------+------------+---------+--------------|
|   |            |             |             |             |             |      
       | 21.8       | 2.58    | -0.6         |

When exporting to latex or html the columns Obligation and Balance, will
not be exported (the first one neither).

However his code does not work when exporting it to CSV

I tried the following code

(defun org-table-export-to-xlsx () 
  (interactive)
  (let* ((source-file  (file-name-sans-extension (buffer-file-name 
(current-buffer))))
         (csv-file (concat source-file ".csv")))
    (save-excursion
      (f-ox-filter-table-column-del nil))
      (org-table-export csv-file "orgtbl-to-csv")
      (org-odt-convert csv-file "xlsx")))


But all columns are exported.

Does somebody have an idea?

Thanks and regards

Uwe Brauer 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]