Version 6 of report

Updated 2001-11-12 19:56:06

Documentation can be found at http://tcllib.sourceforge.net/doc/report.html


Has anyone done anything simple with this command? I'm having problems figuring where to start.


 package require csv
 package require report
 package require struct

 ... open a channel to a a CSV file, with default separator (comma)

 struct::matrix::matrix    m

 # The following code extracts the number of columns from the file
 # and initializes the matrix to that number of columns.

 if {[gets $channel line] < 0} {
     # here, you either continue, return with an error, or take some other action for when the file being read is empty
 }
 set data [::csv::split $line $sepChar]

 m add columns [llength $data]
 m add row $data

 csv::read2matrix $channel m
 report::report         r [m columns] ; # (*)
 r printmatrix2channel  m stdout

This should print the CSV file to stdout, auto-formatted so that each column is wide enough to hold the longest value of that column. No visual frills like header, footer or column separators.


For output as HTML table add

 ::report::defstyle html {} {
    set c  [columns]
     set cl $c ; incr cl -1
     data set "<tr> [split [string repeat " " $cl] ""] </tr>"
     for {set col 0} {$col < $c} {incr col} {
         pad $col left  "<td>"
         pad $col right "</td>"
     }
     return
 }

somewhere before the creation of the report and use

 report::report r [m columns] style html

to create the report object, see (*) above.


Category Package, subset Tcllib