How to set vertical text on PHPExcel

How can I set vertical align to the text on PHPExcel

I tried with

$phpExcelObject->getActiveSheet()->getStyle('B2:B5')->getAlignment()->setReadorder(
            PHPExcel_Style_Alignment::READORDER_RTL
        );

But it didn't work.

I actually have:

THE TEXT

But I want

T
H
E

T
E
X
T

Like the image.

Vertical text

Upvotes: 0

Views: 1849

Answers (2)

Yudha Wibowo
Yudha Wibowo

Reputation: 11

I See what your problem is,

I have solution for you , you still using getAlignment()->setWrapText(true); on your code, but you can add variable that fill is "\n" for every value you want it.

For Example :

 $n= "\n";

 $objPHPExcel->getActiveSheet()->setCellValue('A','T'.$n.'E'.$n.'S'.$n.'T');

 $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setWrapText(true);

result's as bellow:

T
E
S
T

Hope this answer can help you.

Upvotes: 1

Mark Baker
Mark Baker

Reputation: 212402

It's not vertical alignment that you want to look at: vertical alignment is whether the content should be at the top/centre/bottom of a cell; nor RTL, which is Right-to-Left. You could perhaps look at text rotation, but that rotates the orientation of the text.

You'll always need to set the row height to automatic and enable wrapping.

$objPHPExcel->getActiveSheet()
    ->getRowDimension(12)
    ->setRowHeight(-1);
$objPHPExcel->getActiveSheet()
    ->getStyle('A1')
    ->getAlignment()->setWrapText(true);

so that it will expand to the actual size of your text.

Then an option would be to add a new line character after every character in your string before setting the cell value:

$value = "THE TEXT";
$objPHPExcel->getActiveSheet()
    ->setCellValue('A1', implode("\n", str_split($value)));

Upvotes: 1

Related Questions