excel
导入phpexcel
后台代码
$objPHPExcel = new\ PHPExcel();
$orderModel = new OrderModel();
$list = $orderModel - > order('id') - > selectByState(array('orderState' => 1));
$objActSheet = $objPHPExcel->getActiveSheet(); $objActSheet->getColumnDimension('B')->setAutoSize(true);
$objActSheet->getColumnDimension('C')->setAutoSize(true);
$objActSheet->getColumnDimension('D')->setAutoSize(true);
$objActSheet->getColumnDimension('E')->setAutoSize(true);
$objActSheet->getColumnDimension('F')->setAutoSize(true);
$objActSheet->getColumnDimension('G')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->setCellValue('A' . 1, '序列');
$objPHPExcel->getActiveSheet()->setCellValue('B' . 1, '订单号');
$objPHPExcel->getActiveSheet()->setCellValue('C' . 1, '粉丝电话号码');
$objPHPExcel->getActiveSheet()->setCellValue('D' . 1, '粉丝姓名');
$objPHPExcel->getActiveSheet()->setCellValue('E' . 1, '下单时间');
$objPHPExcel->getActiveSheet()->setCellValue('F' . 1, '商品名称');
$objPHPExcel->getActiveSheet()->setCellValue('G' . 1, '商品分类名');
$objPHPExcel->getActiveSheet()->setCellValue('H' . $i, convertUTF8('商品图片'));
$objDrawing = new \PHPExcel_Worksheet_Drawing();
foreach ($list as $key => $value) { $i = $key + 2;
$objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $value['id']);
$objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $value['orderId']);
$objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $value['phoNumber']);
$objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $value['fanName']);
$objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $value['orderTime']);
$objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $value['goodsName']);
$objPHPExcel->getActiveSheet()->setCellValue('G' . $i, $value['category']);
$objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel);
$name = '未发货订单表-' . date('Ymd');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $name . '.xls"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');