1 year ago

#279313

test-img

Neeraj

Laravel Maatwebsite Auto Row Height

While exporting data into excel, I have to assign multiple line breaks for column B, C and D. I have used PHP_EOL in my code for line break.

After export, i can see all data in a single line but i want every row to show data shown below under "Expected Output".

public function collection()
{
    $index = 0;
    $data = collect($this->data)->map(function($lead, $Index) use($index) {
        $index = $index + 1;
        return collect([
            ($Index+1),
            $lead->lead_date ? date('d/m/Y h:i a', strtotime($lead->lead_date)) : "",
            $lead->organisation.PHP_EOL.$lead->industry_type,
            $lead->address.PHP_EOL.$lead->city.PHP_EOL.$lead->state,
            $lead->first_name.PHP_EOL.$lead->last_name.PHP_EOL.$lead->designation_name,
            $lead->product_type,
            $lead->account_type,
            $lead->created_time,
            $lead->contact_number.PHP_EOL. $lead->email_id,
            $lead->sales_person,
        ]);
    });
    return collect($data);
}

public function registerEvents(): array
{
    return [

        AfterSheet::class    => function(AfterSheet $event) {
            $columns = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T"];
            foreach ($columns as $column) {
                $event->sheet->getColumnDimension($column)->setAutoSize(true);
            }

        }
    ];
}

Current Output enter image description here

Expected Output enter image description here

php

laravel

formatting

maatwebsite-excel

row-height

0 Answers

Your Answer

Accepted video resources