Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8487767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:20:41+00:00 2026-06-10T21:20:41+00:00

Iam trying to write an Excel2007 File with Zend Framework and PHPExcel. I know

  • 0

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?

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

    $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_sqlite;
    PHPExcel_Settings::setCacheStorageMethod($cacheMethod);

    $db = Zend_Db_Table_Abstract::getDefaultAdapter();
    $phpExcel = new PHPExcel();

    // set headers
    $select = $db->select();
    $select->from('IMPORT')->limit(1);
    $data = $select->query()->fetchAll();
    $columns = array_keys($data[0]);
    $phpExcel->setActiveSheetIndex(0);
    $colCNT = 1;

    foreach ($columns as $column) {
        $letter = Nc_Utils::getNameFromNumber($colCNT);
        $phpExcel->getActiveSheet()->SetCellValue($letter . '1', $column);
        $colCNT++;
    }

    unset($select);
    unset($data);

    $sql = 'SELECT * FROM IMPORT LIMIT 7000';
    $stmt = $db->query($sql);

    $rowCNT = 2;
    while($rows = $stmt->fetch()){
        $phpExcel->getActiveSheet()->fromArray($rows, null, 'A'.$rowCNT);
        $rowCNT++;
    }  

    unset($rowCNT);
    unset($select);
    unset($db);

    // MEMORY USAGE = 4 MB!

    $phpExcelWrite = new PHPExcel_Writer_Excel2007($phpExcel);
    $phpExcelWrite->setUseDiskCaching(true);
    $phpExcelWrite->save(str_replace('.php', '.xls', __FILE__));

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:20:42+00:00Added an answer on June 10, 2026 at 9:20 pm

    I have tried to use PhpExcel but found out the same problems as you.
    I’ve tried all the proposals to reduce memory consumption (the link Klinky posted in his answer) but got only 25-30% improvement. I even thought about creating CSV output instead of excel.

    Now I am using PEAR’s Spreadsheet_Excel_Writer and it works fine for me with roughly the same amount of data (11k rows 62 columns), though it takes quite some time to generate the file.

    It is not as powerful as PhpExcel, but as I see in your example you are not using it to style cells and write functions, right?

    Example:

    $workbook = new Spreadsheet_Excel_Writer();
    $workbook->send($filename . '.xls');
    $workbook->setVersion(8); // excel 8
    // Create worksheet
    $worksheet =& $workbook->addWorksheet('submissions');
    $worksheet->setInputEncoding('UTF-8');
    // Write some data on Sheet 1
    $row = 0;
    $worksheet->write($row, 0, 'Poster #ID');
    $worksheet->write($row, 1, 'Surname');
    $worksheet->write($row, 2, 'Firstname');
    $worksheet->write($row, 3, 'Country');
    $worksheet->write($row, 4, 'E-mail');
    $worksheet->write($row, 5, 'All authors');
    $worksheet->write($row, 6, 'Institutions');
    $worksheet->write($row, 7, 'Abstract topic');
    $worksheet->write($row, 8, 'Abstract title');
    foreach ($records as $rec_id => $rec_data) {
        $row++;
        $worksheet->write($row, 0, 'P-' . $rec_data['id']);
        $worksheet->write($row, 1, $rec_data['submitter_surname']);
        $worksheet->write($row, 2, $rec_data['submitter_firstname']);
        $worksheet->write($row, 3, $rec_data['submitter_country']);
        $worksheet->write($row, 4, $rec_data['submitter_email']);
        $worksheet->write($row, 5, $rec_data['authors']);
        $worksheet->write($row, 6, $rec_data['institutions']);
        $worksheet->write($row, 7, $rec_data['abstract_topic']);
        $worksheet->write($row, 8, $rec_data['abstract_title']);
    }
    $workbook->close(); // output
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write to a pdf file on php server. I have
Iam trying to write a List<string> to a file with the StreamWriter class. When
I am trying write a function that generates simulated data but if the simulated
I am trying to write some simple code which will read a text file
I am trying to write a copy constructor for a class but I get
I am trying to write a dynamic lambda or query but it occurs an
I am trying to write a validation rule in Yii but can't get the
I am trying to write a String (lengthy but wrapped), which is from JTextArea
I am trying to write a dictionary to a txt file. Then read the
I am trying to write and read a password protected excel file, I found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.