Cannot read an xlsx file

Topics: Developer Forum
May 21, 2014 at 10: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 :


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

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

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

//Starting from here, it's working

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

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $fileType);
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 10: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 8: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);
                $objPHPExcel = $objReader->load($file);
                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 .