
いつもお世話になっております。
ExcelをPDFに変換してそのPDFをダウンロードする処理を書いています。
ダウンロード後にviewをを再表示したいのですが、ダウンロードの
処理の後が何も起きません。
調べても出てこなかったので質問させていただきます。
php
1public function comp(Request $request){ 2 3 $id = $request->input('id'); 4 5 //func_excelでデータを取得してきています。 6 $result = $this->func_excel($id); 7 8 $this->makepdf($result); 9 10 //$a = "aa"; 11 //dd($a); 12 13 return view('sanple::hoge_index'); 14 } 15 16 17private function makepdf($result){ 18 19 $LIBRE_PATH = 'C:\Users***\Downloads\LibreOfficePortablePrevious\App\libreoffice\program\soffice.exe'; 20 21 //テンプレート読み込み 22 $inputFileName = 'sample.xlsx'; 23 $data= json_decode( json_encode($result), true); 24 25 //spreadsheetにテンプレファイル読み込み 26 $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName); 27 28 $sheet = $spreadsheet->getActiveSheet(); 29 30 //Excelに書き出し 31 $sheet->fromArray($data, NULL, 'A2'); 32 33 //Excel保存 34 $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet); 35 $writer->save('sample2.xlsx'); 36 37 38 $path = base_path('public'); 39 40 //Excel→PDFに変換 41 $command = "$LIBRE_PATH --headless --convert-to pdf:writer_pdf_Export $path/sample2.xlsx"; 42 passthru($command); 43 44 // ファイルのパス 45 $filepath = 'sample2.pdf'; 46 47 // リネーム後のファイル名 48 $filename = 'result.pdf'; 49 50 // ファイルタイプにPDFを指定 51 header('Content-Type: application/pdf'); 52 53 // ファイルサイズを取得し、ダウンロードの進捗を表示 54 header('Content-Length: '.filesize($filepath)); 55 56 // ファイルのダウンロード、リネームを指示 57 header('Content-Disposition: attachment; filename="'.$filename.'"'); 58 59 // ファイルを読み込みダウンロードを実行 60 readfile($filepath); 61 }
回答1件
あなたの回答
tips
プレビュー