How to handle phpexcel when handling large files with a large memory-intensive solution

Source: Internet
Author: User
A solution that phpexcel large files with large memory consumption
Phpexcel because it is a memory processing mechanism, when the number of rows or columns of Excel file memory will be an instant hundreds of m, due to server reasons I can not request more memory, so can only think fundamentally solve or circumvent the problem, For example, after processing an Excel file or one of the sheet pages to free memory and then processing the next, online search a circle, not a detailed complete, ask God to help tune, very look forward to.

Ps:
1. I use the version is 1.76, set the use of files and other parameters, completely does not work;
2. Small files have been transferred
3. Mentioned above, no need to talk about the large memory limit




Process the Excel code as follows: Execute error
Fatal error:using $this When not in object context in E:\wamp\www\uploadify\PHPExcel.php on line 796

function Parse_excel_file ($filename)
{
$php _reader = new phpexcel_reader_excel2007 ();
$php _reader = Phpexcel_iofactory::createreaderforfile ($filename);
$php _excel = $php _reader->load ($filename);
$current _sheet = $php _excel->getsheet (0);
$all _column = $current _sheet->gethighestcolumn ();
$all _row = $current _sheet->gethighestrow ();
$list = Array ();
for ($row _index = 2; $row _index <= $all _row; $row _index++)
{
$row _val = ";
for ($col _index = ' A '; $col _index <= $all _column; $col _index++)
{
$ADDR = $col _index. $row _index;
$cell = $current _sheet->getcell ($addr)->getvalue ();
if ($cell instanceof Phpexcel_richtext)
{
$cell = $cell->__tostring ();

$row _val = $row _val. ',' . $cell;
}
Array_push ($list, $row _val);
}
phpexcel::D Estroy ();
return $list;
}

The additional code in phpexcel.php is as follows:
Public Function Destroy () {
foreach ($this->_worksheetcollection as $index = + $dummy) {
$this->_worksheetcollection[$index]->destroy ();
$this->_worksheetcollection[$index] = null;
}
}

The additional code in worksheet.php is as follows:
Public Function Destroy () {
foreach ($this->_cellcollection as $index = + $dummy) {
$this->_cellcollection[$index] = null;
}
}

------to solve the idea----------------------
How many strips are exported at once?
------to solve the idea----------------------
The calling method should be: $php _excel->destroy ();

Phpexcel library consumes too much memory when computing all in memory cache
Once Ini_set (' Memory_limit ', ' 1024M '); only 1W data can be exported
Finally we used the CSV streaming file The world is quiet a lot
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.