Jump to content

Reading large excel files into MySQL with PHPExcel


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) {
        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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.