I have a problem like when I download excel sheet after remaining code not executing. Please look below mentioned sample code.
$data[]=array('EANCODE'=>6161106690015,'ItemDesc'=>'Electrical hammer mill 15hp'
,'UnitDesc'=>'PIECES','qty'=>10);
$object = new PHPExcel();
$object->setActiveSheetIndex(0);
$object->getActiveSheet()->setCellValue('A1', "EANCODE");
$object->getActiveSheet()->setCellValue('B1', "Item Name");
$object->getActiveSheet()->setCellValue('C1', 'Units');
$object->getActiveSheet()->setCellValue('D1', 'Quantity');
$excel_row = 2;
foreach($data as $item)
{
$object->getActiveSheet()->setCellValue('A'.$excel_row, $item['EANCODE']);
$object->getActiveSheet()->setCellValue('B'.$excel_row, $item['ItemDesc']);
$object->getActiveSheet()->setCellValue('C'.$excel_row, $item['UnitDesc']);
$object->getActiveSheet()->setCellValue('D'.$excel_row, $item['qty']);
$excel_row++;
}
$store_name='Insertion Failed Records - '. date('d-m-Y').".xlsx";
header('Content-Type: application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$store_name.'');
header('Cache-Control: max-age=0');
$objWriter =new PHPExcel_Writer_Excel2007($object, 'Excel2007');
$objWriter->save('php://output');
echo "something else";
Output : Excel Sheet downloading but given
echostatement not showing.
To output the XLS sheet to the page you are on, just make sure that page has no other echo's,print's, outputs.
As per my knowledge when we create and download or save file in any directory all echo content before this statement $objWriter->save('php://output'); is written in your file and after that statement, all part is skipped.