Neha Dangui
Neha Dangui

Reputation: 647

PhpExcel: center align text in a single cell in a set of merged cells

I am using PHPExcel to create a xls file. I have merged the cells (B2:E2), but I want the text entered in B2 to be horizantally center aligned in the B2 cell only. It gets center aligned in the merged cell.

$sheet_obj->getStyle('B2')->getAlignment()->setHorizontal(
    PHPExcel_Style_Alignment::HORIZONTAL_CENTER
);

Upvotes: 7

Views: 19958

Answers (1)

Jay Borkhetariya
Jay Borkhetariya

Reputation: 86

hope this helps

$sheet_obj->getActiveSheet()->getStyle('G2') ->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);

Upvotes: 5

Related Questions