作者 刘朕
1 个管道 的构建 通过 耗费 5 秒

数据导出调试

... ... @@ -73,6 +73,41 @@ class TestController extends HomeBaseController
print_r($arr);exit;
}
public function income()
{
$uid = 451;
$user = Db::name('user')->where('id',$uid)->find();
$indent = Db::name('money_income')->where('uid',$uid)->order('create_time','desc')->select();
$arr = collection($indent)->toArray();
$data = [];
$tableheader = array('收入id', '收入金额', '订单id');
foreach ($arr as &$v) {
$data[] = [
$v['id'],
$v['money'],
$v['indent_id']
];
}
$this->excel2($data);
print_r($arr);exit;
}
public function withdraw_log()
{
$uid = 451;
$money_expend = Db::name('money_expend')->where('uid',$uid)->where('state',1)->order('create_time','desc')->select();
$money_expend = collection($money_expend)->toArray();
$data = [];
foreach ($money_expend as $v) {
$data[] = [
date('Y-m-d H:i:s',$v['create_time']),
$v['money']
];
}
$this->excel3($data);
}
/**
*
... ... @@ -111,6 +146,88 @@ class TestController extends HomeBaseController
//填充表格信息
for ($i = 3; $i <= count($data2) + 1; $i++) {
$j = 0;
foreach ($data2[$i - 3] as $key => $value) {
$excel->getActiveSheet()->setCellValue("$letter[$j]$i", "$value");
$j++;
}
}
//创建Excel输入对象
$write = new \PHPExcel_Writer_Excel2007($excel);
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="订单表.xlsx"');
header("Content-Transfer-Encoding:binary");
$write->save('php://output');
}
/**
*
* 导出Excel
*/
public function excel2($data2)
{
//引入PHPExcel库文件
// Vendor('phpexcel2.PHPExcel');
//创建对象
$excel = new \PHPExcel();
//Excel表格式,这里简略写了8列
$letter = array('A', 'B', 'C');
//表头数组
$tableheader = array('收入id', '收入金额', '订单id');
//填充表头信息
for ($i = 0; $i < count($tableheader); $i++) {
$excel->getActiveSheet()->setCellValue("$letter[$i]1", "$tableheader[$i]");
}
//填充表格信息
for ($i = 2; $i <= count($data2) + 1; $i++) {
$j = 0;
foreach ($data2[$i - 2] as $key => $value) {
$excel->getActiveSheet()->setCellValue("$letter[$j]$i", "$value");
$j++;
}
}
//创建Excel输入对象
$write = new \PHPExcel_Writer_Excel2007($excel);
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="收入表.xlsx"');
header("Content-Transfer-Encoding:binary");
$write->save('php://output');
}
/**
*
* 导出Excel
*/
public function excel3($data2)
{
//引入PHPExcel库文件
// Vendor('phpexcel2.PHPExcel');
//创建对象
$excel = new \PHPExcel();
//Excel表格式,这里简略写了8列
$letter = array('A', 'B');
//表头数组
$tableheader = array('提现时间', '提现金额');
//填充表头信息
for ($i = 0; $i < count($tableheader); $i++) {
$excel->getActiveSheet()->setCellValue("$letter[$i]1", "$tableheader[$i]");
}
//填充表格信息
for ($i = 3; $i <= count($data2) + 1; $i++) {
$j = 0;
foreach ($data2[$i - 2] as $key => $value) {
$excel->getActiveSheet()->setCellValue("$letter[$j]$i", "$value");
$j++;
... ... @@ -125,7 +242,7 @@ class TestController extends HomeBaseController
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header('Content-Disposition:attachment;filename="信息系统表.xlsx"');
header('Content-Disposition:attachment;filename="提现表.xlsx"');
header("Content-Transfer-Encoding:binary");
$write->save('php://output');
}
... ...