code: private function writeDefinedNameForPrintTitles(XMLWriter $objWriter, Worksheet $pSheet, $pSheetId = 0)
      {
          // definedName for PrintTitles
          if ($pSheet->getPageSetup()->isColumnsToRepeatAtLeftSet() || $pSheet->getPageSetup()->isRowsToRepeatAtTopSet()) {
              $objWriter->startElement('definedName');
              $objWriter->writeAttribute('name', '_xlnm.Print_Titles');
              $objWriter->writeAttribute('localSheetId', $pSheetId);
  
              // Setting string
              $settingString = '';
  
              // Columns to repeat
              if ($pSheet->getPageSetup()->isColumnsToRepeatAtLeftSet()) {
                  $repeat = $pSheet->getPageSetup()->getColumnsToRepeatAtLeft();
  
                  $settingString .= '\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!$' . $repeat[0] . ':$' . $repeat[1];
              }
  
              // Rows to repeat
              if ($pSheet->getPageSetup()->isRowsToRepeatAtTopSet()) {
                  if ($pSheet->getPageSetup()->isColumnsToRepeatAtLeftSet()) {
                      $settingString .= ',';
                  }
  
                  $repeat = $pSheet->getPageSetup()->getRowsToRepeatAtTop();
  
                  $settingString .= '\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!$' . $repeat[0] . ':$' . $repeat[1];
              }
  
              $objWriter->writeRawData($settingString);
  
              $objWriter->endElement();
          }
      }
docs: Write Defined Name for PrintTitles.
  
  @param XMLWriter $objWriter XML Writer
  @param Worksheet $pSheet
  @param int $pSheetId