public function import_withdrawal()
{
$list = $this->model->order('total_all desc')->select();
include(ROOT_PATH . "/vendor/phpexcel/Classes/PHPExcel.php");
//3.实例化PHPExcel类
$objPHPExcel = new \PHPExcel();
//4.激活当前的sheet表
$objPHPExcel->setActiveSheetIndex(0);
//5.设置表格头(即excel表格的第一行)
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', '序号')
->setCellValue('B1', '游戏ID')
->setCellValue('C1', '游戏昵称')
->setCellValue('D1', '联盟ID')
->setCellValue('E1', '战力值')
->setCellValue('E2', '旧值')
->setCellValue('F2', '新值')
->setCellValue('G2', '差值')
->setCellValue('H1', 'T5击杀')
->setCellValue('H2', '旧值')
->setCellValue('I2', '新值')
->setCellValue('J2', '差值')
->setCellValue('K2', '积分')
->setCellValue('L1', 'T4击杀')
->setCellValue('L2', '旧值')
->setCellValue('M2', '新值')
->setCellValue('N2', '差值')
->setCellValue('O2', '积分')
->setCellValue('P1', 'T5阵亡')
->setCellValue('P2', '数量')
->setCellValue('Q2', '积分')
->setCellValue('R1', 'T4阵亡')
->setCellValue('R2', '数量')
->setCellValue('S2', '积分')
->setCellValue('T1', 'T5、T4阵亡')
->setCellValue('T2', '数量')
->setCellValue('U2', '积分')
->setCellValue('V1', '总积分');
$objPHPExcel->getActiveSheet()->mergeCells('A1'.':'.'A2');
$objPHPExcel->getActiveSheet()->mergeCells('B1'.':'.'B2');
$objPHPExcel->getActiveSheet()->mergeCells('C1'.':'.'C2');
$objPHPExcel->getActiveSheet()->mergeCells('D1'.':'.'D2');
$objPHPExcel->getActiveSheet()->mergeCells('V1'.':'.'V2');
$objPHPExcel->getActiveSheet()->mergeCells("E1:G1");
$objPHPExcel->getActiveSheet()->mergeCells("H1:K1");
$objPHPExcel->getActiveSheet()->mergeCells("L1:O1");
$objPHPExcel->getActiveSheet()->mergeCells("P1:Q1");
$objPHPExcel->getActiveSheet()->mergeCells("R1:S1");
$objPHPExcel->getActiveSheet()->mergeCells("T1:U1");
//设置A列水平居中
$objPHPExcel->setActiveSheetIndex(0)->getStyle('A1:V'.(count($list)+2))->getAlignment()
->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
// 设置垂直居中
$objPHPExcel->getActiveSheet()->getStyle('A1:V'.(count($list)+2))->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
// 设置背景色
$objPHPExcel->getActiveSheet()->getStyle('G2:G'.(count($list)+2))->applyFromArray(
array(
'fill' => array(
'type' => \PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => 'FFCC00')
)
)
);
$objPHPExcel->getActiveSheet()->getStyle('J2:J'.(count($list)+2))->applyFromArray(
array(
'fill' => array(
'type' => \PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => 'FFCC00')
)
)
);
$objPHPExcel->getActiveSheet()->getStyle('Q2:J'.(count($list)+2))->applyFromArray(
array(
'fill' => array(
'type' => \PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => '99CC00')
)
)
);
$objPHPExcel->getActiveSheet()->getStyle('N2:N'.(count($list)+2))->applyFromArray(
array(
'fill' => array(
'type' => \PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => 'FFCC00')
)
)
);
$objPHPExcel->getActiveSheet()->getStyle('O2:O'.(count($list)+2))->applyFromArray(
array(
'fill' => array(
'type' => \PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => '99CC00')
)
)
);
$objPHPExcel->getActiveSheet()->getStyle('V2:V'.(count($list)+2))->applyFromArray(
array(
'fill' => array(
'type' => \PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => 'FFFF99')
)
)
);
// 设置边框颜色
$styleThinBlackBorderOutline = array(
'borders' => array(
'allborders' => array( //设置全部边框
'style' => \PHPExcel_Style_Border::BORDER_THIN //粗的是thick
),
),
);
$objPHPExcel->getActiveSheet()->getStyle('A1:V'.(count($list)+2))->applyFromArray($styleThinBlackBorderOutline);
// 设置表头固定
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->freezePane('A3');
$tabel_name = ['C','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V'];
foreach ($tabel_name as $key => $value) {
//设置单元格宽度
//6.循环刚取出来的数组,将数据逐一添加到excel表格。
$objPHPExcel->setActiveSheetIndex(0)->getColumnDimension($value)->setWidth(12);
}
for ($i = 0; $i < count($list); $i++) {
$objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 3), $i+1);
$objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 3), $list[$i]['game_id']);
$objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 3), $list[$i]['nickname']);
$objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 3), $list[$i]['lm_id']);
$objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 3), $list[$i]['combat_old']);
$objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 3), $list[$i]['combat_new']);
$objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 3), $list[$i]['combat_diff']);
$objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 3), $list[$i]['t5_old']);
$objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 3), $list[$i]['t5_new']);
$objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 3), $list[$i]['t5_diff']);
$objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 3), $list[$i]['t5_sign']);
$objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 3), $list[$i]['t4_old']);
$objPHPExcel->getActiveSheet()->setCellValue('M' . ($i + 3), $list[$i]['t4_new']);
$objPHPExcel->getActiveSheet()->setCellValue('N' . ($i + 3), $list[$i]['t4_diff']);
$objPHPExcel->getActiveSheet()->setCellValue('O' . ($i + 3), $list[$i]['t4_sign']);
$objPHPExcel->getActiveSheet()->setCellValue('P' . ($i + 3), $list[$i]['t5_die_number']);
$objPHPExcel->getActiveSheet()->setCellValue('Q' . ($i + 3), $list[$i]['t5_die_sign']);
$objPHPExcel->getActiveSheet()->setCellValue('R' . ($i + 3), $list[$i]['t4_die_number']);
$objPHPExcel->getActiveSheet()->setCellValue('S' . ($i + 3), $list[$i]['t4_die_sign']);
$objPHPExcel->getActiveSheet()->setCellValue('T' . ($i + 3), $list[$i]['t4andt5total']);
$objPHPExcel->getActiveSheet()->setCellValue('U' . ($i + 3), $list[$i]['t4andt5sign']);
$objPHPExcel->getActiveSheet()->setCellValue('V' . ($i + 3), $list[$i]['total_all']);
}
//7.设置保存的Excel表格名称
$filename = '失落击杀统计' . date('Y-m-d H:i:s', time()) . '.xls';
//8.设置当前激活的sheet表格名称;
$objPHPExcel->getActiveSheet()->setTitle('失落击杀统计');
//9.设置浏览器窗口下载表格
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Disposition:inline;filename="' . $filename . '"');
//生成excel文件
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
//下载文件在浏览器窗口
$objWriter->save('php://output');
exit;
}
发表评论 取消回复