Reading really huge files (16mb)

Topics: Developer Forum, Project Management Forum, User Forum
Mar 23, 2011 at 7:48 PM

So, i REALLY need help ;(

Im using the script that MarkBaker saying on the other discussion, but still i cant read the file:

ini_set("memory_limit","1024M");

set_time_limit(0);

error_reporting(E_ALL);

require_once 'Classes/PHPExcel/IOFactory.php';

class chunkReadFilter implements PHPExcel_Reader_IReadFilter
{

    private $_startRow = 0;

    private $_endRow = 0;



    public function setRows($startRow, $chunkSize)
    {
        $this->_startRow    = $startRow;
        $this->_endRow      = $startRow + $chunkSize;
    }

    public function readCell($column, $row, $worksheetName = '')
    {
        //  Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
        if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
            return true;
        }

        return false;
    }
}

$inputFileType = 'Excel5';
$inputFileName = 'teste_.xlsx';
$sheetname = 'DETALHADO';
$chunkSize = 100;

$objReader = new PHPExcel_Reader_Excel2007();
$chunkFilter = new chunkReadFilter();
$objReader->setReadFilter($chunkFilter);
$objReader->setReadDataOnly(true);
$objReader->setLoadSheetsOnly($sheetname);



$array_data = array();

for ($rowIndex = 2; $rowIndex <= 500; $rowIndex += $chunkSize) {

        $array_data[$rowIndex] = array(
            'localidade'=>'', 'impressora'=>'','cc' =>'','nomeCc'=>'',
            'nrImpressoes'=>'', 'valor'=>'','matricula' =>'','nome'=>'',
            'documento'=>'', 'dtImpressao'=>''
        );

	$chunkFilter->setRows($rowIndex,$chunkSize);
	$objPHPExcel = $objReader->load($inputFileName);
        $sheet = $objPHPExcel->getActiveSheet();
	
	$cell = $sheet->getCell('A' . $rowIndex);
        $array_data[$rowIndex]['localidade'] = $cell->getValue();

        $cell = $sheet->getCell('B' . $rowIndex);
        $array_data[$rowIndex]['impressora'] = $cell->getValue();

     
	$objPHPExcel->disconnectWorksheets();
	unset($objPHPExcel);


}

echo "<pre>";
print_r($array_data);
I have like 150k of lines, in 10 columns(just put 2 on this code), any help? ;(