I am trying to export user details to .docx file. The file successfully exported but, it's giving the object. Phpword format is not working. How to write code to export the dynamic values properly, would someone help me, please?
In AdminController.php -
public function exportUserToDoc(Request $request, $id)
{
$wordTest = new \PhpOffice\PhpWord\PhpWord();
$newSection = $wordTest->addSection();
$desc1 = User::find($id);
$newSection->addText($desc1, array('name' => $desc1->name, 'email' => $desc1->email, 'phone' => $desc1->phone, 'address' => $desc1->address));
$objectWriter = \PhpOffice\PhpWord\IOFactory::createWriter($wordTest, 'Word2007');
try{
$objectWriter->save(storage_path('TestWordFile.docx'));
}catch (Exception $e){
}
return response()->download(storage_path('TestWordFile.docx'));
}
After downloading the doc file the result is like -
{"id":1,"name":"Emdadul Huq Shikder","email":"emdadulshikder@gmail.com","phone":"+8801674338411","address":"59\/6\/1 West Razabazar, Dhaka","status":0,"created_at":"2018-03-13 05:18:32","updated_at":"2018-03-13 05:35:51"}
I want to get the result as well formatted such as with header 'Name', 'Email' etc.