code: private function writeCellMerge(XMLWriter $objWriter, Cell $cell)
      {
          if (!$cell->isMergeRangeValueCell()) {
              return;
          }
  
          $mergeRange = Coordinate::splitRange($cell->getMergeRange());
          list($startCell, $endCell) = $mergeRange[0];
          $start = Coordinate::coordinateFromString($startCell);
          $end = Coordinate::coordinateFromString($endCell);
          $columnSpan = Coordinate::columnIndexFromString($end[0]) - Coordinate::columnIndexFromString($start[0]) + 1;
          $rowSpan = $end[1] - $start[1] + 1;
  
          $objWriter->writeAttribute('table:number-columns-spanned', $columnSpan);
          $objWriter->writeAttribute('table:number-rows-spanned', $rowSpan);
      }
docs: Write attributes for merged cell.
  
  @param XMLWriter $objWriter
  @param Cell $cell
  
  @throws \PhpOffice\PhpSpreadsheet\Exception