1

I have to write texts in cells that are combinations of RTL and LTR languages inline and the prior language is the RTL one. So I need the text in xls file generated by PHPExcel to be RTL by default. What can I do?

  • 2
    Possible duplicate of [Set direction sheet in PHPExcel](http://stackoverflow.com/questions/15154903/set-direction-sheet-in-phpexcel) – u_mulder Jun 28 '16 at 06:39
  • Thank you, but that question is about sheet direction not text direction. –  Jun 28 '16 at 06:41

1 Answers1

4

To set direction for the entire worksheet, you can use:

$objPHPExcel->getActiveSheet()
    ->setRightToLeft(true);

For an individual cell (or range of cells) you can try:

// Set the character order as RTL
$objPHPExcel->getActiveSheet()
    ->getStyle('A1')
    ->getAlignment()
    ->setReadorder(PHPExcel_Style_Alignment::READORDER_RTL);
// Set cell alignment to the right
$objPHPExcel->getActiveSheet()
    ->getStyle('A1')
    ->getAlignment()
    ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
Mark Baker
  • 209,507
  • 32
  • 346
  • 385