4

我正在使用maatwebsite (laravel)将客户数据写入现有的 excel 文件并从数据库动态导出,我的代码工作正常。

我正在关注以下链接:

maat网站

现在我想要下载的excel文件应该保存在任何目录中/uploads/customers/text.xlsx

编辑:查看我的代码:

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());
}

我怎样才能使用 maatwebsite 功能来做到这一点,我没有得到任何功能来做到这一点?

4

2 回答 2

9

在 Laravel Excel (Maatwebsite Excel 3) 中,您在外观 ( ) 上使用store方法:ExcelMaatwebsite\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

于 2019-12-27T19:22:34.163 回答
1

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

于 2018-04-25T11:09:25.443 回答