Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Module proposal: Text::FormatComplexTables

by mirod (Canon)
on Sep 25, 2002 at 14:45 UTC ( [id://200639]=perlmeditation: print w/replies, xml ) Need Help??

I have a need to format tables as text. The original tables are in OpenOffice XML format and the text export does not format them.

I have looked around for an existing solution to this problem, but I have not found any module or canned script that would allow me to do this, even if I converted the OO format to HTML.

Is there any way I could re-use an existing tool?

If not I plan to write a module: Text::FormatComplexTable (Text::FormatTable already exists but it only creates simple tables, now row/col span for example)

The pod is below, comments are welcomed:


SYNOPSIS

  use Text::FormatComplexTable;

  my $table= Text::FormatComplexTable->new( width => 80,
                                          );
  $table->add_cell( "text of cell 1x1");
  $table->add_cell( { colspan => 2 }, "text of cell 1x2,3");
  $table->add_cell( { rowspan => 2 }, "text of cell 1,2x4");
  $table->new_row;
  $table->add_cell( { align => "right" }, "text of cell 2x1");
  $table->add_cell( { valign => "top"  }, "text of cell 2x2");
  $table->add_cell( "text of cell 2x3\nincluding line returns");

  $table->add_row( "text of cell 3x1",
                   { colspan => 3 }, "text of cell 3x2-4");
  $table->add_row_before( 1, "text of cell 0x1", 
                             { colspan => 3 }, "text of cell 0x2-4");
  $table->add_column( "text of cell 0x5", 
                      { rowspan => 3 }, "text of cell 1-4x5")
  $table->add_column_before( 1, "text of cell 0x0", 
                                { rowspan => 4 }, "text of cell 1-4x0")
  $table->set_column_width( 20, 10, 10, 10, 10, 20);

  my $table_as_text= $table->render; # that's where the job is really done 
                                     # performed and error checks


DESCRIPTION

This modules allows editing of tables with a syntax similar to html, and renders them to text


TODO

code the module ;--)

naming of cells/rows/columns

deleting/editing of cells/rows/columns (by position or par name)

traversal of the table (so you can edit/insert/delete cells/rows/columns)

direct import of HTML tables (using an HTML parser)

other export formats: HTML (trivial), XML (based on names?)

use as a SAX filter

nested tables


AUTHOR

Michel Rodriguez <mirod@xmltwig.com>


SEE ALSO

perl(1).

  • Comment on Module proposal: Text::FormatComplexTables

Replies are listed 'Best First'.
Re: Module proposal: Text::FormatComplexTables
by trs80 (Priest) on Sep 25, 2002 at 19:44 UTC
    I have used in the past a system call to get the results from a w3m (or sourceforge to download) source dump.
    my $file_to_read = "/home/trs80/tables.htm"; my $w3m = qx!/usr/local/bin/w3m -dump $file_to_read!; print $w3m;
    I know this is a far cry from a Perl only solution, but this method serves me well for my needs, and supports embedded tables to a point. You can even view the perlmonks with good format and layout :)
Re: Module proposal: Text::FormatComplexTables
by BUU (Prior) on Sep 25, 2002 at 21:59 UTC
    Maybe its just me and i dont see it from reading the module or what not, but i fail to see the advantange over just using an array of arrays, (and then dumping to a templater if nesscesary). So how is this better?

    update
    During further thought, maybe you should just write a module that would automagically generate a table from an array of arrays? Automatically doing nice things such as resizing everything to fit and so forth with colspans/rowspans, and then implementing the multiple outputs (xml n stuff)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://200639]
Approved by TStanley
Front-paged by trs80
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-24 11:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found