Skip to content

Instantly share code, notes, and snippets.

@ctrl-f5
Created January 4, 2016 13:39
Show Gist options
  • Save ctrl-f5/e2ae65c4e87b3c1a54f5 to your computer and use it in GitHub Desktop.
Save ctrl-f5/e2ae65c4e87b3c1a54f5 to your computer and use it in GitHub Desktop.
PHPOffice/PHPExcel cell styling
<?php
$excel = new \PHPExcel();
$sheet = $excel->getActiveSheet();
$sheet->getCell('A1')->setValue('test');
$style = new \PHPExcel_Style();
$style
->getFill()
->setStartColor(new \PHPExcel_Style_Color(\PHPExcel_Style_Color::COLOR_RED))
->setEndColor(new \PHPExcel_Style_Color(\PHPExcel_Style_Color::COLOR_RED))
->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)
;
$style
->getFont()
->setBold(true)
->setColor(new \PHPExcel_Style_Color(\PHPExcel_Style_Color::COLOR_YELLOW))
->setItalic(true)
->setUnderline(true)
->setSize(20);
$sheet->duplicateStyle($style, 'A1');
$writer = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$writer->save('/tmp/test.xlsx');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment