phpexcel Allowed memory size of 134217728 bytes ex

2019-01-12 06:13发布

问题:

This question already has an answer here:

  • PHPExcel runs out of 256, 512 and also 1024MB of RAM 7 answers

I am using phpexcel to write quite a large excel file.

I am writing it from an array that looks like

array(
  [0] => stdClass Object
        (
            [sent] => Mar 31st, 2011 02:10PM
            [to_number] => 64211111111
            [additional_txt] => 
            [misc_data] => 
        )
  ...
  [14058] => stdClass Object
        (
            [sent] => Mar 31st, 2011 02:10PM
            [to_number] => 64211111111
            [additional_txt] => 
            [misc_data] => 
        )
)

The loop is

$r = 0;
foreach ($replies_obj as $row) {
  $c = 'A';
  foreach ($row as $col)
    $xlsx->getActiveSheet()->setCellValue($c++ . $r, $col);
  $r++;
}

and the error is

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 105 bytes) in /home/webspace/xxxx/test/htdocs/application/libraries/PHPExcel/Worksheet.php on line 961

Is this a phpexcel problem or am I doing something wrong?

How can I fix this?

回答1:

There's a lot been written about PHPExcel and memory use, and I'm not going to repeat it all here.

Try reading some of the threads on the PHPExcel discussion board discussing the issue, such as this one; or previous answers here on SO such as this one or this one