You are here

public function PHPExcel_Worksheet::setTitle in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Worksheet.php \PHPExcel_Worksheet::setTitle()

Set title

Parameters

string $pValue String containing the dimension of this worksheet:

string $updateFormulaCellReferences boolean Flag indicating whether cell references in formulae should: be updated to reflect the new sheet name. This should be left as the default true, unless you are certain that no formula cells on any worksheet contain references to this worksheet

Return value

PHPExcel_Worksheet

1 call to PHPExcel_Worksheet::setTitle()
PHPExcel_Worksheet::__construct in vendor/phpoffice/phpexcel/Classes/PHPExcel/Worksheet.php
Create a new worksheet

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Worksheet.php, line 833

Class

PHPExcel_Worksheet
PHPExcel_Worksheet

Code

public function setTitle($pValue = 'Worksheet', $updateFormulaCellReferences = true) {

  // Is this a 'rename' or not?
  if ($this
    ->getTitle() == $pValue) {
    return $this;
  }

  // Syntax check
  self::_checkSheetTitle($pValue);

  // Old title
  $oldTitle = $this
    ->getTitle();
  if ($this->_parent) {

    // Is there already such sheet name?
    if ($this->_parent
      ->sheetNameExists($pValue)) {

      // Use name, but append with lowest possible integer
      if (PHPExcel_Shared_String::CountCharacters($pValue) > 29) {
        $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 29);
      }
      $i = 1;
      while ($this->_parent
        ->sheetNameExists($pValue . ' ' . $i)) {
        ++$i;
        if ($i == 10) {
          if (PHPExcel_Shared_String::CountCharacters($pValue) > 28) {
            $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 28);
          }
        }
        elseif ($i == 100) {
          if (PHPExcel_Shared_String::CountCharacters($pValue) > 27) {
            $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 27);
          }
        }
      }
      $altTitle = $pValue . ' ' . $i;
      return $this
        ->setTitle($altTitle, $updateFormulaCellReferences);
    }
  }

  // Set title
  $this->_title = $pValue;
  $this->_dirty = true;
  if ($this->_parent) {

    // New title
    $newTitle = $this
      ->getTitle();
    PHPExcel_Calculation::getInstance($this->_parent)
      ->renameCalculationCacheForWorksheet($oldTitle, $newTitle);
    if ($updateFormulaCellReferences) {
      PHPExcel_ReferenceHelper::getInstance()
        ->updateNamedFormulas($this->_parent, $oldTitle, $newTitle);
    }
  }
  return $this;
}