errors while rreading Excel file

Topics: Developer Forum, User Forum
Nov 12, 2010 at 11:16 AM

hi i am trying to read Excel 2007 file. actualyl the problem is, the code is working correctly on latest wamp server it works correctly. and when i run the code on previous versions , it gives error messages


Warning: ZipArchive::getFromName() [function.ZipArchive-getFromName]: Invalid or unitialized Zip object in C:\wamp\www\PHPExcel\Classes\PHPExcel\Reader\Excel2007.php on line 272

Warning: ZipArchive::getFromName() [function.ZipArchive-getFromName]: Invalid or unitialized Zip object in C:\wamp\www\PHPExcel\Classes\PHPExcel\Reader\Excel2007.php on line 275

Warning: Invalid argument supplied for foreach() in C:\wamp\www\PHPExcel\Classes\PHPExcel\Reader\Excel2007.php on line 313

Fatal error: Call to a member function getHighestRow() on a non-object in C:\wamp\www\PHPExcel\Classes\xls07.php on line 10

 

The same problem occurs when i upload the code to server. can anyone  guide me, how to resolve this problem.

Dec 1, 2010 at 4:20 AM
Edited Dec 1, 2010 at 4:20 AM

Can anybody got any solution to this..I am also having a similiar kind of problem.

Dec 1, 2010 at 5:03 AM
Manash082 wrote:

Can anybody got any solution to this..I am also having a similiar kind of problem.

i have solved this problem. it occurs due to the extensions which you should install before running the code.  please check thre requirements that which extensions are required to run the code.

Dec 1, 2010 at 5:25 AM
Edited Dec 1, 2010 at 9:38 AM
sheraz4pro wrote:
Manash082 wrote:

Can anybody got any solution to this..I am also having a similiar kind of problem.

i have solved this problem. it occurs due to the extensions which you should install before running the code.  please check thre requirements that which extensions are required to run the code.

Thanks for the quick reply mate.

But I found out that all the thing are in order and enabled.Still having the problem.

1)PHP extension php_zip enabled *)

2)PHP extension php_xml enabled

3)PHP extension php_gd2 enabled

Any other extension I must be aware of???

Dec 1, 2010 at 5:37 AM

what is your wamp version and is xml_rpc enabled or not?

Dec 1, 2010 at 9:59 AM
Edited Dec 1, 2010 at 10:26 AM

Sorry i am using XAMPP and the version is as follows:-

XAMPP Control Panel Version 2.5

I am not using any Pear pacakge or anything. Just simple PHP with PHP Excel. So no idea about this xml_rpc.

Do I need to enable it?What is the function/use of it?

Coordinator
Dec 1, 2010 at 9:27 PM

In xampp's php.ini file, ensure that the line

extension=php_xmlrpc.dll

is not commented out. Likewise for the lines

extension=php_zip.dll

 and

extension=php_gd2.dll
Apr 23, 2013 at 10:47 AM
Hi All,

This came up first in my search results and didn't help with my issue which was the same as the one in the first post. I thought I'd post how I got it working for me in case it helps someone else with the same issue.

I'm using phpExcel on a WIMP setup and I was trying to read and write to an Excel 2007 file. All the test scripts worked fine for me but whenever I tried to test my own script it would always return the error in the first post. The difference was in my script I was using a file upload dialogue to upload my excel file. It seems that on Windows phpExcel didn't like the temp file name (something.tmp). Here's a snippet of the original code that works fine on a proper *nix server but not on Windows:
    $extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
    $upload_file = $_FILES['file']['tmp_name']; 
    $objReader = PHPExcel_IOFactory::createReaderForFile($upload_file);

    if($extension=='xls') {
        $objReader = PHPExcel_IOFactory::createReader('Excel5');
    }
    else {
        $objReader = PHPExcel_IOFactory::createReader('Excel2007');
    }
To get it to work on a Windows server I had to move the temp file to the original file name:
    $extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
    $upload_file = $_FILES['file']['tmp_name']; 

    //here's the bit I added 
    move_uploaded_file($upload_file, realpath('./tmp/') . "\\" . $_FILES['file']['name']);
    $upload_file = realpath('./tmp/') . "\\" . $_FILES['file']['name'];

    $objReader = PHPExcel_IOFactory::createReaderForFile($upload_file);
    if($extension=='xls') {
        $objReader = PHPExcel_IOFactory::createReader('Excel5');
    }
    else {
        $objReader = PHPExcel_IOFactory::createReader('Excel2007');
    }
I haven't looked into why this fixes the problem. I'm just happy that it does and I can resume testing on my dev server. I hope this help someone else as it took me a long time to figure this one out.