简体   繁体   中英

PHP Excel Reader 2 read can't read column if not filled

I've got an excel file like this: Excel example

I want to read the columns F, G ,H ,J when I do:

  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++; } 

I have the problem that I get errors:

PHP Notice: Undefined offset: 7 PHP Notice: Undefined offset: 8 PHP Notice: Undefined offset: 9

the F column is always full, but as you can see I've got problems with the others. How can I escape this error, so the field only gets checked if it's filled with data?

  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
  } 
    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 = '';
                    }

looks realy ugly but it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM