Row style

We can change some properties of tables rows, such as the height and the background. This can be done using the class RowStyle.

To create a row style, we call the constructor with the name of the style.

$rowStyle1 = new RowStyle('rowstyle1');

To apply a row style to a row, we call the method setRowStyle of the class Table, and we pass the index of the row and a RowStyle object. The rows index starts from 0.

$table->setRowStyle(0, $rowStyle1);

Height

To change the height, we use the method setHeight($height).

$rowStyle1->setHeight('3cm');

Background color

To set the bakground color, we use the method setBgColor($color).

$rowStyle1->setBgColor('#ff0000');

Background image

To set the bakground image, we use the method setBgImage($image, $repeat, $position).

    <
  • $image: path of the image.
  • $repeat (optional): whether the image should be repeated or not, or stretched. default value is repeated. This can be set using one of these values StyleConstants::(REPEAT, NO_REPEAT, STRETCH)
  • $position (optional): position of the image StyleConstants::(LEFT|RIGHT|CENTER|TOP|BOTTOM)
$rowStyle1->setBgimage('image2.png', StyleConstants::STRETCH);

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

$rowStyle1 = new RowStyle('rowstyle1');

$table->setRowStyle(0, $rowStyle1);
$rowStyle1->setHeight('3cm');
$rowStyle1->setBgimage('image.jpeg', StyleConstants::STRETCH);

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