PHP Excel - Set cell or Column Direction (RTL)

2019-03-03 16:03发布

问题:

I'm looking for a way to set the "Direction" of a cell in Excel from PHP Excel. I've gone over any documentation i could find and found only the option to set the direction for a sheet, however, it does not affect the cell direction but rather, only the layout of the page from LTR to RTL.

I need to be able to set a specific Cell or better yet, a column, to be RTL.

Please note that I'm not talking about the alignment of the cell, I'm talking about the text direction.

this is not a duplication of Set direction sheet in PHPExcel

thanks

回答1:

This can only be set at the Worksheet level using

// right-to-left worksheet
$objPHPExcel->getActiveSheet()
    ->setRightToLeft(true);

not for individual cells, ranges of cells, columns or rows



回答2:

Got the answer to this by a dear friend (Bastien Koert) :

This takes care of the RTL for a single Cell.
    $objPHPExcel->getActiveSheet()->getStyle('J' , $i)->getAlignment()->setReadorder(PHPExcel_Style_Alignment::READORDER_RTL);

This takes care of the right alignment needed with Hebrew
    $objPHPExcel->getActiveSheet()->getStyle('J' , $i)->getAlignment()-  >setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);