使用PHPExcel创建excel文件时遇到问题。我想选择保存文件excel的位置,但我不知道怎么做。
$model = new User();
$labels = $model->attributeNames();
$data = $model->findAll();
$objPHPExcel = Yii::app()->excel;
........
$filename = 'text.xlsx';
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save($filename);
请帮帮我。非常感谢你。
答案 0 :(得分:9)
将文件名更改为所需路径,即
$name = '/path/to/folder/xyz.xlsx';
$objWriter->save($name);
它对我有用......
答案 1 :(得分:2)
如果您在php文件中包含以下标题。您的用户将有一个下载选项弹出窗口:
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary ");
答案 2 :(得分:0)
使用PHPExcel下载EXCEL:
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
对于使用Excel5 Writer创建的.xls文件:
header('Content-Type: application/vnd.ms-excel'); //mime type
或
对于使用Excel2007 Writer创建的.xlsx文件:
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //mime type
header('Content-Disposition: attachment;filename="you-file-name.xlsx"'); //tell browser what's the file name
header('Cache-Control: max-age=0'); //no cache
ob_end_clean();
$objWriter->save('php://output'`enter code here`);
exit();