user1483636
user1483636

Reputation:

How to set text direction in cells in PHPExcel?

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?

Upvotes: 1

Views: 1589

Answers (1)

Mark Baker
Mark Baker

Reputation: 212402

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);

Upvotes: 4

Related Questions