$file_name = time().'.xlsx';
$excel = new \Vtiful\Kernel\Excel(['path' => public_path().'/excel']);
$fileObject = $excel->constMemory($file_name);
$handle = $fileObject->getHandle();
$fileObject->data($excel_data);
$filePath = $fileObject->output();
header("content-Type: application/vnd.openxmlformats-officedocument,spreadsheetml.sheet");
header('Content-Disposition: attachment;filename="'.$file_name.'"');
header('content-Length:'.filesize($filePath));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Cache-Control: max-age=0');
header('Pragma: public');
if(ob_get_contents()){
ob_clean();
}
if(copy($filePath, 'php://output')=== false){
throw new Exception($filePath ."地址出问题了");
}else{
return $this->json(200, '', ['list'=>$filePath, ]);
}
flush();
以上显示二进制流打印在启动界面,怎么在浏览器中返回给前端呢?求专家指点。
学习,感谢。根据教程实现后端返回文件二进制格式,但前端提示跨域问题,后端这里如何解决?
直接下载文件应该不会吧,除非你在浏览器里面解析excel显示
https://www.workerman.net/doc/webman/response.html#%E8%8E%B7%E5%8F%96%E8%BE%93%E5%87%BA
文档有例子,获取输出,然后返回
学习,感谢。根据教程实现后端返回文件二进制格式,但前端提示跨域问题,后端这里如何解决?
有一个跨域中间件直接用上即可