芝麻web文件管理V1.00
编辑当前文件:/home/forge/stage.sksb.smartcon-survey.com/app/Helpers/ExcelHelper.php
spreadsheet = new Spreadsheet; $this->activeSheetIndex = $this->spreadsheet->getActiveSheetIndex(); } /** * @throws \PhpOffice\PhpSpreadsheet\Exception */ public function addSheet(string $title, array $content): void { if ($this->activeSheetIndex > 0) { $this->spreadsheet->createSheet(); $this->spreadsheet->setActiveSheetIndex($this->activeSheetIndex); } $this->spreadsheet->getActiveSheet()->setTitle($title); $this->spreadsheet->getActiveSheet()->fromArray($content); $this->activeSheetIndex++; } /** * @throws \PhpOffice\PhpSpreadsheet\Exception */ public function addSheets(array $data): void { foreach ($data as $name => $sheet) { $this->addSheet($name, $sheet); } } public function download(string $fileName): StreamedResponse { return response()->streamDownload(function () use ($fileName) { $fileType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; ob_clean(); header('Content-Description: File Transfer'); header('Content-Type: '.$fileType); header('Content-disposition: attachment; filename='.$fileName.' Daten.xlsx'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); $writer = new Xlsx($this->spreadsheet); $writer->save('php://output'); }, $fileName.'.xlsx'); } }