PHPExcel create new row for each values separated by a comma

Topics: Developer Forum, Project Management Forum, User Forum
Oct 2, 2013 at 8:04 AM
I am trying to explode values stored in the database and separated by a comma so that for each value after the comma, a new row is created with PHPExcel and the value written in that new row at column 5 for example a varaible $determined = Lamivudine 45% (Rsd = 45% ; n = 45),Zidovudine 45% (Rsd = 5% ; n = 45) Lamivudine 545% (Rsd = 45% ; n = 5),Zidovudine 45% (Rsd = 45% ; n = 54) Where test = Assay as shown here but instead it does quite the opposite as here

code:
  for ($i = 0; $i < count($trd); $i++) {
    $col = 1;
    foreach ($coa_details as $coa) {
        if ($coa->test_id == $trd[$i]->test_id) {
            $determined = $coa->determined;
            $remarks = $coa->verdict;
        }
    }
    $myval = explode(',', $determined);    

    $worksheet
            ->setCellValueByColumnAndRow($col++, $row, $trd[$i]->name)
            ->setCellValueByColumnAndRow($col++, $row, $trd[$i]->methods)
            ->setCellValueByColumnAndRow($col++, $row, $trd[$i]->compedia)
            ->setCellValueByColumnAndRow($col++, $row, $trd[$i]->specification);
      foreach ($myval as $components):
    if (count($components) > 1) {
        $num_rows = $row;
        $worksheet->insertNewRowBefore($col++, $num_rows + count($components));
        $worksheet->setCellValueByColumnAndRow($col++, $row, $determined);
    } else {
        $worksheet->setCellValueByColumnAndRow($col++, $row, $determined);
    }
        endforeach;

    $worksheet->setCellValueByColumnAndRow($col++, $row, $trd[$i]->complies);

    $row++;
}