Question

I'm trying to create a table using PHPPowerpoint. I'm facing a problem while dealing with merging of table cells which is as follows:

$arr = array('TNS', 'Hard Reserach', 'Kadence', 'RSMRS', 'Sharp', 'Hansa', 'Market Excel');

$shape = $currentSlide->createTableShape(26);
$row = $shape->createRow();
$row->nextCell()->createTextRun('Base')->getFont()->setBold(true)->setSize(14);
$row->nextCell()->createTextRun('')->getFont()->setBold(true)->setSize(14);
$row->nextCell()->setColSpan(3)->createTextRun('All')->getFont()->setBold(true)->setSize(14);

foreach($arr as $name)
{
$row->nextCell()->setColSpan(3)->createTextRun($name)->getFont()->setBold(true)->setSize(14);   
}
$row = $shape->createRow();

This is what I'm getting

Current

This is what I'm looking for

Expected

On thing I observed is that only the 3rd and 6th element of $arr are being printed out. Could this be due to the setColSpan attribute of 3 (multiples of 3 get printed)? If yes, how do I go about it?

Was it helpful?

Solution

Nevermind. I figured it out myself. In case someone else is looking for the same solution, here is how it's done. Slight modification needs to be done which is:

Change

$row->nextCell()->setColSpan(3)->createTextRun('All')->getFont()->setBold(true)->setSize(14);

to

$row->nextCell()->setColSpan(3)->createTextRun('All')->getFont()->setBold(true)->setSize(14);
$row->nextCell()->createTextRun('');
$row->nextCell()->createTextRun('');

and change

$row->nextCell()->setColSpan(3)->createTextRun($name)->getFont()->setBold(true)->setSize(14);

to

$row->$nextCell()->setColSpan(3)->createTextRun($name)->getFont()->setBold(true)->setSize(14);
$row->nextCell()->createTextRun('');
$row->nextCell()->createTextRun('');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top