maatwebsite/excel使用:导出——在磁盘上存储导出
在磁盘上存储导出
存储原始内容
要接收导出文件的原始内容,可以使用 raw()
方法:
$contents = Excel::raw(new InvoicesExport, \Maatwebsite\Excel\Excel::XLSX);
默认磁盘
public function storeExcel()
{
// Store on default disk
Excel::store(new InvoicesExport(2018), 'invoices.xlsx');
}
自定义磁盘
public function storeExcel()
{
// Store on a different disk (e.g. s3)
Excel::store(new InvoicesExport(2018), 'invoices.xlsx', 's3');
// Store on a different disk with a defined writer type.
Excel::store(new InvoicesExport(2018), 'invoices.xlsx', 's3', Excel::XLSX);
}
磁盘选项
如果要将一些选项传递给磁盘,将它们作为第五个参数传递给 Excel::store()
。
public function storeExcel()
{
Excel::store(new InvoicesExport(2018), 'invoices.xlsx', 's3', null, [
'visibility' => 'private',
]);
}
Laravel 有一个私有文件的快捷方式:
public function storeExcel()
{
Excel::store(new InvoicesExport(2018), 'invoices.xlsx', 's3', null, 'private');
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: