[英]How to choose location to save file excel with PHPExcel
使用 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);
請幫我。 太感謝了。
將文件名更改為所需的路徑,即,
$name = '/path/to/folder/xyz.xlsx';
$objWriter->save($name);
這個對我有用...
$objWriter->save($filename);
.... 將$filename
的值更改為要保存文件的位置的文件路徑,例如
$filename = '/path/to/folder/test.xlsx';
$objWriter->save($filename);
如果您在 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 ");
使用 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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.