使用maatwebsite导出并保存excel在目录中

时间:2017-04-17 07:19:58

标签: php laravel maatwebsite-excel

我正在使用/uploads/customers/text.xlsx将客户数据写入现有的excel文件并从数据库中动态导出,我的代码运行正常。

我关注以下链接:

maatwebsite

现在我想要下载应该保存在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()); }

之类的任何目录中的excel文件

编辑:查看我的代码:

User

如何使用maatwebsite功能执行此操作,我没有获得执行此功能的任何功能?

3 个答案:

答案 0 :(得分:0)

出口意义下载; 检查下载目录中的文件

答案 1 :(得分:0)

您可以使用->save功能将生成的文件保存到服务器上的文件夹中。 有关详细信息,请查看https://laravel-excel.maatwebsite.nl/docs/2.1/export/store#docs

答案 2 :(得分:0)

在Laravel Excel(Maatwebsite Excel 3)中,您在store门面(Excel)上使用Maatwebsite\Excel\Facades\Excel方法:

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

第三个参数是在config/filesystems.php中定义的文件系统(可选)。如果要存储这些Excel文件的位置不在默认的localpublic文件系统之外,则可以将其添加到配置文件中:

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

然后使用设置为该新文件系统的thrid参数保存Excel文件:

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

在此处了解更多信息:https://docs.laravel-excel.com/3.1/exports/store.html