Jump to content

Reading large excel files into MySQL with PHPExcel


johndean

Recommended Posts

I would appreciate some assistance with formulating the syntax for PHPExcel to enable the reading of large excel spreadsheet values into a database.

 

I have the code to enter the values into the database which works well for smaller spreadsheets but I do not understand how to use setReadFilter/chunksize that I have seen mentioned to read larger spreadsheets in smaller 'chunks'.

 

The code that I'm currently using is -

$objPHPExcel = PHPExcel_IOFactory::load($path);

foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
    $worksheetTitle     = $worksheet->getTitle();
    $highestRow         = $worksheet->getHighestRow(); // e.g. 10
    $highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
    $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
    $nrColumns = ord($highestColumn) - 64;
    for ($row = 2; $row <= $highestRow; ++ $row) {
		unset($val);
        for ($col = 0; $col < $highestColumnIndex; ++ $col) {
            $cell = $worksheet->getCellByColumnAndRow($col, $row);
            $val[] = $cell->getValue();
        }
		$query="insert into `#__stock_list_staging` (`id`, `part_no`, `stock_no`, `description`, `condition`, `quantity`) values ('','".$val[0]."', '".$val[1]."', '".$val[2]."', '".$val[3]."', '".$val[4]."')";
        // execute query here
    }
}

If anybody can help me to get the setReadFilter code and syntax in place to work with the above code I would be very grateful.

 

Regards, John

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.