传递给PHPExcel_Shared_Date :: isDateTime()的参数1必须是PHPExcel_Cell的一个实例,双给

时间:2014-10-29 09:31:10

标签: php phpexcel

我使用PHPExcel作为我的代码,我在这部分中遇到错误:

第159 -179行:

if($extitle == $h){ 

                    $data = $objWorksheet->getCellByColumnAndRow($col, $row);


                            if(PHPExcel_Shared_Date::isDateTime($data)){
                                    $cellValue = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
                                    $dateValue = PHPExcel_Shared_Date::ExcelToPHP($cellValue);

                                     $dob =  date('Y-m-d',$dateValue);                              

                                        $tz  = new DateTimeZone('Asia/Manila');
                                        $rage = DateTime::createFromFormat('Y-m-d', $dob, $tz)->diff(new DateTime('now', $tz))->y;

                            }else{

                                $dob = "NULL";

                            }

                }

第180行-185

if($extitle == $i){ $data = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();   $mstatus = $data;               
                }

                if($extitle == $j){ $data = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();   $category = $data;              
                }

我收到错误:Catchable fatal error: Argument 1 passed to PHPExcel_Shared_Date::isDateTime() must be an instance of PHPExcel_Cell, double given, called in *****\uploadexceldata.php on line 187 and defined in ******\Classes\PHPExcel\Shared\Date.php on line 254

if($extitle == $q){

                    $data = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();           

//in this part the error occured    



                    if(PHPExcel_Shared_Date::isDateTime($data)){
                                    $cellValue = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
                                    $dateValue = PHPExcel_Shared_Date::ExcelToPHP($cellValue);

                                     $efdate =  date('Y-m-d',$dateValue);                               



                            }else{

                                $efdate = "NULL";

                            }
                }

但是,当我删除第{189}行if($extitle == $p){ $data = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();时,它可以正常工作。

现在,我想知道为什么会这样,我该如何修复它。

1 个答案:

答案 0 :(得分:1)

$data = $objWorksheet->getCellByColumnAndRow($col, $row)

返回一个PHPExcel_Cell对象

$data = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();

不返回PHPExcel_Cell对象,只是一个标量值,如数字或字符串

由于isDateTime()方法需要PHPExcel_Cell对象作为参数,PHPExcel_Shared_Date::isDateTime($data)$data是标量时会出现此错误

使用与您在第159行>中使用的逻辑相同的逻辑。获取$data作为PHPExcel_Cell对象,并使用后续调用

$cellValue = $data->getValue();

或类似

$data = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();           
    if(PHPExcel_Shared_Date::isDateTime($objWorksheet->getCellByColumnAndRow($col, $row))){