...
|
...
|
@@ -235,5 +235,56 @@ class Department extends Backend |
|
|
public function downloadexcel($id)
|
|
|
{
|
|
|
$department = Db::name("department")->where('id', $id)->find();
|
|
|
$workinghours=Db::name("workinghours")
|
|
|
->alias("a")
|
|
|
->join("user b","a.user_id=b.id")
|
|
|
->join("project c","a.project_id=c.id")
|
|
|
->where("a.department_id",$id)
|
|
|
->field("project_name,working_hours,reporttime,username")
|
|
|
->select();
|
|
|
$file=$this->projectexcel($workinghours,$department);
|
|
|
|
|
|
}
|
|
|
/**
|
|
|
*导出表
|
|
|
*/
|
|
|
public function projectexcel($workinghours, $department)
|
|
|
{
|
|
|
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,F");
|
|
|
$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, $department['name'])->getDefaultColumnDimension()->setWidth(20);
|
|
|
$objActSheet->setCellValue('C' . $k, $v['project_name']);
|
|
|
$objActSheet->setCellValue('D' . $k, $v['username']);
|
|
|
$objActSheet->setCellValue('E' . $k, $v['working_hours']);
|
|
|
$objActSheet->setCellValue('F' . $k, date("Y-m-d", $v['reporttime']));
|
|
|
}
|
|
|
$outfile = $department['name'] ."-". rand(10000, 99999) . ".xlsx";
|
|
|
$objExcel->createSheet();
|
|
|
// Redirect output to a client’s web browser (Excel2007)
|
|
|
$title = date("YmdHis");
|
|
|
header('Content-Disposition: attachment;filename="' . $outfile . '.xlsx"');
|
|
|
$objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
|
|
|
$objWriter->save('php://output');
|
|
|
}
|
|
|
} |
...
|
...
|
|