public function settlement_excel() {
$ids = I('get.ids');
dump($ids);
$data = M('worker_project_apply','t_')->where(array('id'=>array('in',$ids)))->select();
foreach ($data as &$value) {
$value = array_values($value);
}
dump($data);
addUserActionLog("导出", "结算明细");
set_time_limit(86400); //设置不超时
vendor('phpexcel.PHPExcel');
vendor('phpexcel.PHPExcel.Reader.Excel2007');
vendor('phpexcel.PHPExcel.Reader.Excel5');
vendor('phpexcel.PHPExcel.Reader.Excel2003XML');
$excel = new \PHPExcel();
//默认用excel2003读取excel,若格式不对,则用之前的版本进行读取
$PHPReader = new \PHPExcel_Reader_Excel2003XML();
$PHPReader = new \PHPExcel_Reader_Excel5();
/*设置文本对齐方式*/
$objActSheet = $excel->getActiveSheet();
$letter = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P','Q','R','S','T','U','V','W');
/*设置表头数据*/
$tableheader = array('id', '项目id','提现记录id','申请提现时间', '项目名称', '唯一识别号', '项目总单号', '发包金额', '增值税', '蝠券抵扣', '最终打款金额', '收款人', '平台账号', '开户行', '银行卡号','身份证', "开票方式","验收时间",'结算方式','采购人员类型','状态','备注');
/*填充表格表头*/
for ($i = 0; $i < count($tableheader); $i++) {
$excel->getActiveSheet()->setCellValue("$letter[$i]1", "$tableheader[$i]");
$objActSheet->getColumnDimension("$letter[$i]")->setWidth(20);
}
/*填充表格内容*/
for ($i = 0; $i < count($data); $i++) {
$j = $i + 2;
/*设置表格宽度*/
//$objActSheet->getColumnDimension("$letter[$i]")->setWidth(20);
/*设置表格高度*/
$excel->getActiveSheet()->getRowDimension($j)->setRowHeight(20);
/*向每行单元格插入数据*/
for ($row = 0; $row < count($data[$i]); $row++) {
$objActSheet->getColumnDimension("$letter[$row]")->setWidth(20);
$excel->getActiveSheet()->setCellValue("$letter[$row]$j", $data[$i][$row]);
continue;
}
}
$objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel5');//Excel5为xls格式,excel2007为xlsx格式
ob_end_clean();//清除缓冲区防止乱码
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header('Content-Disposition:attachment;filename="结算明细.xls"');
header("Content-Transfer-Encoding:binary");
$objWriter->save('php://output');
}
|