Please tell me how you can skip lines that contain the value NULL. I'm trying to build a price list based on another Excel file. And there is a need to skip blank lines.

for ($row = 5; $row <= $highestRow; $row++) { $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE); if ($row == 5) { continue; } $export->getActiveSheet()->setCellValueByColumnAndRow(0, $row, $rowData[0][2]); $export->getActiveSheet()->setCellValueByColumnAndRow(1, $row, $rowData[0][3]); } 

That's it in the value of $ row, $ rowData [0] [2]; slips null

  • So compare with NULL and do continue ? What is the problem? - robertobadjio
  • Add the condition if (isset($row, $rowData[0][2])) { $export->getActiveSheet()->setCellValueByColumnAndRow(0, $row, $rowData[0][2]); $export->getActiveSheet()->setCellValueByColumnAndRow(1, $row, $rowData[0][3]); } if (isset($row, $rowData[0][2])) { $export->getActiveSheet()->setCellValueByColumnAndRow(0, $row, $rowData[0][2]); $export->getActiveSheet()->setCellValueByColumnAndRow(1, $row, $rowData[0][3]); } if (isset($row, $rowData[0][2])) { $export->getActiveSheet()->setCellValueByColumnAndRow(0, $row, $rowData[0][2]); $export->getActiveSheet()->setCellValueByColumnAndRow(1, $row, $rowData[0][3]); } That is, if both of these variables are NOT null, then perform the action. - Edward
  • @robertobadjo tried both options. ibb.co/k3ubTU I get something like this. - Maxim Sychevsky
  • @MaksimSychevsky You need to use a different counter instead of $row . Added answer - robertobadjio

1 answer 1

 $count = 5; for ($row = 5; $row <= $highestRow; $row++) { $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE); if ($row == 5 || empty($rowData[0][2])) { continue; } $export->getActiveSheet()->setCellValueByColumnAndRow(0, $count, $rowData[0][2]); $export->getActiveSheet()->setCellValueByColumnAndRow(1, $count, $rowData[0][3]); $count++; } 
  • Thank you for what you need! - Maxim Sychevsky