Skip to content

Instantly share code, notes, and snippets.

@exuan
Last active October 19, 2015 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exuan/62e4f6f07224d98d51ac to your computer and use it in GitHub Desktop.
Save exuan/62e4f6f07224d98d51ac to your computer and use it in GitHub Desktop.
phpexcel 画一个排期
<?php
$charts = array(); //26 * 27
for($i = 65; $i <91; $i++) {
$charts[] = chr($i);
}
for($i = 65; $i <91; $i++) {
$char = chr($i);
for($j = 65; $j <91; $j++) {
$charts[] = $char . chr($j);
}
}
//表头
$headers = array(
'课程',
'老师'
);
//导出报表
$PHPExcel = Excel::factory('PHPExcel');
$PHPExcelWriter = Excel::factory('PHPExcel_Writer_Excel2007', array(
$PHPExcel
));
$PHPExcel->setActiveSheetIndex(0);
$objActSheet = $PHPExcel->getActiveSheet(0);
foreach($headers as $key => $header) {
$objActSheet->setCellValue($charts[$key] . '1', $header);
$objActSheet->mergeCells($charts[$key] . '1:' . $charts[$key] . '2');
}
// 画日期
$headerCount = count($headers);
$startMonthCellKey = 0;
for($i = $startTime; $i <= $endTime; $i = $i + 86400) {
$dateArray = explode('-', date('Y-m-d', $i));
// 月份
if($dateArray[2] == 1 || $i == $startTime) {
$startMonthCellKey = $headerCount;
$objActSheet->setCellValue($charts[$headerCount] . '1', $dateArray[0] . '-' . $dateArray[1]);
}
// 合并单元格
if(date('t', $i) == $dateArray[2] || $i == $endTime) {
$objActSheet->mergeCells($charts[$startMonthCellKey] . '1:' . $charts[$headerCount] . '1');
$PHPExcel->getActiveSheet()->getStyle($charts[$startMonthCellKey] . '1:' . $charts[$headerCount] . '1')
->getAlignment()
->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
}
// 日期
$objActSheet->setCellValue($charts[$headerCount] . '2', $dateArray[2]);
$headerCount ++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment