PHPPowerpoint and setColspan issue

Nov 25, 2013 at 12:42 PM
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();

What I'm getting

Image

What I'm looking for

Image


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?
Oct 9, 2014 at 7:40 AM
Edited Oct 9, 2014 at 7:41 AM
I have been fail into this issue.
And after checking the raw xml I found that we may misunderstanding of the ooxml's table, It's not similar to html's table
in detail, for every cols/rowspan, the cells being merged is always need to be available
sample
In HTML/your code, it's
<tr>
<td colspan="3">Merge A</td>
<td colspan="3">Merge B</td>
</tr>
<tr>
<td>A1</td><td>A2</td><td>A3</td>
<td>B1</td><td>B2</td><td>B3</td>
</tr>

But in OOXML, it'll be similar to:
<tr>
<td colspan="3">Merge A</td><td></td><td></td> <!-- those 2 empty td/cell will being spanned -->
<td colspan="3">Merge B</td><td></td><td></td> <!-- those 2 empty td/cell will being spanned -->
</tr>
<tr>
<td>A1</td><td>A2</td><td>A3</td>
<td>B1</td><td>B2</td><td>B3</td>
</tr>


In summary, you need some extra $row->nextCell() in your code, place it in the correct position will do the magic