How to vertically align text using PHPExcel
Programmatic
You can programmatically set the vertical alignment of a cell like this:
$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col, $row)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
This code will vertically center the text in a cell. You can replace VERTICAL_CENTER with VERTICAL_TOP (to top-align), VERTICAL_BOTTOM (to bottom-align), or VERTICAL_JUSTIFY.
Note that getStyleByColumnAndRow($col, $row) uses the numeric column/row equivalent. I use this because all of my PHPExcel code increments with numbers rather than alpha characters. If you are using the standard nomenclature, you can just use getStyle(’A2′) instead of getStyleByColumnAndRow.
Style arrays
If you are using style arrays, you can add this attribute:
'alignment' => array('vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER )
Style arrays are handy because they can be defined in one place and re-used throughout your PHPExcel document.
And of course, you apply your style array like this:
$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col, $row)->applyFromArray(array('alignment' => array('vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER )));


















