Converter failed to open the file.

Topics: Developer Forum
Apr 3, 2009 at 6:04 PM
I used the Hello World function provided here on the website (01simple.xlsx) and it works perfectly when I run the PHP from the command line -- the file write and I am able to open/read it.  However, when I put this exact same code in a function and run it from a webpage, the file is created yet I get a dialog box stating "Converter failed to open the file." when I try to open it.

How could the same exact code work perfectly when inline and not work when in a function/called from the web?  Below is the code:

function test() {
error_reporting(E_ALL);
 
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . 'D:\\ASO-APPS\\PROD\\TTR\\db\\Classes\\');
error_reporting(E_ALL);
include("db\Classes\PHPExcel.php");
include("db\Classes\PHPExcel\Writer\Excel2007.php");
 
// Create new PHPExcel object
echo date('H:i:s') . " Create new PHPExcel object\n";
$objPHPExcel = new PHPExcel();
 
// Set properties
echo date('H:i:s') . " Set properties\n";
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw");
$objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");
$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
 
 
// Add some data
echo date('H:i:s') . " Add some data\n";
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Hello');
$objPHPExcel->getActiveSheet()->SetCellValue('B2', 'world!');
$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Hello');
$objPHPExcel->getActiveSheet()->SetCellValue('D2', 'world!');
 
// Rename sheet
echo date('H:i:s') . " Rename sheet\n";
$objPHPExcel->getActiveSheet()->setTitle('Simple');
 
// Save Excel 2007 file
echo date('H:i:s') . " Write to Excel2007 format\n";
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save("db\blahs.xlsx");
 
// Echo done
echo date('H:i:s') . " Done writing file.\r\n";
}
Developer
Apr 3, 2009 at 6:12 PM
This indeed sounds strange. You are running the scripts on the same server? I would try to compare the two files in a HEX editor to see how they differ. They are really supposed to be identical.

Apr 3, 2009 at 6:19 PM
Yes, same exact server, run from the same exact directory.  Has anyone tried to use these classes from the web?  Any issues?
Developer
Apr 3, 2009 at 6:24 PM
Not sure what you mean by running from the web. If you send me the two files, I will take a look [erik at phpexcel dot net].

Apr 3, 2009 at 7:10 PM
Erik:

I sent you those files.  Thanks for taking a look !
Developer
Apr 3, 2009 at 7:46 PM
One file is a corrupt zip file while the other is ok as one notices if one changes file extension from xlsx to zip and tries to unzip them.

This looks like a defect zip extension as we have seen previously on Windows. Are you running this on Windows? If so, check FAQ section
"Excel 2007 can not open the file generated by PHPExcelWriter2007 on Windows"

If this turns out to be the problem I still have no explanation why not both xlsx files are corrupt.

Apr 3, 2009 at 7:53 PM
Edited Apr 3, 2009 at 8:33 PM
Interesting. Yes, I am using a Windows server.Windows 2003 Server R2 SP2 64-bit. I have the latest PHP (5.2.8) -- couldit be an issue with 64-bit?
You are correct though -- the from_queries.zip does notextract properly. Any other ideas?



From: koyama 

Subject: Re: Converter failed to open the file.[PHPExcel:52215]

From: koyama

One file is a corrupt zip file while theother is ok as one notices if one changes file extension from xlsx to zip andtries to unzip them.

This looks like a defect zip extension as we haveseen previously on Windows. Are you running this on Windows? If so, check FAQsection
"Excel 2007 can not open the file generated by PHPExcelWriter2007 onWindows"

If this turns out to be the problem I still have no explanationwhy not both xlsx files are corrupt.

Apr 3, 2009 at 7:57 PM
Interesting. Yes, I am using a Windows server. Windows 2003 Server R2 SP2 64-bit. I have the latest PHP (5.2.8), however I'm running the x86 version of PHP.  Could it be an issue with the 64-bit OS?  I don't know why one world work and not the other.  Very strange.

You are correct though -- the from_queries.zip does not extract properly.  Any other ideas?
Developer
Apr 3, 2009 at 8:06 PM
We have seen this bug on PHP 5.2.8 while 5.2.6 was apparently ok. I think it is fixed in PHP 5.2.9. Don't think it has anything to do with 64-bit. Upgrading to PHP 5.2.9 may be the best solution.

Apr 3, 2009 at 8:17 PM
I wonder if it's an issue with permissory rights or pathing? One main difference that I see between running the script via the CLI and from the webserver is which user is running the php call. When I run it from the CLI, it is my user with its own pathing. When it is run from my webserver, it is Apache's user (SYSTEM) running the script. Do you think that has something to do with it?
Are there specific permissions/pathing issues?
Developer
Apr 3, 2009 at 8:27 PM
I have absolutely no idea whether this could be an explanation, others here might? But there must be some explanation!

Apr 3, 2009 at 8:51 PM
FYI -- I have installed PHP 5.2.9-1 on my development server and the file is opened just fine! I'll confirm on Monday if they same workaround works on my production server.


From: koyama [mailto:notifications@codeplex.com]
Subject: Re: Converter failed to open the file. [PHPExcel:52215]

From: koyama

I have absolutely no idea whether this could be an explanation, others here might? But there must be some explanation!

Apr 7, 2009 at 6:47 PM
I found this issue to be resolved when upgrading to PHP 5.2.9-1 AND trim()'ing my INT fields. Thx for the help.