PHPExcel 中文使用手册详解
安装
composer require "phpoffice/phpexcel"
使用:
已自动加载
实例化
一、
$objPHPExcel = new \PHPExcel(); /* 以下是一些设置 ,什么作者 标题啊之类的 */ $objPHPExcel->getProperties()->setCreator("实习网"); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', ('序号')) ->setCellValue('B1', ('订单号')) ->setCellValue('C1', ('职位名称')) ->setCellValue('D1', ('供职公司')) ->setCellValue('E1', ('申请时间')) ->setCellValue('F1', ('用户名')) ->setCellValue('G1', ('订单状态')) ->setCellValue('H1', ('总价')); foreach ($orderList as $k => $v) { $num = $k + 2; $objPHPExcel->setActiveSheetIndex(0) //Excel的第A列,uid是你查出数组的键值,下面以此类推 ->setCellValue('A' . $num, $v['id']) ->setCellValue('B' . $num, ($v['order_number'])) ->setCellValue('C' . $num, ($v['job_name'])) ->setCellValue('D' . $num, ($v['company_name'])) ->setCellValue('E' . $num, $v['addtime']) ->setCellValue('F' . $num, ($v['username'])) ->setCellValue('G' . $num, ($v['status'])) ->setCellValue('H' . $num, $v['service_money']); } unset($num); static $shxi = '订单'; $objPHPExcel->getActiveSheet()->setTitle('Member'); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true); $objPHPExcel->setActiveSheetIndex(0); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="'.$shxi. date('Ymd',time()) . '.xls"'); header('Cache-Control: max-age=0'); $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit;