Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert image with Laravel-Excel

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..

like image 240
Boring person Avatar asked Jul 19 '15 11:07

Boring person


People also ask

How can I upload a large Excel file to laravel?

When dealing with big files, it's better to import the data in big chunks. You can enable this with filter('chunk') ; To import it into chunks you can use chunk($size, $callback) instead of the normal get() . The first parameter is the size of the chunk. The second parameter is a closure which will return the results.

Is laravel excel free?

Laravel Excel is completely free (MIT) to use, however the package is licensed as Postcardware. This means that if it makes it to your production environment, we would very much appreciate receiving a postcard from your hometown.


2 Answers

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');
like image 143
randawahyup Avatar answered Sep 20 '22 02:09

randawahyup


For new version 3.1

Import

use Maatwebsite\Excel\Concerns\WithDrawings;

use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;

and

class InvoicesExport implements WithDrawings

public function drawings()
{
    $drawing = new Drawing();
    $drawing->setName('Logo');
    $drawing->setDescription('This is my logo');
    $drawing->setPath(public_path('/img/vir.png'));
    $drawing->setHeight(90);
    $drawing->setCoordinates('B3');

    return $drawing;
}
like image 43
Samuel Cruz Avatar answered Sep 20 '22 02:09

Samuel Cruz