Insert image with Laravel-Excel

Boring person picture Boring person · Jul 19, 2015 · Viewed 15k times · Source

I'm using this package to generate excel documents with Laravel: https://github.com/Maatwebsite/Laravel-Excel

However, documentation doesn't say anything about inserting images from files into my excel document. I'm pretty sure it's possible with native phpexcel itself, but how to do this through this package?

Some example code would be much appreciated..

Answer

randawahyup picture randawahyup · Jan 4, 2016

first you need declare Class use PHPExcel_Worksheet_Drawing;

and in controller :

$filename = 'File Name';
    
Excel::create($filename, function($excel){    
    $excel->sheet('sheet name', function($sheet){
        $objDrawing = new PHPExcel_Worksheet_Drawing;
        $objDrawing->setPath(public_path('img/headerKop.png')); //your image path
        $objDrawing->setCoordinates('A2');
        $objDrawing->setWorksheet($sheet);
    });
})->export('xls');