...
|
...
|
@@ -127,4 +127,52 @@ class Project extends Backend |
|
|
}
|
|
|
$this->success();
|
|
|
}
|
|
|
|
|
|
public function downloadexcel($ids){
|
|
|
$workinghours=Db::name("workinghours")
|
|
|
->alias("a")
|
|
|
->join("user b","a.user_id=b.id")
|
|
|
->where("project_id",$ids)
|
|
|
->select();
|
|
|
$project=Db::name("project")->where("id",$ids)->find();
|
|
|
$res=$this->projectexcel($workinghours,$project);
|
|
|
return $res;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*导出表
|
|
|
*/
|
|
|
public function projectexcel($workinghours, $project)
|
|
|
{
|
|
|
vendor('phpoffice.phpexcel.PHPExcel');
|
|
|
Vendor('phpoffice.phpexcel.Classes.PHPExcel');
|
|
|
Vendor('phpoffice.phpexcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory');
|
|
|
//实例化
|
|
|
$objExcel = new \PHPExcel();
|
|
|
//设置文档属性
|
|
|
$objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
|
|
|
//设置内容
|
|
|
$objActSheet = $objExcel->getActiveSheet();
|
|
|
$key = ord("A");
|
|
|
$letter = explode(',', "A,B,C,D,E");
|
|
|
$arrHeader = array('序号', '项目名称', '提交人','工时','提交时间');
|
|
|
//填充表头信息
|
|
|
$lenth = count($arrHeader);
|
|
|
for ($i = 0; $i < $lenth; $i++) {
|
|
|
$objActSheet->setCellValue("$letter[$i]1", "$arrHeader[$i]");
|
|
|
};
|
|
|
//填充表格信息
|
|
|
foreach ($workinghours as $k => $v) {
|
|
|
$j = $k + 1;
|
|
|
$k += 2;
|
|
|
$objActSheet->setCellValue('A' . $k, $j);
|
|
|
$objActSheet->setCellValue('B' . $k, $project['project_name']);
|
|
|
$objActSheet->setCellValue('C' . $k, $v['username']);
|
|
|
$objActSheet->setCellValue('D' . $k, $v['working_hours']);
|
|
|
$objActSheet->setCellValue('E' . $k, date("Y-m-d",$v['reporttime']));
|
|
|
}
|
|
|
$outfile = $project['project_name'] . ".xlsx";
|
|
|
$objWriter->save('./datauploads/' . $outfile);
|
|
|
return $outfile;
|
|
|
}
|
|
|
} |
...
|
...
|
|