问题
i have managed to create and save an excel file:
// Rename the file
$fileName = URL . "MODEL/case" . $caseNO . ".xlsx";
// Write the file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $fileType);
$objWriter->save($fileName);
I would like now PHPExcel run Excel automatically, open the file created and maximize it. Is it possible? Will this work even if Excel is already running?
Thank you for your help,
Donato
回答1:
As per my above comment, you can only force to have a download option. For this you can set headers in this way -
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Disposition: attachment;filename=\"filename.xlsx\"");
header("Cache-Control: max-age=0");
Reference - PHP Excel Reader
For more options you can also check the cheat sheet - Cheat Sheet
Although the best way to read here - Codeplex
EDIT
Do something like this -
$excel = new PHPExcel();
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="your_name.xls"');
header('Cache-Control: max-age=0');
// Do your stuff here
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
// This line will force the file to download
$writer->save('php://output');
回答2:
PHPExcel can't run MS Excel on the client.... but you can download a file directly to the browser which will offer the client the options of saving it to disk or opening it directly in MS Excel (if they have MS Excel installed) by sending the appropriate http headers, and "saving" the file to php://output.
Of course, if the client doesn't have MS Excel installed, then opening in MS Excel isn't an option; although it will still prompt for save.
The 01simple-download-xlsx.php file in the /Tests or /Examples directory does exactly this
And "yes", it will work if MS Excel is already running on the client
回答3:
Insert the following headers just before creating the Writer
$filename = "filedetail". date("Y-m-d-H-i-s").".xlsx";
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
回答4:
header("Location: ".URL . "MODEL/case" . $caseNO . ".xlsx");
来源:https://stackoverflow.com/questions/15189296/phpexcel-automatically-download-and-open-an-excel-file