I\'m using PHPExcel to export some data to user in an excel file. I would like the script to send the excel file to the user immediately after it\'s creation. Here is my tes
For some people who may have this same ERROR message : it may very simply be because the filename you're trying to save to is actually already open in your Excel.. Was my case
Hi i tried the following: in a server linux Centos 7.0 do not specified the route of directory tmp, input:
function SaveViaTempFile($objWriter){
$filePath = '' . rand(0, getrandmax()) . rand(0, getrandmax()) . ".tmp";
$objWriter->save($filePath);
readfile($filePath);
unlink($filePath);
exit;
}
and work !!
And my answer is: Filename had symbols such as ":", ",", '"' Had to replace them to different ones. All worked
set chmod 777 -R public/results
The following works for the Excel2007 format. It would need to be adapted for different formats.
Open this file:
\Classes\PHPExcel\Writer\Excel2007.php
Look near Line 196 for:
if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
$pFilename = @tempnam(PHPExcel_Shared_File::sys_get_temp_dir(), 'phpxltmp');
Replace the second line with this:
$pFilename = dirname(\__FILE__).'/'. rand(0, getrandmax()) . rand(0, getrandmax()) . ".phpxltmp";
Then you can use the export-function as described in the developer guide.
Thanks to Mark Baker. His answer has solved the problem. I have written a simple helper method using his approach.
static function SaveViaTempFile($objWriter){
$filePath = sys_get_temp_dir() . "/" . rand(0, getrandmax()) . rand(0, getrandmax()) . ".tmp";
$objWriter->save($filePath);
readfile($filePath);
unlink($filePath);
}
And I have just replaced $objWriter->save('php://output')
with SaveViaTempFile($objWriter)