i use phpspreadsheet package in laravel to generate excel file, it works like charm so far. Here is my issue, i wanted the excel to be saved in certain directory instead of popup download, i gave a path in order to save in certain directory and it works fine.
$writer->save($full_path.$filename);
but the popup download still comes up, below is the code to generate excel:
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Style\Aligment;
use SpreadsheetReader;
public function export()
{
$spreadsheet = new Spreadsheet();
// Add some data
$sheet = $spreadsheet->getActiveSheet();
$sheet->getStyle('C')->getAlignment()->setHorizontal('left');
$sheet->getColumnDimension('A')->setWidth(20);
$sheet->getColumnDimension('B')->setWidth(20);
$sheet->setCellValue('A1', 'Name');
$sheet->setCellValue('B1', 'Service');
$users = User::get();
if(count($users) > 0) {
$rowCount = 2;
foreach($users as $user) {
$sheet->setCellValue('A' . $rowCount, $user->name);
$sheet->setCellValue('B' . $rowCount, $user->service);
$rowCount++;
}
}
$spreadsheet->getActiveSheet()->setTitle('User Services');
$spreadsheet->setActiveSheetIndex(0);
$filename = "file-".date('YmdHis').".xlsx";
$full_path = public_path().'\rpts\\';
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
//$writer->save('php://output');
$writer->save($full_path.$filename);
exit;
}
Is it anyway to forbid the save as
popup during the export process?
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2RnRz1K
via IFTTT
Aucun commentaire:
Enregistrer un commentaire