You are here

public function PHPExcel_Worksheet::setCodeName 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::setCodeName()

* Define the code name of the sheet * *

Parameters

null|string Same rule as Title minus space not allowed (but, like Excel, change silently space to underscore): * @return objWorksheet * @throws PHPExcel_Exception

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

File

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

Class

PHPExcel_Worksheet
PHPExcel_Worksheet

Code

public function setCodeName($pValue = null) {

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

  //Excel does this automatically without flinching, we are doing the same

  // Syntax check
  // throw an exception if not valid
  self::_checkSheetCodeName($pValue);

  // We use the same code that setTitle to find a valid codeName else not using a space (Excel don't like) but a '_'
  if ($this
    ->getParent()) {

    // Is there already such sheet name?
    if ($this
      ->getParent()
      ->sheetCodeNameExists($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
        ->getParent()
        ->sheetCodeNameExists($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);
          }
        }
      }
      $pValue = $pValue . '_' . $i;

      // ok, we have a valid name

      //codeName is'nt used in formula : no need to call for an update

      //return $this->setTitle($altTitle,$updateFormulaCellReferences);
    }
  }
  $this->_codeName = $pValue;
  return $this;
}