Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge and center cells in phpspreadsheet

im searching for hours in doc but got nothing to merge and horizontal center..

anyone can help me how to do this?

my last code :

$spreadsheet = new Spreadsheet();
$excel = $spreadsheet->getActiveSheet();
$spreadsheet->getProperties()->setTitle($name_sheet)->setCreator('Creator');

$excel->mergeCells('A1:W1');
$excel->mergeCells('A2:W2');
$excel->mergeCells('A3:W3');

//how to make cells A1 till W1 to be centered cell?
like image 390
MUH. ISA S Avatar asked Nov 15 '25 08:11

MUH. ISA S


1 Answers

At the begin of your page : use PhpOffice\PhpSpreadsheet\Style\Alignment;

Definition of the center alignment : $excel->getStyle('A1:W1')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);

like image 145
Ki Mi Avatar answered Nov 18 '25 09:11

Ki Mi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!