Friday, March 22, 2013

reportx - Tcl Framework To Generate Tabular Reports

The reportx Framework:

  • Tcllib is an excellent set of libraries used in various areas of applications like networking, data structures, documentation, mathematics.... etc. etc.
  • The ::report and struct::matrix packages of tcllib can be used to generate tabular reports such as the one below: 

In this post, I will present a small framework that simplifies the usage of these two packages in generating tabular reports. This framework is named reportx. The reportx framework itself contains only one method/proc named ::reportx::format.

The format method takes 3 arguments (onely one mandatory and 2 optional):
  1. Tabular Format Template:
    1. Defines the structure of the report starting outer most table to rows inside the table and the columns in each row.
    2. Is a nested/recursive structure. Hence, you can define a cell to create sub-tables.
    3. Can have Tcl variable names (e.g. $company_name) that will be substituted with values later.
    4. Can also mention the name of the style definition to be applied to the outer most table, rows and columns.
  2.  Data Values: Optional list of name-value pairs that will be used to substitute the variables in the template.
  3. Style Definitions: Optional list of style definitions of the style names used in the template
The signature of this method is:
proc ::reportx::format {template   {subst_data ""}   {styles_def ""}}
::reportx::format method returns a string that contains the entire formatted report that can be sent to a printing framework.

Source Code & Demo:

The source code and demo applications can be downloaded from: reportx github repository

Acknowledgement:

I must thank Hai for his blog on Tcl Print CSV File from where I've learnt about the ::report package.

No comments:

Post a Comment