Tinderbox v9 Icon

ExportingTabular data as Tab-delim or CSV

Tinderbox is perfectly capable of exporting data tables in either Tab-delimited (TSV) or Commas Separated (CSV formats). Indeed, it is possible to use the same methods to export in formats like JSON It basically boils down to two aspects:

Structure

The best way to achieve this is to export a container using its chid notes as the source of the data rows. Less usually, descendant notes can be used to provide part of the per-row data. Depending on the nature of the task and the layout of the document, it is possible to use either a standard container note, or an agent to provide the data source.

Templates

This process needs two templates. The first, used by the source container, sets the column headings for the table. These headings are generally set as literal strings. Thus for TSV ('[Tab] implies an otherwise invisible tab character, and [Return] a line return):

Part[Tab]Cost[Tab]Number[Tab]Total[Return] 

^children("tsv-item")^ 

or as CSV:

"Part","Cost","Number","Total"[Return] 

^children("csv-item")^ 

In either case the template exports a set of 4 literal headers and than includes each of it's children in turn using the same template (which is different to this one)

For the children, assume the following. The 'Part' is the title of the note (thus, data from $Name). The 'Cost' will be from a user Number-type attribute ($Cost) and will need formatting as a number with two decimal places. The 'Number' will be taken from a user attribute 'Ordered' (so $Ordered). Lastly the line's 'Total' will be calculated as a number with two decimal places and based on the two preceding values.

First, in TSV form:

^value($Name)^[tab]^value($Cost.format(2))^[tab]^value($Ordered)^[tab]^value(($Cost*$Ordered).format(2))^[Return] 

and in CSV form

"^value($Name)^","^value($Cost.format(2))^","^value($Ordered)^","^value(($Cost*$Ordered).format(2))^[Return] 



A Tinderbox Reference File : Export : ExportingTabular data as Tab-delim or CSV