PHPExcel — Color part of XLSX table

To colour the rows:

$objPHPExcel->getActiveSheet()->getStyle('A1000:IV2000')
    ->getFill()
    ->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('A1000:IV2000')
    ->getFill()
    ->getStartColor()->setARGB(PHPExcel_Style_Color::COLOR_BLUE);

To format dates:

Make sure that you’re setting your date values as an Excel serialized timestamp

$myDate = "21/12/2014 15:08:23";
$myDateValue = DateTime::createFromFormat('d/m/Y H:i:s', $myDate);
$excelTimeStamp = PHPExcel_Shared_Date::PHPToExcel($myDateValue);

$objPHPExcel->getActiveSheet()
    ->setCellValue('A1', $excelTimeStamp);
$objPHPExcel->getActiveSheet()
    ->getStyle('C9')
    ->getNumberFormat()
    ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY);

All of this is covered in the documentation and in the examples provided with the PHPExcel package

Leave a Comment