Generate Multiple Excel Files

Topics: Developer Forum, Project Management Forum, User Forum
Jul 1, 2013 at 9:42 PM
Edited Jul 1, 2013 at 9:43 PM
I need to generate multiple excel files within a loop. The code below only generates the file for the last loop.
for($i=0; $i<5; $i++) {
    $reader = new PHPExcel_Reader_Excel5();
    $objPHPExcel = $reader->load(APPPATH."files/dmr.xls");

    $sheet = $objPHPExcel->getSheet(0);
    $sheet->getCell('D4')->setValue("test");

    $filename='dmr.xls';
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="'.$filename.'"');
    header('Cache-Control: max-age=0'); //no cache
                 
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); 
    $objWriter->save('php://output');
}
Any help would be great! Thanks
Coordinator
Jul 1, 2013 at 10:41 PM
This isn't a problem with PHPExcel, it's a problem with the whole interweb. You can only send one file at a time to a web browser. If you want to send multiple files, you'll need to create a zip containing them all, then send them to the browser as a single zip file with the appropriate headers for a zip file.