#Table data extraction

19 messages · Page 1 of 1 (latest)

haughty agate
#
#let someList = table(
  columns: (auto, auto, auto, auto, auto, auto),
  align: (left, left, right, right, right, left),
  table.header[1][2][3][4][5][6],
  [some], [some], [some], [some], [some1], [some],
  [some], [some], [some], [some], [some2], [some],
  [some], [some], [some], [some], [some3], [some],
  [some], [some], [some], [some], [some4], [some],
  [some], [some], [some], [some], [some5], [some],
  [some], [some], [some], [some], [some6], [some],
  [some], [some], [some], [some], [some7], [some],
  [some], [some], [some], [some], [some8], [some],
  [some], [some], [some], [some], [some9], [some],
  [some], [some], [some], [some], [some10], [some],
  [What], [What], [what], [what], [what], [waht],
)

It looks like this, i want some<num> in a array

#

@edgy fog

#

what is footer

edgy fog
#

what do you mean about the footer?

#

for the table I meant if you paste the actual table (if it's not private) I would do the extraction to practice my helix skills

haughty agate
#

non public. idk what you'll do but i have been given data to work on a report.

edgy fog
#

ok then for fun let's see how complicated it would be to get the data from json

sullen smelt
#

for that table you can do this in vscode:

#

enable regex and replace

#
\[(.*?)\],{0,1}

with

arr.push($1);
#

won't work if you have escaped [] inside the tables of course

haughty agate
#

what does arr.push($1) do? This looks promising. it selected all the cells

#

i should make a copy one right?

sullen smelt
#

it pushes that regex match

#

[(.*?)],{0,1} --> .*? is what's in $1

edgy fog
#

for the json solution: if you add a label <tbl> to your table, this will extract all the cell texts:

typst query a.typ '<tbl>' | jq '.[0].children[] | select(.func=="cell").body.text'

(requires that you have the jq command installed in your system)

#

then to join them with commas in Bash you could do this:

lines=$(typst query a.typ '<tbl>' | jq '.[0].children[] | select(.func=="cell").body.text')
while read -r line; do printf "$line, "; done <<< "$lines"