Tables

To create a simple table, we follow these steps:

Create a Table object, and give it a name:

$table = new Table('table1');

Specify the number of columns:

$table->createColumns(3);

Add a header to the table. The header is simply an array containing the titles of each column:

$table->addHeader(array('Col 1', 'Col 2', 'Col 3'));

This step can be ommited if you don't need a header.

Lastly, we add the rows to the tables. The rows are contained in an array, each element of the array represents a row, and is also an array.

$rows = array(array('1-1', '1-2', '1-3'), array('2-1', '2-2', '2-3'));
$table->addRows($rows);

include 'phpodt-0.3/phpodt.php';

$odt = ODT::getInstance();

$table = new Table('table1');
$table->createColumns(3);
$table->addHeader(array('Col 1', 'Col 2', 'Col 3'));
$rows = array(array('1-1', '1-2', '1-3'), array('2-1', '2-2', '2-3'));
$table->addRows($rows);

$odt->output('test_table.odt');