Yesterday, i was working on my php laravel 5 application and i installed PHPOffice/PHPWord package and trying to use it in controller. But when i run my project and see i got following error :
"Illegal string offset 'w:compatSetting'"
Even i generate docx file, i thought why it's come event file is created successfully. I try to understand deeply but i didn't get well. However i found temporary solution using try catch. So you can solve by following way:
Fixed:
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addText("test");
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
try {
$objWriter->save(storage_path('helloWorld.docx'));
} catch (Exception $e) {
}
return response()->download(storage_path('helloWorld.docx'));
I hope you found your best solution
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example