Ad

How To Work With PHPWord And LaravelExcel In Laravel 5.1 Framework?

- 1 answer

m new to Laravel ...I need to generate document form Mysql database im using Larvel framework i install PHPWord, maatwebsite/excel and through composer i used this document Excel

and i install PHPWord using this [PHPWord][2]

[2]: http://phpword.readthedocs.org/en/latest/installing.html but i don't know next step how to use ??? and where to use ??? controller or Model??? if anyone know how to use this packages in laravel help me

Ad

Answer

For PHPword:

// you can import it or put it on variable like this
$phpWord = new \PhpOffice\PhpWord\PhpWord();

//Now you can access PhpWord function

// Adding an empty Section to the document...
$section = $phpWord->addSection();
// Adding Text element to the Section having font styled by default...
$section->addText(
    htmlspecialchars(
        '"Learn from yesterday, live for today, hope for tomorrow. '
            . 'The important thing is not to stop questioning." '
            . '(Albert Einstein)'
    )
);

For: Maatwebsite/Laravel-Excel

add the ServiceProvider to the providers array in config/app.php

'Maatwebsite\Excel\ExcelServiceProvider'

Add to your facade:

'Excel' => 'Maatwebsite\Excel\Facades\Excel'

example for excel:

Excel::create('Laravel Excel', function($excel) {

    $excel->sheet('Excel sheet', function($sheet) {

          $sheet->setOrientation('landscape');

    });

})->export('xls');

Other function refer to this:

  1. PhpWord
  2. Maatwebsite/Laravel-Excel
Ad
source: stackoverflow.com
Ad