2014-10-29 121 views
0

我使用PHPExcel對我的代碼,我在這部分得到一個錯誤:參數1傳遞給PHPExcel_Shared_Date :: isDateTime()必須PHPExcel_Cell的一個實例,雙定

線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
$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))){ 
+0

謝謝先生,你總是救我時,即時通訊麻煩 – itsmecidz 2014-10-29 09:57:52

相關問題