Problem Editing File 07reader.php

Topics: User Forum
Apr 15, 2009 at 12:11 PM

The live link to my problem is www.go2boss.com/registrar/07reader.php .  The page will load the example xlsx file fine, edit it, and save it correctly; however, when I change the file to a file I need opened, the page appears to time out and nothing gets done.  You can click on the link to see what the page prints out.  The code is exactly the same as the example in 07reader.php minus the file name difference.

The link to the excel file I am trying to open and edit is: www.go2boss.com/registrar/Grad.xlsx .  If someone could help me out it would be very much appreciated!  Thank you!


This is a code snippit from the 07reader.php:
 

echo date('H:i:s') . " Load from Excel2007 file<br>";

$objReader = PHPExcel_IOFactory::createReader('Excel2007');

$objPHPExcel = $objReader->load("Grad.xlsx");

echo date('H:i:s') . " Write to Excel2007 format<br>";

 

$objPHPExcel->getActiveSheet()->setCellValue('C13', 'Test Subject');

 

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');

$objWriter->save(str_replace('07reader.php', $s.'.xlsx', __FILE__));

Apr 15, 2009 at 2:43 PM
Edited Apr 15, 2009 at 2:55 PM
I changed the code to:

echo date('H:i:s') . " Load from Excel2007 file<br>";
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load("Grad.xlsx");

echo date('H:i:s') . " Write to Excel2007 format<br>";
$objPHPExcel->getActiveSheet()->setCellValue('C13', 'Test Subject');

echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r<br>";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('test.xlsx');

The page takes a long time to load, still times out.  Here's what it prints:
10:38:55 Load from Excel2007 file
10:38:59 Write to Excel2007 format
10:38:59 Peak memory usage: 20 MB

Please help!  Thank you, Frank.

Developer
Apr 16, 2009 at 3:31 AM
The script never finishes writing the file? Can you try to add one more line at the end?

echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r<br>";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('test.xlsx');

echo 'hello';

Otherwise, try this:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('max_execution_time', 1000);
ini_set('memory_limit', '512M');

echo date('H:i:s') . " Load from Excel2007 file<br>";
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load("Grad.xlsx");

echo date('H:i:s') . " Write to Excel2007 format<br>";
$objPHPExcel->getActiveSheet()->setCellValue('C13', 'Test Subject');

echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r<br>";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('test.xlsx');

echo 'Finished';
?>

Apr 16, 2009 at 12:26 PM
The second solution seemed to fix the problem.  I'm guessing the key line of code was the:

ini_set('max_execution_time', 1000);

The memory still doesn't exceed 20MB, and it never did display an error after the new code was added so I think it was the execution time that was causing the application to time out before it was successful.  I will have to change that in the php.ini settings.  I appreciate all of your help, thank you!

Frank