unofficial mirror of emacs-orgmode@gnu.org
 help / color / Atom feed
* org-tables, export only certain column (csv)
@ 2020-06-24 11:48 Uwe Brauer
  0 siblings, 0 replies; only message in thread
From: Uwe Brauer @ 2020-06-24 11:48 UTC (permalink / raw)
  To: emacs-orgmode


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 



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-24 11:48 org-tables, export only certain column (csv) Uwe Brauer

unofficial mirror of emacs-orgmode@gnu.org

Archives are clonable:
	git clone --mirror https://yhetil.org/orgmode/0 orgmode/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 orgmode orgmode/ https://yhetil.org/orgmode \
		emacs-orgmode@gnu.org
	public-inbox-index orgmode

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git