If we want to change the style of specific cell, we can use the class CellStyle
for that purpose.
CellStyle
objects are created automatically when we create the rows. So we can get them by calling the method getCellStyle($column, $row)
.
$cellStyle1 = $table->getCellStyle(0,0); //get the cell in the first column of the first row
You can set the vertical alignement to one of these values: StyleConstants::(TOP|MIDDLE|BOTTOM|AUTO) using the method setVerticalAlign($vAlign)
.
$cellStyle1->setVerticalAlign(StyleConstants::MIDDLE);
Just like RowStyle
, we use setBgColor
and setBgImage
to change the background of a cell. Everything that we said about RowStyle
apply also here.
$cellStyle1->setBgColor('#0000ff'); $cellStyle1->setBgImage('image.png', StyleConstants::NO_REPEAT, StyleConstants::CENTER);
You can add a border to a cell using the method setBorder
. You can call this method without arguments, which will add a black border, or ou can pass the color you want.
$cellStyle1->setBorder('#00ff00');
You add set a padding to the cell using setPadding
. You can also add a padding to a side of the cell only using one of the following: setTopPadding
, setBottomPadding
, setRightPadding
, setLeftPadding
.
$cellStyle1->setPadding('0.2cm');