Reputation: 2160
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?
Upvotes: 2
Views: 17511
Reputation: 904
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);
Upvotes: 1
Reputation: 1
textWrap not working bacause you set ROW height, ex:
$worksheet -> setRow($numRow, 17);
Remove this line, and height of row will be calculating automaticly.
Upvotes: 0
Reputation: 91
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
Upvotes: 7
Reputation: 2160
Ok figured it out. I was trying to do it like this:
$format_caption =& $workbook->addFormat(array('size' => 11, 'fontFamily' => 'Calibri', 'numformat' => '@', 'bold' => 1, 'left' => 1, 'top' => 1, 'bottom' => 1, 'right' => 1, 'vAlign' => 'vcenter', 'align' => 'center', 'fgcolor' => 50, 'textWrap' => 1));
But setting 'textWrap' => 1
didn't work.
So I changed it a bit:
$format_caption =& $workbook->addFormat(array('size' => 11, 'fontFamily' => 'Calibri', 'numformat' => '@', 'bold' => 1, 'left' => 1, 'top' => 1, 'bottom' => 1, 'right' => 1, 'vAlign' => 'vcenter', 'align' => 'center', 'fgcolor' => 50));
$format_caption -> setTextWrap();
And that solved my issue.
Upvotes: 0