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('');