2012-10-24 43 views
0

我有一個Excel文件這樣的:Excel examplePHP的Excel閱讀器2個讀不能讀列,如果沒有填寫

我想讀的列F,G,H,J,當我做:

   for ($i = 3; $i <= $data->sheets[0]['numRows']; $i++) { 
       error_log(
        FW_Class_Voucher_Code::cleanCode($data->sheets[0]['cells'][$i][6]).' - '. 
        FW_Class_Voucher_Code::cleanCode($data->sheets[0]['cells'][$i][7]).' - '. 
        FW_Class_Voucher_Code::cleanCode($data->sheets[0]['cells'][$i][8]).' - '. 
        FW_Class_Voucher_Code::cleanCode($data->sheets[0]['cells'][$i][9])); 
       $count++; 
       } 

我有我得到的錯誤問題:

PHP公告:未定義抵消:7 PHP公告:未定義抵消:8 PHP注意:未定義偏移:9

F列總是滿的,但正如您所看到的,我已經與其他人發生了問題。我怎樣才能避免這個錯誤,所以只有填充了數據才能檢查該字段?

回答

1
for ($i = 3; $i <= $data->sheets[0]['numRows']; $i++) { 
    $err=array; 
    for($j=6; $j<=9; $j++){ 
     if(isset(FW_Class_Voucher_Code::cleanCode($data->sheets[0]['cells'][$i][$j]))) 
     $err[]=FW_Class_Voucher_Code::cleanCode($data->sheets[0]['cells'][$i][$j]) ; 
    } 
    if(!empty($err){ 
     $msg=implode('-',$err); 
     error_log($msg); 
    } 
    $count++; //I don't know what you're using $count for 
    } 
0
if (isset($data->sheets[0]['cells'][$i][7])) { 
         $col7 = $data->sheets[0]['cells'][$i][7]; 
        } else { 
         $col7 = ''; 
        } 
        if (isset($data->sheets[0]['cells'][$i][8])) { 
         $col8 = $data->sheets[0]['cells'][$i][8]; 
        } else { 
         $col8 = ''; 
        } 
        if (isset($data->sheets[0]['cells'][$i][9])) { 
         $col9 = $data->sheets[0]['cells'][$i][9]; 
        } else { 
         $col9 = ''; 
        } 

看起來真的很醜,但它的工作原理。