Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Excel Writer Wrap text

I'm using this plugin, I know it's not the best, but I don't have time to rewrite all these scripts. I need to know how enable text wrap. The incomplete documentation on the website doesn't help at all.

I have tried using 1 and 'wrap' as the parameter in the array, but no luck.

Has anyone gotten this to work?

like image 564
Bird87 ZA Avatar asked Mar 17 '26 00:03

Bird87 ZA


2 Answers

If You want to use construction addFormat(), name of wrapText property have to be 'wrap'.

You wrote: 'textWrap' => 1

you should: 'wrap' => true or 'wrap' => 1

for example:

$style = array(
    'alignment' => array(
        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
        'wrap' => true
    )
);
$objPHPExcel->getActiveSheet()->getStyle('A1')->applyFromArray($style);

the result for cell A1 is central alignment whith text wraping

like image 116
kudis Avatar answered Mar 18 '26 13:03

kudis


This code worked for me in PhpSpreadsheet

 $styleArray = [
            'borders'   => [
                'allBorders' => [
                    'borderStyle' => Border::BORDER_THIN,
                ],
            ],
            'alignment' => [
                'wrapText' => true,
            ],
        ];

 $sheet->setCellValue('A1', 'product_name')->getStyle('A1')->applyFromArray($styleArray);
like image 36
Akbarali Avatar answered Mar 18 '26 14:03

Akbarali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!