//PHPExcel-1.8导出excel
<?php
header("Content-type: text/html; charset=utf-8");
mysql_query("SET NAMES 'utf-8'");
include "dbconfig.php";
//var_dump(111);exit();
include "PHPExcel-1.8/Classes/PHPExcel.php";

//创建对象
$objPHPExcel = new PHPExcel();
$st=$_POST['XX']." 00:00:00";
$et=$_POST['XX']." 23:59:59";;
//var_dump($st,$et); exit();
$result=mysql_query("select * from `XXX` where XXX");
//var_dump($result); exit();
$emps=array();
while($row=mysql_fetch_array($result)){
static $i=0;
$emps[$i] = $row;
$i++;
echo $i;
}
//设置内存占用
set_time_limit(0);
ini_set('memory_limit', '512M');
//设置属性
$objPHPExcel->getProperties()
->setCreator("WOLF")
->setLastModifiedBy("WOLF")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
//3.填充表格
$objActSheet = $objPHPExcel->setActiveSheetIndex(0); //填充表头
$objActSheet->setCellValue('A1','ID');
$objActSheet->setCellValue('B1','网站编号');
$objActSheet->setCellValue('C1','区域');
$objActSheet->setCellValue('D1','收货人');
$objActSheet->setCellValue('E1','订单编号');
$objActSheet->setCellValue('F1');
$objActSheet->setCellValue('G1');
$objPHPExcel->getActiveSheet()->mergeCells('E1:F1:G1');
$objActSheet->setCellValue('H1','用户名');
//填充内容
for($i=0;$i<count($emps);$i++){
$key=$i+2;
if($emps[$i]['sg']=='y'){
$ss[$i]='是';
}else{
$ss[$i]='否';
}
$aa[$i]=$emps[$i]['ostatus'];
switch ($aa[$i]) {
case '1':
$dd='等待支付中';
break;
case '2':
$dd='等待汇款中';
break;
default:
$dd='';
break;
}
$objActSheet->setCellValue('A'.$key,$emps[$i]['id']);
$objActSheet->setCellValue('B'.$key,$emps[$i]['XX']);
$objActSheet->setCellValue('C'.$key,$emps[$i]['XX']);
$objActSheet->setCellValue('D'.$key,$emps[$i]['XX']);
$objActSheet->setCellValue('E'.$key,$emps[$i]['XX']);
$objPHPExcel->getActiveSheet()->mergeCells('E1:F1:G1');
$objActSheet->setCellValue('H'.$key,$emps[$i]['XX']);
} //exit();
//4.输出
$objPHPExcel->getActiveSheet()->setTitle('XXX信息表');
$objPHPExcel->setActiveSheetIndex(0);
$day = date("m-d");
$filename = $day.'lifu.xls';
ob_end_clean();//清除缓冲区,避免乱码
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header('Content-Disposition: attachment;filename='.$filename);
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel5');
$objWriter->save('php://output');
exit;
?>

04-01 06:39