我在foreach中有一个foreach来将数据父母列入专栏。它适用于PHP,但不适用于PHP excel 看屏幕截图: 这就是我想要的
但它只填充第二个循环中的数据:
这是我的代码:
$row=7;
$column = 'A';
$refcodegests = RefGest::find_by_sql('SELECT DISTINCT c.code, p.lib ..."');
foreach ($refcodegests as $refcodegest) {
$Code = $refcodegest->code;
$Lib = $refcodegest->lib;
$objPHPExcel->setActiveSheetIndex(0)->setCellValue( $column . $row, $Code . ' -' . $Lib );
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFill()->getStartColor()->setRGB('3F6E89');
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFont()->getColor()->setRGB('FFFFFF');
$refcodeacts = RefGest::find_by_sql('SELECT DISTINCT c.code_action, a.lib_action...
FROM cap_val_charges c,com_ref_action a
WHERE c.code_gestion="'.$CodeGestion.'" ...');
foreach ($refcodeacts as $refcodeact) {
$CodeAction = $refcodeact->code_action;
$LibAction = $refcodeact->lib_action;
$objPHPExcel->setActiveSheetIndex(0)->setCellValue( $column . $row, $CodeAction . ' -' . $LibAction );
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFill()->getStartColor()->setRGB('DFDFDF');
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFont()->getColor()->setRGB('233748');
$row++;
}
$row++;
}
任何人都知道要改变什么?
提前致谢
答案 0 :(得分:0)
我认为您需要在第二个$row++
循环中移动第二个foreach()
:
$row=7;
$column = 'A';
$refcodegests = RefGest::find_by_sql('SELECT DISTINCT c.code, p.lib ..."');
foreach ($refcodegests as $refcodegest) {
$Code = $refcodegest->code;
$Lib = $refcodegest->lib;
$objPHPExcel->setActiveSheetIndex(0)->setCellValue( $column . $row, $Code . ' -' . $Lib );
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFill()->getStartColor()->setRGB('3F6E89');
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFont()->getColor()->setRGB('FFFFFF');
$row++;
$refcodeacts = RefGest::find_by_sql('SELECT DISTINCT c.code_action, a.lib_action...
FROM cap_val_charges c,com_ref_action a
WHERE c.code_gestion="'.$CodeGestion.'" ...');
foreach ($refcodeacts as $refcodeact) {
$CodeAction = $refcodeact->code_action;
$LibAction = $refcodeact->lib_action;
$objPHPExcel->setActiveSheetIndex(0)->setCellValue( $column . $row, $CodeAction . ' -' . $LibAction );
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFill()->getStartColor()->setRGB('DFDFDF');
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFont()->getColor()->setRGB('233748');
$row++;
}
}
否则您的第一个$refcodeact
会覆盖您刚刚设置的$refcodegest