php - Phpexcel xls file showing garbage data while downloading -
i using phpexcel 1.8.0 in project. when want generate , download .xls file data database, file downloaded garbage data. here code:
$result = mysql_query("select * my_table"); ob_start(); //excel code $this->load->library('excel'); //activate worksheet number 1 $this->excel->setactivesheetindex(0); //name worksheet $this->excel->getactivesheet()->settitle('test worksheet'); $rownumber = 5; while ($row = mysql_fetch_assoc($result)) { $col = 'b'; foreach ($fields $cell) { $this->excel->getactivesheet()->setcellvalue($col .$rownumber, $row[$cell]); $col++; } $rownumber++; } // ob_end_clean(); // ob_clean() ; $filename='report.xls'; //save our workbook file name header('content-type: application/vnd.ms-excel'); //mime type header('content-disposition: attachment;filename="'.$filename.'"'); header('cache-control: max-age=0'); //no cache $objwriter = phpexcel_iofactory::createwriter($this->excel, 'excel5'); $objwriter->save('php://output'); exit();
i have used both ob_end_clean() , ob_clean() nothing works.
try code:
$objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel5'); ob_end_clean(); $objwriter->save('php://output');
Comments
Post a Comment