1

I tried to read excel file and convert it into array. But i m getting

    following error.
    Fatal error: 
    Allowed memory size of 1677721600 bytes exhausted (tried to allocate 38 bytes)
    in /var/www/import_excel/Classes/PHPExcel/Worksheet.php on line 2431

I used this following code to read

set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
include 'PHPExcel/IOFactory.php';   


    $inputFileName = $target_file; 
    try {
        $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
    } catch(Exception $e) {
        die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
    }

error_reporting(-1);
ini_set('display_errors',1);

$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);

echo "<pre>";
print_r($allDataInSheet);
die();  

i need to get excel data as array. but the excel file has 130 columns & more than 100 rows. so when i tried to convert to array. i m getting error. but when i tried with less column and row its working. When i try with 130 column and 50+ rows getting error.

Is there available any alternative way to convert array instead of this $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); this line. Please someone advice or help me to fix this issue. Thank you

Jonathan John
  • 195
  • 2
  • 4
  • 12
  • 1
    Why do you need it as an array? Arrays take a lot of memory in PHP. Why can't you simply process it row by row? – Mark Baker Nov 03 '15 at 09:28
  • 1
    Have you looked at any of the cell caching or other options that PHPExcel provides to reduce memory usage? – Mark Baker Nov 03 '15 at 09:29
  • @MarkBaker hi thank you for your reply. No this is first time i m using Phpexcel. the code was already written by previous programmer now they asked me to upgrade the code. Thats why am asking. Entire code was written based on array value. Please if u tell any suggestion getting in array that will be great. – Jonathan John Nov 03 '15 at 09:42
  • i tried in all way by increasing execute time, memory limit and file size, post size everything but same error only getting – Jonathan John Nov 03 '15 at 09:44
  • Start by reading the [PHPExcel Docs](https://github.com/PHPOffice/PHPExcel/wiki/User%20Documentation) section on [cell caching](https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/04-Configuration-Settings.md) – Mark Baker Nov 03 '15 at 09:57
  • 1
    Also look at the logic of what you do with that array of data, if you could refactor that to work with a row of data direct from the worksheet object at a time, it will save a lot of memory – Mark Baker Nov 03 '15 at 09:58

0 Answers0