使用phpexcel保存到临时文件
我必须将excel保存在临时文件中,但我不知道如何保存 最初我是这样保存excel文件的使用phpexcel保存到临时文件,php,excel,phpexcel,Php,Excel,Phpexcel,我必须将excel保存在临时文件中,但我不知道如何保存 最初我是这样保存excel文件的 header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="Autolarte.xlsx"'); header('Cache-Control: max-age=0'); header('C
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Autolarte.xlsx"');
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header ('Cache-Control: cache, must-revalidate');
header ('Pragma: public');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
现在我想创建一个包含excel文件内容的临时文件
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Autolarte.xlsx"');
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header ('Cache-Control: cache, must-revalidate');
header ('Pragma: public');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
我有这个例子,但因为我不知道excel的内容是什么变量,所以在我的例子中没有实现
$temp = tmpfile();
fwrite($temp, "writing in the temporary file");
fseek($temp, 0);
echo fread($temp, 1024);
fclose($temp);
现在我需要的是我的临时文件,我想把临时文件的路径和名称放在addfile中,以便将excel添加到zip中
$zipname = 'file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
$zip->addFile('/path/to/index.txt', 'newname.txt');
$zip->addFromString("testfilephp.txt", "#1 This is a test string added as testfilephp.txt.\n");
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
exit;
save()
命令保存到文件,但您使用的是php://output
作为文件名立即获取直接输出。只要改变它
$tempfile = tempnam();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save($tempfile);
不要忘记在删除文件之后使用
unlink()
警告:strtolower()希望参数1是字符串,在/home1/autolart/public\u html/app/webroot/descargas/PHPExcel-1.8/Classes/PHPExcel/Writer/Excel2007.php中给出的资源在第189行
警告:file\u exists()希望参数1是有效路径,第228行的/home1/autolart/public_html/app/webroot/descargas/PHPExcel-1.8/Classes/PHPExcel/Writer/Excel2007.php中提供的资源,第232行的/home1/autolart/public_html/app/webroot/descargas/PHPExcel-1.8/Classes/PHPExcel/Writer/Excel2007.php中提供的资源,第233行的/home1/autolart/public_html/app/webroot/descargas/PHPExcel-1.8/Classes/PHPExcel/Writer/Excel2007.php中给出的资源消息来自库,当函数被误用时会显示此消息