我在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
答案 0 :(得分:0)
使用成功解决了这个问题
\PhpOffice\PhpSpreadsheet\Shared\File::setUseUploadTempDirectory(true);
现在一切都很顺利。
问题是PHP进程无法写入phpSpreadSheet使用的tmp目录。更改了tmp目录以上载tmp目录,现在问题已解决。