PHPExcel and Synfony gets an exception

Apr 5, 2008 at 3:24 PM
Hi all,
I'm using PHPExcel in my symfony project, and I when I try to save a new xls:

$objWriter = new PHPExcelWriterExcel5($objPHPExcel);

the browser return me this kind of error:

Can't open 05pippo.xls. It may be in use or protected.
stack trace

  • at ()
in SFROOTDIR/lib/PHPExcel/Shared/OLE/OLE_Root.php line 103

} else {
$this->FILEH = @fopen($filename, "wb");
if ($this->FILEH == false) {
throw new Exception("Can't open $filename. It may be in use or protected.");
// Make an array of PPS's (for Save)

Do anybody knows what could be the problem?

Apr 7, 2008 at 6:09 AM
Have you checked if you can read the file with, say for example, filegetcontents()?
Apr 8, 2008 at 5:13 PM
Really, the things that I have to do in my php page is to let downloadable this xml file to the client, but I don't know how is it implementable! Do you have any suggestion about it?

Apr 8, 2008 at 6:41 PM
Do you have the required file permissions on your hosting account?
Apr 9, 2008 at 10:41 AM
Not yet... for now I have just to create a runtime download xml file from sql queries.

for example I'm able to do this with TCPDF class whit one line of code:

$pdf->Output('Statistic.pdf', 'D');

the "Statistic.pdf" doesn't exist and is create runtime for downloading.

I don't have any idea whit PHPXml class because I'm only find the command to create a physical file on the server.
Apr 9, 2008 at 12:44 PM
Sould be no problem then. Can you try setting the temp path (see docs) and output path to a absolute path? (i.e. /var/www/examplesite/out.xls)
Apr 9, 2008 at 2:55 PM
How can I set the temp path? I tried like this:

$objWriter = new PHPExcelWriterExcel5($objPHPExcel);

but i get this error: Call to undefined function setTempDir()
Apr 10, 2008 at 6:53 AM
$objWriter->setTempDir("/home/valerio/"); should be working... Are you using the latest version of PHPExcel?
Apr 15, 2008 at 9:30 AM

Sorry for answer you so late, but I was very busy.
My PHPExcel version is: 1.6.0, 2008-02-14

and I still get the same error also with "$objWriter->setTempDir("/home/valerio/")" instruction:

Strict Standards: Assigning the return value of new by reference is deprecated in /home/valerio/se1-0fidasonline_com/lib/PHPExcel/Writer/Excel5/Workbook.php on line 186

Strict Standards: Assigning the return value of new by reference is deprecated in /home/valerio/se1-0fidasonline_com/lib/PHPExcel/Writer/Excel5/Workbook.php on line 195


Can't open pippo.xls. It may be in use or protected.

Aug 19, 2008 at 10:36 AM
(Using PHPExcel 1.6.2)
I had the same problem and succeeded to resolve it.
Such like you valerio, i tried to define a temp directory to store a temporary file but it failed with Linux. Why ? It seems that the only that this temporary file is created is with the only readable right just for the root guy, even in the /tmp folder (witch is open in RW for everyone).
I have done that like that :

$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
$objWriter->setTempDir("/var/www/tmp"); //This never worked i don't know why... it still working on the /tmp directory
//To store on a local folder
$fp = fopen($nomficXLS, 'rb');
sleep(1);  //just a pause to let him time but i am not sure now if this is needed
fclose($fp);  //to close the file

The previews method never worked for me because of the read only property given for the root
So I have changed and decided to not work with a temporary file, like that

$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
//sending the file with the data directly

And it works now... I mean I receave the file and can watch everything fine. The only thing that do not work properly is the cells calculation formated like '=SUM(A4:A100)'. I don't know why, even if i specified : $objPHPExcel->getActiveSheet()->getCell('A3')->getCalculatedValue();
It doesn't worked. The cell is not calculated. If somebody has a clue... thanx to help :)