Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP-Spreadsheet: First Row Bold

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.

like image 241
Silvan Kisseleff Avatar asked Jan 08 '19 08:01

Silvan Kisseleff


People also ask

How do I make text bold in Excel using PHP?

The setBold() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set the boldness of the text.

How do I change font size in PHPExcel?

$objPHPExcel->getActiveSheet()->getStyle("F1:G1")->getFont()->setFontSize(16);

How do I download PhpSpreadsheet?

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.

How do I merge cells in Excel using PHPExcel?

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');


1 Answers

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);
like image 89
Silvan Kisseleff Avatar answered Sep 17 '22 14:09

Silvan Kisseleff