我想在一个 excel 文件中生成类似的东西,但它生成的不是我想要的。我希望输出完全相同。如果测试数量为四,则在 Excel 文件中的一个单元格中动态打印四个测试,如 Word 文档中一样,加上其他详细信息
这是有关测试数量及其详细信息的更多详细信息。
$trd = $this->getRequestedTestsDisplay2($labref); //An array of objects 4 in total
$coa_details = $this->getAssayDissSummary($labref); //details as shown http://nqcl.alphybay.com/word.png
phpword代码
for ($i = 0; $i < count($trd); $i++) {
foreach ($coa_details as $coa) {
if ($coa->test_id == $trd[$i]->test_id) {
$determined = $coa->determined;
$remarks = $coa->verdict;
}
}
$table3->addRow(400);
$table3->addCell(1500)->addText($trd[$i]->name);
$table3->addCell(1500)->addText($trd[$i]->methods);
$table3->addCell(1700)->addText($trd[$i]->compedia);
$table3->addCell(1800)->addText($trd[$i]->specification);
$table3->addCell(1700)->addText('DETERMINED', $style3);
$table3->addCell(1500)->addText($trd[$i]->complies);
}
phpxcel代码
$row = 19;
$col=1;
$worksheet= $objPHPExcel->getActiveSheet();
for ($i = 0; $i < count($trd); $i++) {
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)
->setCellValueByColumnAndRow($col, $row, $trd[$i]->specification)
->setCellValueByColumnAndRow($col, $row, $trd[$i]->complies);
$col++;
}
$row++;
}