【发布时间】:2017-01-04 06:58:15
【问题描述】:
我正在尝试使用 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++在你的循环中......这是行号,你永远不会改变它