Because PHP-Excel is deprecated, PHP-Spreadsheet is the new Option to make Excel in PHP. The Documentation is not the best and the're not many questions on Stackoverflow about PHP-Spreadsheet, so that's why I make this Question about how to make the first row bold in PHP-Spreadsheet.
The setBold() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set the boldness of the text.
$objPHPExcel->getActiveSheet()->getStyle("F1:G1")->getFont()->setFontSize(16);
Use composer to install PhpSpreadsheet into your project. Or also download the documentation and samples if you plan to use them. A good way to get started is to run some of the samples. Don't forget to download them via --prefer-source composer flag.
In code it would look a little something like this: $workbook = new PHPExcel; $sheet = $workbook->getActiveSheet(); $sheet->setCellValue('A1','A pretty long sentence that deserves to be in a merged cell');
This should do the trick.
//Create Spreadsheet
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
//Create Styles Array
$styleArrayFirstRow = [
'font' => [
'bold' => true,
]
];
//Retrieve Highest Column (e.g AE)
$highestColumn = $sheet->getHighestColumn();
//set first row bold
$sheet->getStyle('A1:' . $highestColumn . '1' )->applyFromArray($styleArrayFirstRow);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With