I have generated a valid spreadsheet and I am able to save it with the documented save method :
$writer = new Xlsx($spreadsheet);
$writer->save('file.xlsx');
But how can I use the storages disks provided by Laravel ? Can I get the content of the file before writing it to the disk ?
I figured out by myself. Since there is no $writer->getContent() method here is my workaround :
Here is my code :
$writer = new Xlsx($spreadsheet);
ob_start();
$writer->save('php://output');
$content = ob_get_contents();
ob_end_clean();
Storage::disk('local')->put("myfile.xlsx", $content);
Storage::disk('myftp')->put("myfile.xlsx", $content);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With