使用PHPEXCEL将自定义标题添加到excel列

我正在使用PHPEXCEL将一个while循环的值写入Excel工作表。 在这样做,我需要为每个行写一个标题。 我现在只能得到的是数据库的结果,我如何添加一个自定义标题

例如
超级联赛
EVENTTID STARTDATE STATUS
1022 17-09-2013韩元

超级联赛
EVENTTID STARTDATE STATUS
3421 22-10-2012输了

这是我的代码

<?php mysql_connect("localhost", "root", ""); mysql_select_db("test2"); $sql=mysql_query("select * from event"); error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); date_default_timezone_set('Europe/London'); require_once '../Classes/PHPExcel.php'; $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex(0); $rowCount = 1; while($row = mysql_fetch_array($sql)){ $objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount, $row['EventID']); $objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount, $row['StartDate']); $objPHPExcel->getActiveSheet()->SetCellValue('C'.$rowCount, $row['Status']); $rowCount++; } // Redirect output to a client's web browser (Excel5) header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="01simple.xls"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header ('Last-Modified: '.gmdate('D, d MYH:i:s').' GMT'); // always modified header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header ('Pragma: public'); // HTTP/1.0 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; 

像这样的东西:

 $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex(0); $rowCount = 1; $customTitle = array ('test a','test b','test c'); $objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount, $customTitle[0]); $objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount, $customTitle[1]); $objPHPExcel->getActiveSheet()->SetCellValue('C'.$rowCount, $customTitle[2]); $rowCount++; while($row = mysql_fetch_array($sql)){ $objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount, $row['EventID']); $objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount, $row['StartDate']); $objPHPExcel->getActiveSheet()->SetCellValue('C'.$rowCount, $row['Status']); $rowCount++; }