Writing text between merged cells using phpExcel

I have this code from phpExel.

$objPHPExcel->setActiveSheetIndex(1)->mergeCells('A1:I1');

      

This code creates white space between columns A1-I1. Just add some text in the white center space (A1: I1).

I am trying to use this code:

$objPHPExcel->setActiveSheetIndex(1)->mergeCells('A1:I1','add some text here...');

      

but this code doesn't work. Can anyone help me?

+3


source to share


1 answer


You just write the text value you want to the top left cell in the range of merged cells

$objPHPExcel->setActiveSheetIndex(1)
    ->mergeCells('A1:I1');
$objPHPExcel->getActiveSheet()
    ->getCell('A1')
    ->setValue('This is the text that I want to see in the merged cells');

      

EDIT



To center the text use

$objPHPExcel->getActiveSheet()
    ->getStyle('A1')
    ->getAlignment()
    ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

      

using the top left cell of the range

+5


source







All Articles