Cannot read an xlsx file

Topics: Developer Forum
May 21, 2014 at 11:20 AM
Hello, I'm trying to open an xlsx file, modify it and save it with another name. It's supposed to be quite simple but he doesn't work. Here is my code :
<?php
error_reporting(E_ALL);
date_default_timezone_set('Europe/London');
set_include_path('./lib/PHPExcel/Classes/');
require_once('PHPExcel/IOFactory.php');

ini_set('memory_limit','128M');

$toModifyPath = "./toModify.xlsx";
$outPath = "./out.xlsx";
$fileType = "Excel2007";


echo '<p>Starting...</p>';



//Open
$objReader = PHPExcel_IOFactory::createReader($fileType);
$objPHPExcel = $objReader->load($toModifyPath)
echo '<p>Opened</p>';


//Starting from here, it's working

//Modify
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('C6', '4')->setCellValue('C7', '5')->setCellValue('C8', '6')->setCellValue('C9', '7');
echo '<p>Modifed</p>';

//Save
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $fileType);
$objWriter->save($outPath);
echo '<p>Saved</p>';

echo '<p>Done !</p>';

?>
The output is "Starting...". So the line "$objPHPExcel = $objReader->load($toModifyPath)" is blocking with no error and i dont understand why. Anyone gots a clue?
May 21, 2014 at 11:53 PM
Just an idea, and I'm not sure if this pertains directly to your issue.

Wouldn't it be easier/simpler to copy the file to the new name and then open the new copy with PHPExcel for editing?

-- Christopher Mullins
Jun 6, 2014 at 9:09 AM
got same here.

i use yii framework .

i don't know why. everytime i try to read .xlsx it's always getting blank page .
if($original_extension == 'xls')
                {
                    $objReader = PHPExcel_IOFactory::createReader('Excel5');
                } elseif($original_extension == 'xlsx')
                {
                    $objReader = PHPExcel_IOFactory::createReader('Excel2007');
                }
                //$inputFileType = PHPExcel_IOFactory::identify($file);
                // $objReader = PHPExcel_IOFactory::createReader($inputFileType);
                $objReader->setReadDataOnly(true);
                $objPHPExcel = $objReader->load($file);
                $check=$objPHPExcel->getActiveSheet()->getCell('A1')->getValue();
                
                echo "<pre>";
                // var_dump($objPHPExcel);
                echo $check;
                echo "</pre>";
if i am insert xls file, i got the value . but when i am insert xlsx file. i got blank page .
thought PHPExcel_IOFactory can't read it . because when i use PHPExcel_IOFactory::indentify($file) it's got blank page too.

can someone help me what's going on here .