php - PHPExcel......spreadsheet displays on webpage instead of downloading -
<?php if($_post['export']) { require_once (dirname(__file__) . '/../classes/phpexcel.php'); $qry="select accessed_menus menus,phone_number phone,date_accessed timeaxed,sessionid sessiondetails access_trails dateadd(dd, 0, datediff(dd, 0 ,date_accessed)) >= dateadd(dd, -10, datediff(dd, 0, {fn now()})) order date_accessed desc"; $result=mssql_query($qry); $objphpexcel = new phpexcel(); $objphpexcel->setactivesheetindex(0); $rowcount = 1; while($row =mssql_fetch_assoc($result)){ $objphpexcel->getactivesheet()->setcellvalue('a'.$rowcount, $row['menus']); $objphpexcel->getactivesheet()->setcellvalue('b'.$rowcount, $row['phone']); $objphpexcel->getactivesheet()->setcellvalue('c'.$rowcount, $row['timeaxed']); $objphpexcel->getactivesheet()->setcellvalue('d'.$rowcount, $row['sessiondetails']); $rowcount++; } $objphpexcel->getactivesheet()->settitle('access logs'); $objphpexcel->setactivesheetindex(0); header('content-type: application/vnd.ms-excel'); header('content-disposition: attachment;filename="access logs.xls"'); header('cache-control: max-age=0'); $objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel5'); $objwriter->save('php://output'); exit; ?>
hi guys.....am using code above export data database spreadsheet....i able retieve data right displays inside loaded page. able download .xls file localhost though. help
you can try adding these 2 headers, though i'm unsure (i didn't tested it):
header("content-description: file transfer"); header("content-transfer-encoding: binary");
Comments
Post a Comment