/** * 设置工作表数据 * @param \PHPExcel $phpExcel * @param string $startDate * @param string $endDate * @param int $sheetId 工作表ID * @param array $data 表头数据 */ public static function setSheetData(\PHPExcel $phpExcel, $startDate, $endDate, $sheetId, array $data) { //评价周期 $days = DateUtil::inDays($startDate, $endDate); $t = count($days); $phpExcel->setActiveSheetIndex($sheetId); $sheetFieldNum = count($data); for ($i = 0; $i < $sheetFieldNum; $i++) { $name = $data[$i]; $col = self::numToStr($i); $field = $col . '1'; self::setSheetTitleStyle($phpExcel, $field, $col, $name); //$i为列,$j为行 for ($j = 0; $j < $t; $j++) { if ($i == 0) { self::setCellValue($phpExcel, self::numToStr($i) . ($j + 2), $days[$j]); } else { self::setCellValue($phpExcel, self::numToStr($i) . ($j + 2), ''); } self::setBorder($phpExcel, self::numToStr($i) . ($j + 2)); } } }