<?php
//若需要引入的文件可以私信
global $_W;
global $_GPC;
include_once IA_ROOT . '/framework/library/phpexcel/PHPExcel.php';
include_once IA_ROOT . '/framework/library/phpexcel/PHPExcel/IOFactory.php';
include_once IA_ROOT . '/framework/library/phpexcel/PHPExcel/Shared/Date.php';//时间转化
$Excel = new PHPExcel();
$arr = array();
$arr_header = array('A'=>'订单号','B'=>'订单状态','C'=>'司机姓名','D'=>'司机电话','E'=>'用车时间','F'=>'上车地址','G'=>'下车地址','H'=>'订单工费');
array_push($arr,$arr_header);
array_push($arr,$arr_header);
for($i= 0; $i< count($ress); $i++){
$arr_row = array('A'=>$ress[$i]['ordernum'],'B'=>$ress[$i]['type'],'C'=>$ress[$i]['siname'],'D'=>$ress[$i]['siphone'],'E'=>$ress[$i]['yctime'],'F'=>$ress[$i]['uaddress'],'G'=>$ress[$i]['xaddress'],'H'=>$ress[$i]['gmoney']);
array_push($arr,$arr_row);
}
$Excel
->getProperties()
->setCreator("dee")
->setLastModifiedBy("dee")
->setTitle("数据EXCEL导出")
->setSubject("数据EXCEL导出")
->setDescription("数据EXCEL导出")
->setKeywords("excel")
->setCategory("result file");
foreach($arr as $key => $val) { // 注意 key 是从 0 还是 1 开始,此处是 0
//print_r("key=".$key.',val='.$val);
//$num = $key + 1;
$Excel ->setActiveSheetIndex(0)
//Excel的第A列,uid是你查出数组的键值,下面以此类推
->setCellValue('A'.$key, $val['A'])
->setCellValue('B'.$key, $val['B'])
->setCellValue('C'.$key, $val['C'])
->setCellValue('D'.$key, $val['D'])
->setCellValue('E'.$key, $val['E'])
->setCellValue('F'.$key, $val['F'])
->setCellValue('G'.$key, $val['G'])
->setCellValue('H'.$key, $val['H']);
//->setCellValue('I'.$key, $val['I'])
}
$Excel->getActiveSheet()->setTitle('export');
$Excel->setActiveSheetIndex(0);
$Excel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
$Excel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
$Excel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
$Excel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
$Excel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
$Excel->getActiveSheet()->getColumnDimension('F')->setAutoSize(true);
$Excel->getActiveSheet()->getColumnDimension('G')->setAutoSize(true);
$Excel->getActiveSheet()->getColumnDimension('H')->setAutoSize(true);
// $Excel->getActiveSheet()->getColumnDimension('I')->setAutoSize(true);
$fileName = "订单"."-".date('YmdHis').".xls";
$ExcelWriter = PHPExcel_IOFactory::createWriter($Excel, 'Excel2007');
$filePath = $_SERVER['DOCUMENT_ROOT'].'/attachment/temp/'.$fileName;
$aa=$ExcelWriter->save($filePath);
$url = $_W['siteroot'].'/attachment/temp/'.$fileName;
// echo json_encode($url);exit;
// header('Location:'.$url);
itoast('导出成功', $url);
}else{
itoast('导出成功', $this->createMobileUrl('admin_main',array('mod' => 'mmcbb', 'ac' => 'list')));
}
?>