NAME
HTML::Table - produces HTML tables
SYNOPSIS
use HTML::Table;
$table1 = new HTML::Table($rows, $cols);
$table1->setCell($cellrow, $cellcol, "This is Cell 1");
$table1->setCellBGColor("blue");
$table1->setCellColSpan(1,1, 2);
$table1->print;
$table2 = new HTML::Table;
$table2->addRow(@cell_values);
$table2->addCol(@cell_values2);
$table1->setCell(1,1, "$table2->getTable");
$table1->print;
REQUIRES
Perl5.002
EXPORTS
Nothing
DESCRIPTION
HTML::Table is used to generate HTML tables for CGI scripts. By using the methods provided fairly complex tables can be created, manipulated, then printed from Perl scripts. The module also greatly simplifies creating tables within tables from Perl. It is possible to create an entire table using the methods provided and never use an HTML tag.
HTML::Table also allows for creating dynamically sized tables via its addRow and addCol methods. These methods automatically resize the table if passed more cell values than will fit in the current table grid.
Methods are provided for nearly all valid table, row, and cell tags specified for HTML 3.0.
METHODS
[] indicate optional parameters. default value will
be used if no value is specified
Creation
- new HTML::Table([num_rows, num_cols])
-
Creates a new HTML table object. If rows and columns are specified, the table will be initialized to that size. Row and Column numbers start at 1,1. 0,0 is considered an empty table.
Table Level Methods
- setBorder([pixels])
-
Sets the table Border Width -- <BORDER> tag
- setWidth([pixels|percentofscreen])
-
Sets the table width -- <WIDTH> tag Remember to escape percent symbol if used
- setCellSpacing([pixels])
- setCellPadding([pixels])
- setCaption("CaptionText" [, TOP|BOTTOM])
- setBGColor([colorname|colortriplet])
Row/Column Level Methods
- addRow("cell 1 content" [, "cell 2 conent", ...])
-
Adds a row to the bottom of the table. Assumes if you pass more values than there are columns that you want to increase the number of columns.
- addCol("cell 1 content" [, "cell 2 conent", ...])
-
Adds a column to the right end of the table. Assumes if you pass more values than there are rows that you want to increase the number of rows.
- setColAlign(col_num, [CENTER|RIGHT|LEFT])
- setColVAlign(col_num, [CENTER|TOP|BOTTOM])
- setRowAlign(row_num, [CENTER|RIGHT|LEFT])
- setRowVAlign(row_num, [CENTER|TOP|BOTTOM])
- setColNoWrap(col_num, [0|1])
- setRowBGColor(row_num, [colorname|colortriplet])
Cell Level Methods
- setCell(row_num, col_num, "content")
-
Sets the content of a table cell. This could be any string, even another table object via the getTable method
- setCellAlign(row_num, col_num, [CENTER|RIGHT|LEFT])
- setCellVAlign(row_num, col_num, [CENTER|TOP|BOTTOM])
- setCellWidth(row_num, col_num, [pixels])
- setCellHeight(row_num, col_num, [pixels])
- setCellNoWrap(row_num, col_num, [0|1])
- setCellBGColor(row_num, col_num, [colorname|colortriplet])
- setCellRowSpan(row_num, col_num, num_cells)
-
Causes the cell to overlap a number of cells to the right. If the overlap number is greater than number of cells to the right of the cell, a false value will be returned.
- setCellColSpan(row_num, col_num, num_cells)
-
Causes the cell to overlap a number of cells below it. If the overlap number is greater than number of cells below the cell, a false value will be returned.
- setCellSpan(upleft_row_num, up_left_col_num, lowright_row_num, lowrigt_col_num)
-
Joins the block of cells with the corners specified. If the values specified are greater than the number of rows or columns, a false value will be returned.
- getCell(row_num, col_num)
-
Returns the contents of the specified cell as a string.
Output Methods
- getTable
-
Returns a string containing the HTML representation of the table.
The same effect can also be achieved by using the object reference in a string scalar context.
For example...
This code snippet: $table = new HTML::Table(2, 2); print "<P>Start</P>"; print $table->getTable; print "<P>End</P>"; would produce the same output as: $table = new HTML::Table(2, 2); print "<P>Start</P>$table<P>End</P>";
-
Prints HTML representation of the table to STDOUT
CLASS VARIABLES
HISTORY
This module was originally created in 1997 by Stacy Lacy and whose last version was uploaded to CPAN in 1998. The module was adopted in July 2000 by Anthony Peacock in order to distribute a revised version. This adoption took place without Stacy Lacy's explicit consent as it proved impossible to contact them at the time. Although explicit consent was not obtained at the time, there was some evidence that Stacy Lacy was looking for somebody to adopt the module in 1998.
AUTHOR
Anthony Peacock, a.peacock@chime.ucl.ac.uk Stacy Lacy (Original author)
COPYRIGHT
Copyright (c) 1998-2000 Anthony Peacock, CHIME. Copyright (c) 1997 Stacy Lacy
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
perl(1), CGI(3)