July 18 2017

Yii2 set wraptext on moonlandsoft phpexcel

On phpexcel you are allow to set “setWrapText(true)” property. but on Yii2 plugin moonlandsoft phpexcel it don’t have this property.

To set this property. you need to add extra code on the plugin.
Open Excel.php file. and then scroll to line 387 add the code below.
if (isset($column['wraptext']) &&  $column['wraptext'] == true) {
	$activeSheet->getStyle($col.$row)->getAlignment()->setWrapText(true);
}

Example to use the WrapText property
\moonland\phpexcel\Excel::export([
	'models' => $modelData, 
	'setFirstRecordAsKeys' => true,
	'columns' => [
		[
			'header' => 'Column',
			'format' => 'text',
			'wraptext' => true,
			'value' => function($model) {
				return $model[0];
			},
		],
	]
]);

You just need add ‘wraptext’ => true to the column only.

Make a Comment

*

code