1

I'm new using PHPExcel. I have some issues with it.

I have an Excel like this:

enter image description here

Which in the row 3 are my origin locations and in the column B my destination.

What i need to do is read this data to save in a database table.

For example, my table price:

id_price          origin             destination          price
   1              Miami                Houston             20
   2              Florida              Houston             25
   3             New York              Houston             30

It doesn't matter in which order will save, maybe it can be like this:

id_price          origin             destination          price
   1              Miami                Houston             20
   2              Miami              Washington DC         10
   3              Miami                Miami               0

This is what actually I have:

include '../PHPExcel/PHPExcel/IOFactory.php';
$objPHPExcel = PHPExcel_IOFactory::load('example.xls');

$rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator();

foreach ($rowIterator as $row) {

    if ($row->getRowIndex() > 2) { // starts with row 4

        echo '    - Row number: ' . $row->getRowIndex() . "\r\n";

        $cellIterator = $row->getCellIterator();

        foreach ($cellIterator as $cell) {
            $columnIndex = PHPExcel_Cell::columnIndexFromString($cell->getColumn());

            if ($columnIndex > 0) { // starts with column 'C'
                echo '        - Cell: ' . $cell->getCoordinate() . ' - ' . $cell->getCalculatedValue() . "\r\n";

                /**
                 * Here, I just get the name of the columns from left to right
                 * then, in the next iterator i have the values
                 */

            }
        }

    }

}

I really don't know how to get what i need. Thanks for help.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Jhonatan Sandoval
  • 1,283
  • 6
  • 24
  • 40

0 Answers0