Php Excel set whole column data alignment not working

pankil thakkar picture pankil thakkar · Nov 9, 2012 · Viewed 66.1k times · Source

I am Using this code For E column data set to right align but Its not showing me effect

$objPHPExcel->getActiveSheet()
    ->getStyle('E')
    ->getAlignment()
    ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

instead of 'E' if i write E6 then it display E6 cell data to right.

$objPHPExcel->getActiveSheet()
    ->getStyle('E6')
    ->getAlignment()
    ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

Answer

Mark Baker picture Mark Baker · Nov 9, 2012

You're correct: row and column styles aren't supported by PHPExcel.

Cell styling is, but you can also set style by a range of cells:

$objPHPExcel->getActiveSheet()
    ->getStyle('E1:E256')
    ->getAlignment()
    ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);