废话少说上代码,可能写的有点复杂,你可能需要下载一下phpexcel,让后整个放到vendor 下去引用一下.
- public function deal_record()
- {
- import("Vendor.PhpExcel.PHPExcel");
- $objPHPExcel = new /PhpExcel();
- $list=session('deallist');
- $list=array_splice($list,2);
- //echo P;var_dump($list);die;
- $row=array();
- $row[0]=array('交易时间','交易类型','影响金额','代收金额','说明','可用金额');
- $objPHPExcel->setActiveSheetIndex(0);
- //头部
- foreach ($row[0] as $key => $value)
- {
- $cwr=chr(65+$key).'1';//这里用来输出ABCDEFG...
- $objPHPExcel->getActiveSheet()->SetCellValue($cwr, $value);
- }
- foreach ($list['data'] as $key => $value) {
- $arr[$key][]=$value['date'];
- $arr[$key][]=$value['type'];
- $arr[$key][]=$value['affect_money'];
- $arr[$key][]=$value['collect_money'];
- $arr[$key][]=$value['desc'];
- $arr[$key][]=$value['account_money'];
- }
- $total = count($arr);
- $cr = count($arr['0']);//获取每个数组有几个元素用来控制列
- for($i=0;$i<=$cr;$i++)
- {
- $cwr2=chr(64+$i+1);
- for($j=2;$j<=$total+2;$j++)//因为第一行已经写成表的字段了。所以从第二行开始。
- {
- $cwr=$cwr2.$j;//abcdefg
- $objPHPExcel->getActiveSheet()->SetCellValue($cwr,$arr[$j-2][$i]);
- }
- }
- $objWriter = new /PHPExcel_Writer_Excel5($objPHPExcel);
- $objWriter->save(str_replace('.php', '.xls', __FILE__));
- $filename='交易记录.xls';
- 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=".$filename);
- //Vevb.com
- header("Content-Transfer-Encoding:binary");
- $objWriter->save("php://output");
- }
新闻热点
疑难解答
图片精选