PHP: How to Read XLS file

If you want to read any Microsoft excel file, then you can use an opensource php library to handle your task. The php library to read the excel file is "phpexcelreader". Recently I have used the library to read a excel file for one of my project. And it worked like a charm.

You can find the library using google "phpexcelreader" or by downloading from http://sourceforge.net/projects/phpexcelreader/

1) Just download the library and unzip it using your zip software.

2) Go inside the Excel folder, and open the reader.php file.

3) remove the below code from the top of the line.
require_once 'Spreadsheet/Excel/Reader/OLERead.php';

4) And add the below code after remove that.
require_once 'Excel/oleread.inc';

That's it. Now try to run the sample codes, and then apply this library with your project or whatever you need.

Thanks
Wolf.

Comments

Hi! I've tried what you said to run the examples but both ran out of time and memory in the execution. My settings are default (30 s to execute and 16MB of memory to each script), is there something that I'm missing? Thanks anyway for your tips.
Unknown said…
If you are still looking for an answer to this issue, try replacing the example xls file with one of your own. That fixed it for me.
Anonymous said…
Dear,

you can use http://www.dbTube.org
to import excel data into mySQL.
Nishant said…
Hi Wolf,

Thanks a lot for this library. You saved me from doing a lot of coding.

@Ricardo: I also pasted my file in the same folder and then changed the example xls to my xls file and it worked. It is showing me all the records of my .xls file and I am able to store them in mysql database.
Nishant said…
Hi Wolf,

Thanks a lot for this library. You saved me from doing a lot of coding.

@Ricardo: I also pasted my file in the same folder and then changed the example xls to my xls file and it worked. It is showing me all the records of my .xls file and I am able to store them in mysql database.
Anonymous said…
Great code, works. But on line 261 of reader.php, there is a notice:

Error: Deprecated: Assigning the return value of new by reference is deprecated

The script on this line:
$this->_ole =& new OLERead();
Anonymous said…
Hi, to remove the deprecated error simply remove & from =& because in a newer php version this symbol is deprecated
can u please tell me how to read an exl file from inside a folder.because its shows erroe file name not readble.while importing a file inside any folder..please
Anjaan said…
Hi.
I keep getting this error.

[16-Sep-2012 02:44:11] PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 66322433 bytes) in //excel-reader/Excel/oleread.inc on line 172
Anjaan said…
Hi.
I keep getting this error.

[16-Sep-2012 02:44:11] PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 66322433 bytes) in //excel-reader/Excel/oleread.inc on line 172
Karpov Igorok said…
This is fine solution for small xls files. But if you want read 10k rows, this way will not work.
For big files you should use NoXLS API Parser http://noxls.net/documentation