$objReader->load() not working

May 13, 2011 at 9:15 AM

The following code stops working at the $objReader->load($fl); line

$fl = "../../documents/imports/".$subid."__AXA.xlsx";

if (file_exists($fl)) {

    require_once '../../includes/phpexcel/Classes/PHPExcel/IOFactory.php';
   
    $inputFileName = $fl;
   
    $objReader = PHPExcel_IOFactory::createReader('Excel2007');
    try {
        // Load $inputFileName to a PHPExcel Object
        $objPHPExcel = $objReader->load($fl);
    } catch(Exception $e) {
        die('Error loading file: '.$e->getMessage());
    }

}

Any ideas please.

Jun 3, 2011 at 8:48 PM

Hi,

I have the same problem!

My code :

require_once '/var/www/htdocs/rapport/Classes/PHPExcel/IOFactory.php';

$objet1 = new PHPExcel_Reader_Excel5(); $excel1 = $objet1->load('rap.xlsx');   $objet2 = new PHPExcel_Reader_Excel5(); $excel2 = $objet2->load('rap2.xlsx'); $writer = new PHPExcel(); for ($i=0;$i<$excel1->getSheetCount();$i++){ $writer->addSheet($excel1->getSheet($i)); } for ($i=0;$i<$excel2->getSheetCount();$i++){ $writer->addSheet($excel2->getSheet($i)); } $save = new PHPExcel_Writer_Excel5($writer); $save->save('master.xlsx');

 

Can anyone help us?

Thanks

Coordinator
Jun 3, 2011 at 9:04 PM

@Triqu.

Try using the correct reader... the Excel5 reader is for Excel BIFF files, those files (typically) created using MS Excel 2003 or earlier, with an extension of .xls. To load Office Open XML files created with Excel 2007 or later, with an extension of .xlsx, you need to use the Excel2007 Reader.

Likewise, when writing, use the correct writer: Excel2007 for .xlsx files, Excel5 for .xls files.

@Drumgor

No ideas without a lot more information. Do you get any errors displayed? Is anything written to your PHP error log? Is there anything in the file that might break PHPExcel? Are you hitting a timeout or a memory limit? The possibilities are infinite, and my crystal ball is broken at the moment.

Jun 6, 2011 at 12:03 AM

I got mine to work but unfortunately cannot remember what it was that I changed. The code I posted above is still the same so the problem obviously lay elsewhere. Sorry I can't help.

Jun 7, 2011 at 12:22 AM

I have just hit the same problem again and remembered the issue is not with phpexcel but rather something in the spreadsheet one is trying to load that phpexcel does not like, because the exact same code works fine on other spreadsheets.

Jun 9, 2011 at 6:04 PM

Finally i used this : 

// Creation d'un lecteur
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
// Lecture du fichier excel (le nouveau rapport)
$objPHPExcel = $objReader->load($nouveauRapport);

It's working perfectly.

Thanks again for the quick reply MarkBaker.