PHPExcel - 读取矩阵excel以列开头

时间:2015-03-13 01:57:30

标签: matrix phpexcel

我是使用PHPExcel的新手。我有一些问题。

我有一个像这样的Excel:

enter image description here

3 行中的哪一个是我的原始位置,而 B 列是我的目的地。

我需要做的是读取此数据以保存在数据库表中。

例如,我的表价格

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

保存的顺序无关紧要,也许可以这样:

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

这就是我的实际情况:

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
                 */

            }
        }

    }

}

我真的不知道如何得到我需要的东西。谢谢你的帮助。

0 个答案:

没有答案
相关问题