我在 Laravel PHP 框架中使用 PHPOffice/SpreadSheet。我的电脑操作系统是 macOS。
在生成 excel 文件时,我收到此错误
ZipArchive::close(): Failure to create temporary file: No such file or directory
我的完整代码在这里
use Illuminate\Http\Request;
use PhpOffice\PhpSpreadsheet\IOFactory;use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
class SpreadSheetController extends Controller
{
public function examMarksEntrySheet(Request $request)
{
$reader = new Xlsx();
$spreadSheet = $reader->load($inputFileName);
$spreadSheet->setActiveSheetIndex(0);
$activeSheet = $spreadSheet->getActiveSheet();
// loaded excel file is edited here (hidde)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $fileName . '.xlsx"');
header('Cache-Control: max-age=0');
$writer = IOFactory::createWriter($spreadSheet, 'Xlsx');
$writer->save('php://output');
}
}
Laravel 版本:5.5
PHP 版本:7.1.7
PHPOffice/PHPSpreadSheet 版本:1.2
macOS 版本:10.13.3