Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

phpexcel

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
);
like image 434
Neha Dangui Avatar asked Jun 02 '15 10:06

Neha Dangui


1 Answers

hope this helps

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

like image 71
Jay Borkhetariya Avatar answered Sep 28 '22 21:09

Jay Borkhetariya