title: PHPExcel Memory Problems - any more ideas?
body: <p>Iam trying to write an Excel2007 File with Zend Framework and PHPExcel. I know i could increase the PHP Memory Limit.. but is there no other way? </p>
  
  <p>This is my Code so far, it works well with 5000 Rows and 77 Columns but i need 12000 rows :-) Memory is set to 128MB</p>
  
  <pre><code>    $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_sqlite;
      PHPExcel_Settings::setCacheStorageMethod($cacheMethod);
  
      $db = Zend_Db_Table_Abstract::getDefaultAdapter();
      $phpExcel = new PHPExcel();
  
      // set headers
      $select = $db-&gt;select();
      $select-&gt;from('IMPORT')-&gt;limit(1);
      $data = $select-&gt;query()-&gt;fetchAll();
      $columns = array_keys($data[0]);
      $phpExcel-&gt;setActiveSheetIndex(0);
      $colCNT = 1;
  
      foreach ($columns as $column) {
          $letter = Nc_Utils::getNameFromNumber($colCNT);
          $phpExcel-&gt;getActiveSheet()-&gt;SetCellValue($letter . '1', $column);
          $colCNT++;
      }
  
      unset($select);
      unset($data);
  
      $sql = 'SELECT * FROM IMPORT LIMIT 7000';
      $stmt = $db-&gt;query($sql);
  
      $rowCNT = 2;
      while($rows = $stmt-&gt;fetch()){
          $phpExcel-&gt;getActiveSheet()-&gt;fromArray($rows, null, 'A'.$rowCNT);
          $rowCNT++;
      }  
  
      unset($rowCNT);
      unset($select);
      unset($db);
  
      // MEMORY USAGE = 4 MB!
  
      $phpExcelWrite = new PHPExcel_Writer_Excel2007($phpExcel);
      $phpExcelWrite-&gt;setUseDiskCaching(true);
      $phpExcelWrite-&gt;save(str_replace('.php', '.xls', __FILE__));
  </code></pre>
  
  <blockquote>
    <p>PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted
    (tried to allocate 13878925 bytes) in
    /Applications/MAMP/htdocs/phpexcel/library/PHPExcel/Shared/XMLWriter.php
    on line 102</p>
  </blockquote>