插入新行并将数据填充到vcells-phpExcel中


Inserting a new row and filling in data to vcells phpExcel

我有以下代码,它能很好地将数据发送到excel表。在数据库中,我在一列下有值,比如k,我有逗号分隔的值,例如alphonce、ochieng、abc,所以对于每个值/单词,我想创建一个新行,以便alphonce在给定单元格中的新行中,与ochieng等相同,就像生成的表行中保存名称一样。

    $trd = $this->getRequestedTestsDisplay2($labref);
    $coa_details = $this->getAssayDissSummary($labref);
    $row = 26;
    $worksheet = $objPHPExcel->getActiveSheet();
    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;
            }
        }

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

          $worksheet->setCellValueByColumnAndRow($col++, $row, str_replace(",", "'n", $trd[$i]->specification));

        $worksheet->setCellValueByColumnAndRow($col++, $row, str_replace(",", "'n",$determined)); 

        $worksheet->setCellValueByColumnAndRow($col++, $row, str_replace(",", "'n", $trd[$i]->complies));
        $worksheet->getStyle($col++ . $row)->getAlignment()->setWrapText(true);
        $worksheet->getRowDimension($row)->setRowHeight(-1);
        $row++;
    }

}
$myData = "Hello,World";
// Write data to cell A1, replacing comma with a new line character
$worksheet->setCellValueByColumnAndRow(1, 1, str_replace(",", "'n", $myData));
// Set the cell alignment to wrap the text
$worksheet->getStyle('A1')->getAlignment()->setWrapText(true);
// Set the row height to automatically adjust to the number of lines
//    of data in the cell
$worksheet->getRowDimension(1)->setRowHeight(-1);