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).


In reply to Module proposal: Text::FormatComplexTables by mirod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.