評等結果
點擊便能為這篇文章進行評等!
[評等總次數: 0,平均評等: 0]
PHPEXCEL 產生月曆資料
<?php
include('Classes/PHPExcel.php');
require_once('Classes/PHPExcel/IOFactory.php');
function getthemonth($date){
$firstday = date('Y-m-01', strtotime($date));//取得該日期月份的第一天
$lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));//取得該日期月份的最後一天
return array($firstday,$lastday);
}
$YM = (isset($_GET['date'])?$_GET['date']:date("Y-m"));
$day=getthemonth($YM);
$dayCount = date("t",strtotime($day[0])); //該月份的總天數
$weekday = date('w', strtotime($day[0]));
$d_last=date("j",strtotime($day[1]));
$d_last=$dayCount+$weekday-1;//若第一天不是禮拜日
$w=array(1=>'A',2=>'B',3=>'C',4=>'D',5=>'E',6=>'F',7=>'G');
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle('排班表');
$objPHPExcel->getActiveSheet()->setCellValue('A1','星期 日');
$objPHPExcel->getActiveSheet()->setCellValue('B1','星期 一');
$objPHPExcel->getActiveSheet()->setCellValue('C1','星期 二');
$objPHPExcel->getActiveSheet()->setCellValue('D1','星期 三');
$objPHPExcel->getActiveSheet()->setCellValue('E1','星期 四');
$objPHPExcel->getActiveSheet()->setCellValue('F1','星期 五');
$objPHPExcel->getActiveSheet()->setCellValue('G1','星期 六');
$i=1;//日期
for($r=0;$r<=5;$r++){//跑六次
for($r1=1;$r1<=7;$r1++){//跑七次
$x=($r1+($r>0?$r*7:0));
$objPHPExcel->getActiveSheet()->setCellValue($w[$r1].($r+2),$x.($x>$weekday && $x<=$d_last+1?'【'.$i.'】':'')); //產生42格
$i=($x>$weekday?$i+1:1);
}
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('export/export_'.$YM.'.xlsx');
header('Location:export/export_'.$YM.'.xlsx');
exit;
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
評等結果
點擊便能為這篇文章進行評等!
[評等總次數: 0,平均評等: 0]