Home > Net >  <br> not working in Maatwebsite excel export
<br> not working in Maatwebsite excel export

Time:09-27

I use maatwebsite for to export report as excel format . I want to add break within a cell .But is not working.It shows the '
' as tag.

public function map($order): array
    {
        return [
            [
                $order->id,
                $this->getCourse($order),
            ],
        ];
    }

    public function headings(): array
    {
        return [
            'ORDER ID',
            'COURSE'
        ];
    }

public function getCourse($order){
        $course = '';
        $i=1;
        foreach($order->orderItems as $val2){
        if(!empty($val2->package->course->name)){
            $course.=$i.') ';
            $course.=$val2->package->course->name .' <br> ';                               
        }else{
            $course.='- <br> ';
        }
        }

        return $course;
    }

CodePudding user response:

Use PHP_EOL instead. <br> is not renderable in excel

or

You can use \n by setting wrap text to TRUE in settings:

Excel::create($file_name, function($excel) {           
    $excel->getDefaultStyle()
        ->getAlignment()
        ->applyFromArray(array(
            'horizontal'    => \PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
            'vertical'      => \PHPExcel_Style_Alignment::VERTICAL_TOP,
            'wrap'      => TRUE
        ));
})->download('xlsx');

Source

  • Related