Unable to read XLS file

Topics: Developer Forum
May 1, 2013 at 4:59 PM
So I've been at this for hours and reach almost every forumn post I can find, but still I can't find a solution.

My company has a vendor that sends us an .xls file every day. The file needs to be parse and and updated on a website I've built already. The site was developed in PHP using Code Igniter.

The file is not a CVS or XML file masquerading as .xls because I have tried to open it up in a text editor and it's in some sort of binary format.

I know it's a valid Excell file because I can open it in my open copy of Excel on my mac.

The code I'm using in my PHP to load the file is this:
      $inputFileType = PHPExcel_IOFactory::identify(FCPATH ."files/". $file);                   
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
    try {
        $this->excel = $objReader->load(FCPATH ."files/". $file);
    } catch (Exception $e) {
        die ($e->getMessage());
But it won't work no matter what I try. I get this error message in my logs.

Uncaught exception 'Exception' with message 'The filename /var/www/mywebsite/my-webapp/files/Digital-Pacing-Report.xls is not recognised as an OLE file'

I would appreciate any suggestions at this point. I've tried loading it using the ''Excel2007' and "'Excel2003XML'" and it makes no difference. As far as I can tell PHPExcell can't even identify the file type.

Help please.

May 1, 2013 at 5:14 PM
Without seeing the file itself, it's difficult to say.

Can you try opening the file in a copy of MS Excel noting any messages you might get while opening), then doing a "save as". In the "save as" dialogue box, Excel will offer you a choice of formats that you can save the file as, with one of those formats currently as the selected type. What is that currently selected type?
May 1, 2013 at 5:15 PM
Is it possible to upload the file to this forum somehow?
May 1, 2013 at 5:41 PM
Edited May 1, 2013 at 5:41 PM
Uploading files can be done in the issue tracker: http://phpexcel.codeplex.com/WorkItem/View.aspx?WorkItemId=10749.

Some ground rules for file uploads:
◾When uploading a file to this issue, give it a clear name
◾Add a comment to the issue tracker, stating file is related to discussion post
May 1, 2013 at 6:35 PM
Okay, I've uploaded the file to the issue tracker.

Here is a link to the file.


I'm curious what this file is, if it's not an Excel file and if it's not Excel is there a way to convert it to a useful format?

May 1, 2013 at 11:22 PM
Excel 2013 opens it in protected mode, which I currently have set for files written using Excel4 (1992) or below. Further checks show that it is actually BIFF4. That means it was created/saved as an OLE1 document (a different format to the later BIFF5-8 OLE2 formats) that only supported a single worksheet. Unfortunately, PHPExcel doesn't support reading any BIFF versions below BIFF5.

Most versions of MS Excel should be capable of reading these earlier files, and protected mode can be disabled allowing them to be saved using a more recent format (Excel5/Excel95 or above).
May 2, 2013 at 2:00 PM
Hey Mark,

This is helpful. Unfortunately the files are emailed to me, from another company. Is there a way to convert them somehow either with PHPExcel or another PHP package, so that it can work automatically?

Just curious.

May 2, 2013 at 2:12 PM
Unless PHPExcel can read the file, it can't convert it; and if it could read the file you wouldn't have this problem anyway. Nor am I aware of any PHP library/script that can read OLE1 files (and I do maintain a long list of libraries).

The only way I can think of to do it is using MS Excel itself (I don't believe that Open/Libre Office or Gunumeric support anything earlier than Excel5)
May 2, 2013 at 2:15 PM
Okay, Thanks so much for your help. At least I know now what the problem has been. I really appreciate the feedback.


May 2, 2013 at 6:49 PM
Edited May 2, 2013 at 6:56 PM
pisaacs wrote:
So I've been at this for hours and reach almost every forumn post I can find, but still I can't find a solution.

Help please.

Hello Phil,

I am not an expert in this, nevertheless, I gave it a try, you can see the output by clicking on the link below. I saved your file into regular xls file from Excel 2007 and ran my PHPExcel script; except for the logos, I got rest of the contents. Have a look at it.


May 3, 2013 at 10:26 PM
Thanks for the feedback psb1967, but that wasn't exactly my problem. The issue was having PHPExcell read the file without having to resave it in Excell (by hand ) first, which is what you did.

Thanks for the help though.