我正在尝试使用PHP和Symfony将数组导出为XLS文件,如下所示。一旦创建了XLS文件,我只能获取数组的最后一行,并且它显示在我的文件的第一行。似乎“lignes”变量没有递增。我无法弄清楚问题出在哪里,有人可以帮忙吗?
foreach ($adresses as $ad ){
$phpExcelObject->setActiveSheetIndex(0)->setCellValue('A' . $lignes, $ad->getId());
$phpExcelObject->setActiveSheetIndex(0)->setCellValue('E' . $lignes, $ad->getTypeVoie());
$phpExcelObject->setActiveSheetIndex(0)->setCellValue('F' . $lignes, $ad->getVoie());
$phpExcelObject->setActiveSheetIndex(0)->setCellValue('G' . $lignes, $ad->getTypeQuartier());
$phpExcelObject->setActiveSheetIndex(0)->setCellValue('H' . $lignes, $ad->getQuartier());
$phpExcelObject->setActiveSheetIndex(0)->setCellValue('I' . $lignes, $ad->getCodePostale());
$phpExcelObject->setActiveSheetIndex(0)->setCellValue('K' . $lignes, $ad->getPays());
$phpExcelObject->setActiveSheetIndex(0)->setCellValue('J' . $lignes, $ad->getVille());
$lignes++;
}
$writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel2007');
$writer->save($fichier->getWebPathOut() );
$lignes++
,它代表该行的行号,永远不要改变它。 - Mark Baker