(with-temp-file"/tmp/insert-file-test.org"
(goto-char (point-max))
(insert"some text at the start #+NAME: test-table1 | a | b | c | |---+---+---| | 1 | 2 | 3 | | 2 | 4 | 6 | |---+---+---| | | | 9 | #+TBLFM: @>$>=vsum(@I..@II) some text at the end #+NAME: notable #+BEGIN_EXAMPLE Some Example #+END_EXAMPLE some other text at the start #+NAME: test-table2 #+caption: original caption of test-table2 #+ATTR_LATEX: :font \\footnotesize :placement [H] | a | b | c | |---+----+----| | 1 | 20 | 10 | | 2 | 40 | 20 | |---+----+----| | | | 30 | #+TBLFM: @>$>=vsum(@I..@II) some other text at the end"))
Test
a
b
c
1
20
10
2
40
20
30
a
b
c
1
20
10
2
40
20
30
TableFilter
(let ((lst (split-string vals)))
(concatenate'list (loop for row in tbl
if (member (nth col row) lst)
collect row into newtbl
;; else do (princ (format "%s: %s\n" (nth col row) lst))
finally return newtbl)))
Test
Name
A
B
Peter
1
10
Paul
2
20
Mary
3
30
Peter
4
40
Mary
5
50
Peter
6
60
Name
A
B
Peter
1
10
Paul
2
20
Peter
4
40
Peter
6
60
GroupTable
import pandas as pd
import numpy as np
import orgbabelhelper as obh
import sys
import re
df = obh.orgtable_to_dataframe(tbl)
grparr = re.split(r",\s*", grp)
#print re.split(r",\s*", rescols) + [grp]
df = df[re.split(r",\s*", rescols) + grparr]
for elem in grparr:
assert elem in df.columns, "Error: group column %s not in table columns %s"% (elem, ",".join(df.columns))
if op =="sum":
res = df.groupby(grparr).sum()
else:
error("operation %s not implemented"% op)
sys.exit(1)
print obh.dataframe_to_orgtable(res)
Test
Name
Year
A
B
Peter
2018
1
10
Paul
2018
2
20
Mary
2018
3
30
Peter
2019
4
40
Paul
2019
5
50
Mary
2019
5
60
Peter
2019
6
70
Name
B
Mary
90
Paul
70
Peter
120
Year
Name
B
2018
Mary
30
2018
Paul
20
2018
Peter
10
2019
Mary
60
2019
Paul
50
2019
Peter
110
ExportOneTableToExcel
Function to write a single table TBL to an Excel file FNAME.
import pandas as pd
import numpy as np
from pathlib import Path
import orgbabelhelper as obh
import openpyxl
df = obh.orgtable_to_dataframe(tbl)
with pd.ExcelWriter(fname, engine='openpyxl') as writer:
if Path(fname).exists():
book = openpyxl.load_workbook(fname)
writer.book = book
df.to_excel(writer, sheet, index=False)
writer.save()
TODO: Suppress columns/rows containing org meta information (e.g. “!” column)
ExportTablesToExcel
Function to write several tables to different sheets in the same
Excel file FNAME. The table names are given as a string TBLNAMES
containing the comma separated list of table names. The sheet name
is given in SHEET.
Here I use a method copied from the org-sbe implementation where
a particular source block is called by executing
org-babel-execute-src-block on a constructed source block info
structure, where the call is given as part of that source block’s
:var definition.