Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export and save excel in a directory using maatwebsite

I am using maatwebsite (laravel) to write customer data into existing excel file and export dynamically from database and my code is working fine.

I am following below link:

maatwebsite

Now I want as excel file will download that should be save in any directory like /uploads/customers/text.xlsx

Edit: See my code:

try {
    Excel::selectSheetsByIndex(1)->load('/public/uploads/new.xlsx', function($reader) {
    $reader->sheet('sheetname',function($sheet)
    {  
      $sheet->appendRow('test','test', 'test');
    });
 }, 'UTF-8')->export('xlsx');
} catch (Exception $ex) {
    echo $ex->getMessage().$ex->getLine();
    return response(Helpers::makeDefaultErrorAjaxResponse());
}

How can I do that using the maatwebsite function, I am not getting any function for doing this?

like image 442
Raghbendra Nayak Avatar asked Dec 23 '22 18:12

Raghbendra Nayak


2 Answers

In Laravel Excel (Maatwebsite Excel 3) you use store method on Excel facade (Maatwebsite\Excel\Facades\Excel):

Excel::store(new YourExport(), 'customers/fileName.xlsx', 'local');

The third parameter is a filesystem defined in config/filesystems.php (it's optional). If the location where you want to store those Excel files is outside the default local and public filesystems, you can add it to the config file:

'customer_uploads' => [
    'driver' => 'local',
    'root' => '/uploads/customers/',
],

And then save your Excel files with the thrid parameter set to that new filesystem:

Excel::store(new YourExport(), 'fileName.xlsx', 'customer_uploads');

Read more here: https://docs.laravel-excel.com/3.1/exports/store.html

like image 169
Mateusz Avatar answered Jan 19 '23 00:01

Mateusz


You can use ->save function to save the generated file to a folder on server. For more details look at https://laravel-excel.maatwebsite.nl/docs/2.1/export/store#docs

like image 20
karmendra Avatar answered Jan 18 '23 23:01

karmendra