is not recognised as an OLE file

Topics: Developer Forum, User Forum
Dec 18, 2009 at 9:25 AM

Hi! I'm from Russia, sorry for my English. I use PHExcel to read .xml file and i have problrm: "The filename /site/web/www/obr.xls is not recognised as an OLE file"? What does it mean? How can i solve this problem?

My script: http://6550101.ru/managers/test.php

My code:

 

/** PHPExcel */
include 'Classes/PHPExcel.php';

include 'Classes/PHPExcel/Reader/Excel5.php';


$excelFileName ="/site/web/www/obr.xls";
            
$objReader = new PHPExcel_Reader_Excel5();
$objPHPExcel = $objReader->load($excelFileName);


$objWorksheet = $objPHPExcel->getActiveSheet();

echo '<table>' . "\n";
foreach ($objWorksheet->getRowIterator() as $row) {
  echo '<tr>' . "\n";
        
  $cellIterator = $row->getCellIterator();
  $cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,
                                                     // even if it is not set.
                                                     // By default, only cells
                                                     // that are set will be
                                                     // iterated.
  foreach ($cellIterator as $cell) {
    echo '<td>' . $cell->getValue() . '</td>' . "\n";
  }
 
  echo '</tr>' . "\n";
}
echo '</table>' . "\n";

Developer
Jan 20, 2010 at 11:45 AM

This is strange. To find the problem, can you change this in PHPExcel\Shared\OLERead.php

     // Check OLE identifier
        if (substr($this->data, 0, 8) != self::IDENTIFIER_OLE) {
            throw new Exception('The filename ' . $sFileName . ' is not recognised as an OLE file');
        }

to this

     // Check OLE identifier
        var_dump(base64_encode(substr($this->data, 0, 8)));
        if (substr($this->data, 0, 8) != self::IDENTIFIER_OLE) {
            throw new Exception('The filename ' . $sFileName . ' is not recognised as an OLE file');
        }

Post back the result you see on the screen.

Mar 17, 2010 at 4:06 AM

Hi, I have the same problem and I see on the screen

 

string(12) "PGh0bWw+DQo="

 

Thanks Mary

Developer
Mar 17, 2010 at 5:40 AM
marymarymary wrote:

Hi, I have the same problem and I see on the screen

 

string(12) "PGh0bWw+DQo="

 

Thanks Mary

Although the file may have an xls extension, this is a "fake" Excel file. If you open the file in a text editor you will notice that it is actually an HTML file.

 

Mar 18, 2010 at 3:52 AM

Thank you very much Kayoma.

That was exactly the problem.

Mary

 

Mar 13, 2013 at 11:10 AM
Hi.. I am having some problem regarding PHP Excel reader. Though the file has .xls extension ...I am getting

Fatal error: Uncaught exception 'PHPExcel_Reader_Exception' with message 'The filename C:\xampp\tmp\phpB8EC.tmp is not recognised as an OLE file'
Coordinator
Mar 14, 2013 at 10:28 AM
@Reeti

The message is pretty self-explanatory, PHPExcel doesn't believe that the file you'e trying to load is a correctly formatted Excel BIFF file. All that has an .xls extension isn't necessarily a real .xls file; a lot of script writers who don't know any better will write a csv file or html markup but give it an extension of .xls instead, and believe that it automagically creates a real Excel BIFF file from that.

Either use the IO Factory's identify() method to see what PHPExcel thinks the file is, and then use the reader that it recommends; or open the file ina text editor and see what it contains for yourself. If it's obviously a csv, or html instead of a BIFF binary filestream, then you'll need to select the appropriate Reader.