Can't read excel file

Topics: Developer Forum
Jul 22, 2014 at 10:06 PM
Edited Jul 22, 2014 at 10:18 PM
I create a cronjob to read a excel file, that I receive everyday by FTP on my server.
I implemeneted this code:

$fileName = $_SERVER["DOCUMENT_ROOT"]./searchresults.xls;
       $fileType = PHPExcel_IOFactory::identify($fileName);
        $objReader = PHPExcel_IOFactory::createReader($fileType);
        $objPHPExcel = $objReader->load($fileName);
        $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);

I always have this error:
I don't know what is happening because the file can be opened on Excel.

But, If I opened the file on Excel, then copy the data and paste in another file (newFile.xls), the code works. I posted the file searchresults.xls here:

Any advice please!!!

I am using:
  • PHP 5.3.21
  • PHPExcel 1.8.0
  • Centos 5.6
Jul 22, 2014 at 10:43 PM
Edited Jul 22, 2014 at 10:50 PM
From the error message, your Excel file isn't an Excel file, it's simply HTML markup. You can check this by opening the file in a text editor: if it looks like HTML, then it is HTML.

To fix this error in the HTML Reader, edit /Classes/PHPExcel/Reader/HTML.php and change line 425 from
$dom = new domDocument;
$dom = new DOMDocument;