Word-wrap issue in cell in excel file after export from laravel datatables

909 Views Asked by At

Hello Dear,

I have query in my code, I am using yajra/laravel-datatables package ("yajra/laravel-datatables-oracle": "^9.0"). I want to export Laravel data-table same as table view. Means I can't export data-table with word-wrap text. Please visit below screenshot so you can sure about it.

Screenshot 1: This one is the view of my laravel data-table. That I need same as during export in excel file.

https://prnt.sc/vgji9s

Screenshot 2: This one is my current view of excel file.

https://prnt.sc/vgj83k

https://prnt.sc/vgj8nn

Please check it and give me a suggestion for it. Thanks in advance.

1

There are 1 best solutions below

7
On

You need to use column formatting. You should use ShouldAutoSize.

Read More about column formatting

You can use ShouldAutoSize in your export class. sample code of export class is as below:

<?php

namespace App\Exports;

use App\Models\Member;
use Maatwebsite\Excel\Concerns\FromCollection;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;

class MemberTwoExport implements FromView, ShouldAutoSize
{
/**
* @return \Illuminate\Support\Collection
*/


   public function view() : View
   {
       $member = Member::get();
       return view('Your blade file')->with('member', $member);
   }
}