Exemplo n.º 1
0
 /**
  * Get an instance of this class
  *
  * @return ReferenceHelper
  */
 public static function getInstance()
 {
     if (!isset(self::$_instance) || is_null(self::$_instance)) {
         self::$_instance = new ReferenceHelper();
     }
     return self::$_instance;
 }
Exemplo n.º 2
0
 private function _castToFormula($c, $r, &$cellDataType, &$value, &$calculatedValue, &$sharedFormulas, $castBaseType)
 {
     //		echo '<font color="darkgreen">Formula</font><br />';
     //		echo '$c->f is '.$c->f.'<br />';
     $cellDataType = 'f';
     $value = "={$c->f}";
     $calculatedValue = $this->{$castBaseType}($c);
     // Shared formula?
     if (isset($c->f['t']) && strtolower((string) $c->f['t']) == 'shared') {
         //			echo '<font color="darkgreen">SHARED FORMULA</font><br />';
         $instance = (string) $c->f['si'];
         //			echo 'Instance ID = '.$instance.'<br />';
         //
         //			echo 'Shared Formula Array:<pre>';
         //			print_r($sharedFormulas);
         //			echo '</pre>';
         if (!isset($sharedFormulas[(string) $c->f['si']])) {
             //				echo '<font color="darkgreen">SETTING NEW SHARED FORMULA</font><br />';
             //				echo 'Master is '.$r.'<br />';
             //				echo 'Formula is '.$value.'<br />';
             $sharedFormulas[$instance] = array('master' => $r, 'formula' => $value);
             //				echo 'New Shared Formula Array:<pre>';
             //				print_r($sharedFormulas);
             //				echo '</pre>';
         } else {
             //				echo '<font color="darkgreen">GETTING SHARED FORMULA</font><br />';
             //				echo 'Master is '.$sharedFormulas[$instance]['master'].'<br />';
             //				echo 'Formula is '.$sharedFormulas[$instance]['formula'].'<br />';
             $master = Cell::coordinateFromString($sharedFormulas[$instance]['master']);
             $current = Cell::coordinateFromString($r);
             $difference = array(0, 0);
             $difference[0] = Cell::columnIndexFromString($current[0]) - Cell::columnIndexFromString($master[0]);
             $difference[1] = $current[1] - $master[1];
             $helper = ReferenceHelper::getInstance();
             $value = $helper->updateFormulaReferences($sharedFormulas[$instance]['formula'], 'A1', $difference[0], $difference[1]);
             //				echo 'Adjusted Formula is '.$value.'<br />';
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Set name
  *
  * @param string $value
  * @return NamedRange
  */
 public function setName($value = null)
 {
     if (!is_null($value)) {
         // Old title
         $oldTitle = $this->_name;
         // Re-attach
         if (!is_null($this->_worksheet)) {
             $this->_worksheet->getParent()->removeNamedRange($this->_name, $this->_worksheet);
         }
         $this->_name = $value;
         if (!is_null($this->_worksheet)) {
             $this->_worksheet->getParent()->addNamedRange($this);
         }
         // New title
         $newTitle = $this->_name;
         ReferenceHelper::getInstance()->updateNamedFormulas($this->_worksheet->getParent(), $oldTitle, $newTitle);
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Remove a column, updating all possible related data
  *
  * @param 	int	$pColumn	Remove starting with this one
  * @param 	int	$pNumCols	Number of columns to remove
  * @throws 	Exception
  * @return Worksheet
  */
 public function removeColumn($pColumn = 'A', $pNumCols = 1)
 {
     if (!is_numeric($pColumn)) {
         $pColumn = Cell::stringFromColumnIndex(Cell::columnIndexFromString($pColumn) - 1 + $pNumCols);
         $objReferenceHelper = ReferenceHelper::getInstance();
         $objReferenceHelper->insertNewBefore($pColumn . '1', -$pNumCols, 0, $this);
     } else {
         throw new Exception("Column references should not be numeric.");
     }
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Remove a column, updating all possible related data
  *
  * @param string    $pColumn     Remove starting with this one
  * @param int       $pNumCols    Number of columns to remove
  * @throws    Exception
  * @return Worksheet
  */
 public function removeColumn($pColumn = 'A', $pNumCols = 1)
 {
     if (!is_numeric($pColumn)) {
         $highestColumn = $this->getHighestDataColumn();
         $pColumn = Cell::stringFromColumnIndex(Cell::columnIndexFromString($pColumn) - 1 + $pNumCols);
         $objReferenceHelper = ReferenceHelper::getInstance();
         $objReferenceHelper->insertNewBefore($pColumn . '1', -$pNumCols, 0, $this);
         for ($c = 0; $c < $pNumCols; ++$c) {
             $this->getCellCacheController()->removeColumn($highestColumn);
             $highestColumn = Cell::stringFromColumnIndex(Cell::columnIndexFromString($highestColumn) - 2);
         }
     } else {
         throw new Exception("Column references should not be numeric.");
     }
     return $this;
 }