<?php
if($_POST['export'])
{
require_once (dirname(__FILE__) . '/../Classes/PHPExcel.php');
$qry="select accessed_Menus as menus,phone_number as phone,date_Accessed as timeAxed,sessionid as sessiondetails from access_trails where DATEADD(dd, 0, DATEDIFF(dd, 0 ,date_Accessed)) >= DATEADD(dd, -10, DATEDIFF(dd, 0, {fn NOW()})) order by 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;
?>
大家好.....我使用上面的代码将数据从数据库导出到电子表格......我能够正确检索数据,但它只显示在加载的页面内。我能够从我的本地主机下载一个 .xls 文件。帮助