Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel Make first row bold

Tags:

php

phpexcel

I am trying to make cells in first row are bold.

This is the method I have created for that purpose.

function ExportToExcel($tittles,$excel_name)  {   $objPHPExcel = new PHPExcel();   $objRichText = new PHPExcel_RichText();   // Set properties   $objPHPExcel->getProperties()->setCreator("SAMPLE1");   $objPHPExcel->getProperties()->setLastModifiedBy("SAMPLE1");   $objPHPExcel->getProperties()->setTitle("SAMPLE1");   $objPHPExcel->getProperties()->setSubject("SAMPLE1");   $objPHPExcel->getProperties()->setDescription("SAMPLE1");     // Add some data   $objPHPExcel->setActiveSheetIndex(0);    $letters = range('A','Z');   $count =0;   $cell_name="";   foreach($tittles as $tittle)   {    $cell_name = $letters[$count]."1";    $count++;    $value = $tittle;    $objPHPExcel->getActiveSheet()->SetCellValue($cell_name, $value);    // Make bold cells    $objPHPExcel->getActiveSheet()->getStyle($cell_name)->getFont()->setBold(true);   }   // Save Excel 2007 file   $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);   //$objWriter->save(str_replace('.php', '.xlsx', __FILE__));   $objWriter->save($excel_name.".xlsx");  } 

The problem is in output excel file the cells are not bold.

like image 649
Rakesh Avatar asked Feb 07 '13 08:02

Rakesh


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 text color in phpExcel?

I'm beginner. When I'm using following code and its working fine. $phpExcel = new PHPExcel(); $phpExcel->getActiveSheet()->getStyle("A1")->getFont()->setBold(true) ->setName('Verdana') ->setSize(10) ->getColor()->setRGB('6F6F6F');

How do I change font size in phpExcel?

This is what I tried: $objPHPExcel->getActiveSheet()->getStyle("F1:G1")->getFont()->setFontSize(16);


2 Answers

Try this for range of cells:

$from = "A1"; // or any value $to = "B5"; // or any value $objPHPExcel->getActiveSheet()->getStyle("$from:$to")->getFont()->setBold( true ); 

or single cell

$cell_name = "A1"; $objPHPExcel->getActiveSheet()->getStyle( $cell_name )->getFont()->setBold( true ); 

hope that helps

like image 75
Ali Mezal Avatar answered Sep 20 '22 08:09

Ali Mezal


Try this

$objPHPExcel->getActiveSheet()->getStyle('A1:D1')->getFont()->setBold(true); 
like image 28
Sadikhasan Avatar answered Sep 20 '22 08:09

Sadikhasan