PHPExcel无法从Excel获取公式结果

时间:2018-10-15 08:51:15

标签: php codeigniter phpexcel

我的导入功能有问题,在excel的某些单元格中,我的公式如下图所示

enter image description here

为什么我无法获得公式结果?我在google上搜索过,据说使用getCalculatedValuegetFormattedValue,但是我不知道如何将其实现为脚本,这是我的以下代码:

$inputFileName =  './public/uploads/excel/'.$uploaded['file_name'];
        try {
            $inputFileType = IOFactory::identify($inputFileName);
            $objReader = IOFactory::createReader($inputFileType);
            $objPHPExcel = $objReader->load($inputFileName);
        } catch(Exception $e) {
            die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
        }

        $sheet = $objPHPExcel->getSheet(0);
        $highestRow = $sheet->getHighestRow();
        $highestColumn = $sheet->getHighestColumn();

        for ($row = 3; $row <= $highestRow; $row++){                  //  Read a row of data into an array                 
            $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);

             $data = array(
                "part_no"           => $rowData[0][0],
                "part_revised_no"   => $rowData[0][1],
                "part_latest_no"    => $rowData[0][2],
                "part_desc"         => $rowData[0][3],
                "part_incoming_date"=> $rowData[0][4],
                "part_fob_japan"    => $rowData[0][5],
                "part_min_order"    => $rowData[0][6],
                "part_master_key1"  => $rowData[0][7],
                "part_total_stock"  => $rowData[0][8],
                "part_stock_j"      => $rowData[0][9],
                "part_stock_b"      => $rowData[0][10],
                "part_stock_s"      => $rowData[0][11],
                "part_stock_m"      => $rowData[0][12],
                "part_rak"          => $rowData[0][13],
                "part_last_opname"  => $rowData[0][14],
                "part_discontinued" => $this->convDiscontinued($rowData[0][15]),
                "part_mesin_code"   => $rowData[0][16],
                "part_srp"          => $rowData[0][17],
                "part_srp_cod"      => $rowData[0][18],
                "part_supv_price"   => $rowData[0][19],
                "part_mgr_price"    => $rowData[0][20],
                "part_dtr_price"    => $rowData[0][21],
                "part_keterangan"   => $rowData[0][22],
            );

            $insert = $this->db->insert("sparepart", $data);
            // unlink($uploaded['file_path']);
        }

1 个答案:

答案 0 :(得分:1)

您可以这样做:

$data = array( "part_no" => $sheet->getCellByColumnAndRow(0,0)->getCalculatedValue())