/** * Set the value for a cell, with the explicit data type passed to the method (bypassing any use of the value binder) * * @param mixed $pValue Value * @param string $pDataType Explicit data type * @return PHPExcel_Cell * @throws PHPExcel_Exception */ public function setValueExplicit($pValue = NULL, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING) { // set the value according to data type switch ($pDataType) { case PHPExcel_Cell_DataType::TYPE_STRING2: $pDataType = PHPExcel_Cell_DataType::TYPE_STRING; case PHPExcel_Cell_DataType::TYPE_STRING: case PHPExcel_Cell_DataType::TYPE_NULL: case PHPExcel_Cell_DataType::TYPE_INLINE: $this->_value = PHPExcel_Cell_DataType::checkString($pValue); break; case PHPExcel_Cell_DataType::TYPE_NUMERIC: $this->_value = (double) $pValue; break; case PHPExcel_Cell_DataType::TYPE_FORMULA: $this->_value = (string) $pValue; break; case PHPExcel_Cell_DataType::TYPE_BOOL: $this->_value = (bool) $pValue; break; case PHPExcel_Cell_DataType::TYPE_ERROR: $this->_value = PHPExcel_Cell_DataType::checkErrorCode($pValue); break; default: throw new PHPExcel_Exception('Invalid datatype: ' . $pDataType); break; } // set the datatype $this->_dataType = $pDataType; return $this->notifyCacheController(); }
/** * Get cell value * * Get the value for a specific data type * * @todo Check the actual usefulness of this method * * @param $value * @param string $cellDataType * @return bool|float|mixed|string * @throws Exception */ public function getCellValue($value, $cellDataType = '') { if ($cellDataType == '') { return $value; } switch ($cellDataType) { case PHPExcel_Cell_DataType::TYPE_STRING2: case PHPExcel_Cell_DataType::TYPE_STRING: case PHPExcel_Cell_DataType::TYPE_NULL: case PHPExcel_Cell_DataType::TYPE_INLINE: return PHPExcel_Cell_DataType::checkString($value); case PHPExcel_Cell_DataType::TYPE_NUMERIC: return (double) $value; case PHPExcel_Cell_DataType::TYPE_FORMULA: return '=FORMULA(' . (string) $value . ')'; case PHPExcel_Cell_DataType::TYPE_BOOL: return (bool) $value; case PHPExcel_Cell_DataType::TYPE_ERROR: return PHPExcel_Cell_DataType::checkErrorCode($value); default: throw new Exception('Invalid datatype: ' . $cellDataType); break; } }