kernel::single('ome_func')->getTmpDir() // xlsx文件保存路径 ]; $excel = new \Vtiful\Kernel\Excel($config); $fileTmpName = time().uniqid().rand(10,99).'.xlsx'; // fileName 会自动创建一个工作表,你可以自定义该工作表名称,工作表名称为可选参数 $filePath = $excel->fileName($fileTmpName, 'sheet1'); if($title) { $filePath = $filePath->header($title); } if($data) { $filePath = $filePath->data($data); } $filePath = $filePath->output(); header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); header('Content-Disposition: attachment;filename="' . $fileName . '-' . date('Ymd') . '.xlsx"'); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate'); header('Cache-Control: max-age=0'); header('Pragma: public'); header('Content-Length: ' . filesize($filePath)); if (!empty($path)) { $savePath = $path; } else { $savePath = 'php://output'; } if (copy($filePath, $savePath) === false) { // Throw exception } // Delete temporary file @unlink($filePath); return true; } catch (\Exception $e) { throw $e; } return false; } }