From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id CD+bF+qHi2CpEQEAgWs5BA (envelope-from ) for ; Fri, 30 Apr 2021 06:30:34 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id AEltEuqHi2AQGQAA1q6Kng (envelope-from ) for ; Fri, 30 Apr 2021 04:30:34 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 0910B11DAA for ; Fri, 30 Apr 2021 06:30:33 +0200 (CEST) Received: from localhost ([::1]:40958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcKnO-0002Lx-EZ for larch@yhetil.org; Fri, 30 Apr 2021 00:30:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcKmz-0002Le-ST for emacs-orgmode@gnu.org; Fri, 30 Apr 2021 00:30:06 -0400 Received: from ciao.gmane.io ([116.202.254.214]:34184) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcKmy-0002p2-CX for emacs-orgmode@gnu.org; Fri, 30 Apr 2021 00:30:05 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1lcKmv-000239-Mg for emacs-orgmode@gnu.org; Fri, 30 Apr 2021 06:30:01 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Pankaj Jangid Subject: Transforming table and then exporting as CSV Date: Thu, 29 Apr 2021 20:31:02 +0530 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (darwin) Cancel-Lock: sha1:k0As9pBveL4COwdVJJsozigr6+Q= Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_12_24=1.049, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1619757033; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=RRZ+cK3nx1AZGPtLYJeRF5j71HcpB7DegV7uwsuPAq8=; b=r8WdaCn4Mz0oxzGIxB55wVLU7c1oDrP4Tl66NdC1q9lUzWt9K+lj4PVt+F5Irgxmleb3qK FWdCWRcD2Tjk5CWUfOAKW6x3wwA63IQ+fmtpFfUVRESWCNN+c2UhO4J9B0WiHe9ZUTXEAz BvMqNwlhRG25e0dQEtIRz1z+RiAytIU2hF34Uii8Da44vT2SenxQzpIckwjJ5bjkF1w+pT vAVAKitEh/WL6vah5Pru+k8HGX5rng+sD05IO1u0TIHW7llW46/x+4s254AzPKA6oDS6Eg /osFpFGCB6kOodtmUGTPkuvS421FrYd13e6aAcPZn6KjP2Hxez+l5GPvmsyNKQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619757033; a=rsa-sha256; cv=none; b=m5SrUp966hmQt+gbyke56xdRD5bdJdNcCJjfjVSW/xA7kHLDG3VqRFAuf9keZUmt8zmrwr 9JQzFa4/fBh7dk+3n+6SCvwe5OLif1UtrEnqbOBsApAHyh9dFFKJGKcbMslExmQQEtcEp3 NoLg1qmgAx7wmeAuG6XlIP65OQvyFzfuhb8NcTGyphLYBIbcqPD6Lbt5ZdVpBEPoWsF7EX ykTLi9d6alo+dqR2N48woeWHUn0mC2zWP7QftNFqLNoFJJNA9RrMLGRhtBhQFo6HDLaSX5 sOqnLOLUCFF/uRB3PjFqE4DSdSMPnehgACOw8m5Cg8HY88jyAPF2Sr3TQwpBrg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -1.96 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 0910B11DAA X-Spam-Score: -1.96 X-Migadu-Scanner: scn0.migadu.com X-TUID: b5nwWJKfQPwl I have the following requirement. For this I have written the code that follows. Bank requires from me a CSV file in this format: --8<---------------cut here---------------start------------->8--- ACCOUNT NO,DR/CR,AMOUNT,NARRATION 50.......658,C,xxxxx.xx,APR2021 50.......590,C,xxxxx.xx,APR2021 50.......904,C,xxxxx.xx,APR2021 06.......965,C,xxxxx.xx,APR2021 50.......489,C,xxxxx.xx,APR2021 50.......680,C,xxxxx.xx,APR2021 50.......357,C,xxxxx.xx,APR2021 --8<---------------cut here---------------end--------------->8--- But this doesn’t have names of the people. First column shows the account numbers. So I have created an org-table like this --8<---------------cut here---------------start------------->8--- * April 2021 :PROPERTIES: :TABLE_EXPORT_FILE: enet_apr_2021/0684SAL2904.001.csv :TABLE_EXPORT_FORMAT: orgtbl-to-csv :END: #+NAME: APR2021 | NAME | ACCOUNT NO | DR/CR | AMOUNT | NARRATION | |-----------------------+----------------+-------+-----------+-----------| | Dh........ma...arwal | 50.........658 | C | xxxxx.xx | APR2021 | | Pr........ar | 50.........590 | C | xxxxx.xx | APR2021 | | Ol........y | 50.........904 | C | xxxxx.xx | APR2021 | | Sa........gid | 06.........965 | C | xxxxx.xx | APR2021 | | Pa........gid | 50.........489 | C | xxxxx.xx | APR2021 | | Ma........ar | 50.........680 | C | xxxxx.xx | APR2021 | | Sh........agi | 50.........357 | C | xxxxx.xx | APR2021 | |-----------------------+----------------+-------+-----------+-----------| | TOTAL | | | xxxxxx.xx | | #+TBLFM: $4=$4;%.2f --8<---------------cut here---------------end--------------->8--- I have written below code for the conversion. This code removes the first column and last row. And then run ‘org-table-export‘. This works fine. #+begin_src elisp (require 'org) (defun enet-export (name) (interactive "MTable Name: ") (outline-show-all) (let ((case-fold-search t)) (goto-char (point-min)) (if (search-forward-regexp (concat "#\\+NAME: +" name) nil t) (progn (forward-line) (let* ((beg (org-table-begin)) (end (org-table-end)) (txt (buffer-substring-no-properties beg end)) (file (org-entry-get (point) "TABLE_EXPORT_FILE")) (format (org-entry-get (point) "TABLE_EXPORT_FORMAT"))) (with-temp-buffer (insert txt) (goto-char (point-min)) (org-table-next-field) (org-table-delete-column) (goto-char (org-table-end)) (backward-char) (org-table-kill-row) (org-table-kill-row) (org-entry-put (point) "TABLE_EXPORT_FILE" file) (org-entry-put (point) "TABLE_EXPORT_FORMAT" format) (make-directory (file-name-directory file) t) (org-table-export)))) (message "Not Found")))) #+end_src Same org file has multiple tables, so I am asking for “Table Name”. I want to do two improvements: 1. When asking for table name, I want to offer all the table names in the file as completion options. 2. Current table at point as default 3. I want to run the function from command line. Like, --8<---------------cut here---------------start------------->8--- emacs --batch enet_2021_22.org -l enet.el --eval="(enet-export \"APR2021\")" --8<---------------cut here---------------end--------------->8--- Do I need to change the (interactive...) part in any way to enable this? -- Regards Pankaj