krot

spout type cell string||bool||number Worksheet:getCellXML

Oct 26th, 2017
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  /**
  2.      * Build and return xml for a single cell.
  3.      *
  4.      * @param int $rowIndex
  5.      * @param int $cellNumber
  6.      * @param mixed $cellValue
  7.      * @param int $styleId
  8.      * @return string
  9.      * @throws InvalidArgumentException If the given value cannot be processed
  10.      */
  11.     protected function getCellXML($rowIndex, $cellNumber, $cellValue, $styleId)
  12.     {
  13.         $columnIndex = CellHelper::getCellIndexFromColumnIndex($cellNumber);
  14.         $cellXML = '<c r="' . $columnIndex . $rowIndex . '"';
  15.         $cellXML .= ' s="' . $styleId . '"';
  16.  
  17.         if (CellHelper::isNonEmptyString($cellValue)) {/* return (gettype($value) === 'string' && $value !== '');*/
  18.             $cellXML .= $this->getCellXMLFragmentForNonEmptyString($cellValue);
  19.         } else if (CellHelper::isBoolean($cellValue)) {
  20.             $cellXML .= ' t="b"><v>' . intval($cellValue) . '</v></c>';
  21.         } else if (CellHelper::isNumeric($cellValue)) {
  22.             $cellXML .= '><v>' . $cellValue . '</v></c>';
  23.         } else if (empty($cellValue)) {
  24.             if ($this->styleHelper->shouldApplyStyleOnEmptyCell($styleId)) {
  25.                 $cellXML .= '/>';
  26.             } else {
  27.                 // don't write empty cells that do no need styling
  28.                 // NOTE: not appending to $cellXML is the right behavior!!
  29.                 $cellXML = '';
  30.             }
  31.         } else {
  32.             throw new InvalidArgumentException('Trying to add a value with an unsupported type: ' . gettype($cellValue));
  33.         }
  34.  
  35.         return $cellXML;
  36.     }
RAW Paste Data