Ejemplo n.º 1
0
 /**
  * Get hash code
  *
  * @return string Hash code
  */
 public function getHashCode()
 {
     $hashConditionals = '';
     foreach ($this->conditionalStyles as $conditional) {
         $hashConditionals .= $conditional->getHashCode();
     }
     return md5($this->fill->getHashCode() . $this->font->getHashCode() . $this->borders->getHashCode() . $this->alignment->getHashCode() . $this->numberFormat->getHashCode() . $hashConditionals . $this->protection->getHashCode() . ($this->quotePrefix ? 't' : 'f') . __CLASS__);
 }
Ejemplo n.º 2
0
 /**
  * Create array from a range of cells
  *
  * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
  * @param mixed $nullValue Value returned in the array entry if a cell doesn't exist
  * @param boolean $calculateFormulas Should formulas be calculated?
  * @param boolean $formatData Should formatting be applied to cell values?
  * @param boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero
  *                               True - Return rows and columns indexed by their actual row and column IDs
  * @return array
  */
 public function rangeToArray($pRange = 'A1', $nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false)
 {
     // Returnvalue
     $returnValue = array();
     //    Identify the range that we need to extract from the worksheet
     list($rangeStart, $rangeEnd) = Cell::rangeBoundaries($pRange);
     $minCol = Cell::stringFromColumnIndex($rangeStart[0] - 1);
     $minRow = $rangeStart[1];
     $maxCol = Cell::stringFromColumnIndex($rangeEnd[0] - 1);
     $maxRow = $rangeEnd[1];
     $maxCol++;
     // Loop through rows
     $r = -1;
     for ($row = $minRow; $row <= $maxRow; ++$row) {
         $rRef = $returnCellRef ? $row : ++$r;
         $c = -1;
         // Loop through columns in the current row
         for ($col = $minCol; $col != $maxCol; ++$col) {
             $cRef = $returnCellRef ? $col : ++$c;
             //    Using getCell() will create a new cell if it doesn't already exist. We don't want that to happen
             //        so we test and retrieve directly against cellCollection
             if ($this->cellCollection->isDataSet($col . $row)) {
                 // Cell exists
                 $cell = $this->cellCollection->getCacheData($col . $row);
                 if ($cell->getValue() !== null) {
                     if ($cell->getValue() instanceof RichText) {
                         $returnValue[$rRef][$cRef] = $cell->getValue()->getPlainText();
                     } else {
                         if ($calculateFormulas) {
                             $returnValue[$rRef][$cRef] = $cell->getCalculatedValue();
                         } else {
                             $returnValue[$rRef][$cRef] = $cell->getValue();
                         }
                     }
                     if ($formatData) {
                         $style = $this->parent->getCellXfByIndex($cell->getXfIndex());
                         $returnValue[$rRef][$cRef] = Style\NumberFormat::toFormattedString($returnValue[$rRef][$cRef], $style && $style->getNumberFormat() ? $style->getNumberFormat()->getFormatCode() : Style\NumberFormat::FORMAT_GENERAL);
                     }
                 } else {
                     // Cell holds a NULL
                     $returnValue[$rRef][$cRef] = $nullValue;
                 }
             } else {
                 // Cell doesn't exist
                 $returnValue[$rRef][$cRef] = $nullValue;
             }
         }
     }
     // Return
     return $returnValue;
 }
Ejemplo n.º 3
0
 /**
  *    Get cell value with formatting
  *
  *    @return    string
  */
 public function getFormattedValue()
 {
     return (string) Style\NumberFormat::toFormattedString($this->getCalculatedValue(), $this->getStyle()->getNumberFormat()->getFormatCode());
 }