Update library PHPExcel to version 1.7.3
This commit is contained in:
@@ -22,28 +22,10 @@
|
||||
* @package PHPExcel_Style
|
||||
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.7.2, 2010-01-11
|
||||
* @version 1.7.3, 2010-05-17
|
||||
*/
|
||||
|
||||
|
||||
/** PHPExcel root directory */
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
|
||||
}
|
||||
|
||||
/** PHPExcel_IComparable */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
|
||||
|
||||
/** PHPExcel_Shared_Date */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Date.php';
|
||||
|
||||
/** PHPExcel_Calculation_Functions */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation/Functions.php';
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Style_NumberFormat
|
||||
*
|
||||
@@ -143,17 +125,17 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
|
||||
private $_parent;
|
||||
|
||||
/**
|
||||
* Create a new PHPExcel_Style_NumberFormat
|
||||
*/
|
||||
public function __construct($isSupervisor = false)
|
||||
{
|
||||
// Supervisor?
|
||||
* Create a new PHPExcel_Style_NumberFormat
|
||||
*/
|
||||
public function __construct($isSupervisor = false)
|
||||
{
|
||||
// Supervisor?
|
||||
$this->_isSupervisor = $isSupervisor;
|
||||
|
||||
// Initialise values
|
||||
$this->_formatCode = PHPExcel_Style_NumberFormat::FORMAT_GENERAL;
|
||||
$this->_builtInFormatCode = 0;
|
||||
}
|
||||
// Initialise values
|
||||
$this->_formatCode = PHPExcel_Style_NumberFormat::FORMAT_GENERAL;
|
||||
$this->_builtInFormatCode = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind parent. Only used for supervisor
|
||||
@@ -230,22 +212,23 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
|
||||
return array('numberformat' => $array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply styles from array
|
||||
*
|
||||
* <code>
|
||||
* $objPHPExcel->getActiveSheet()->getStyle('B2')->getNumberFormat()->applyFromArray(
|
||||
* array(
|
||||
* 'code' => PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE
|
||||
* )
|
||||
* );
|
||||
* </code>
|
||||
*
|
||||
* @param array $pStyles Array containing style information
|
||||
* @throws Exception
|
||||
* @return PHPExcel_Style_NumberFormat
|
||||
*/
|
||||
public function applyFromArray($pStyles = null) {
|
||||
/**
|
||||
* Apply styles from array
|
||||
*
|
||||
* <code>
|
||||
* $objPHPExcel->getActiveSheet()->getStyle('B2')->getNumberFormat()->applyFromArray(
|
||||
* array(
|
||||
* 'code' => PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE
|
||||
* )
|
||||
* );
|
||||
* </code>
|
||||
*
|
||||
* @param array $pStyles Array containing style information
|
||||
* @throws Exception
|
||||
* @return PHPExcel_Style_NumberFormat
|
||||
*/
|
||||
public function applyFromArray($pStyles = null)
|
||||
{
|
||||
if (is_array($pStyles)) {
|
||||
if ($this->_isSupervisor) {
|
||||
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
|
||||
@@ -260,32 +243,34 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Format Code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormatCode() {
|
||||
/**
|
||||
* Get Format Code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormatCode()
|
||||
{
|
||||
if ($this->_isSupervisor) {
|
||||
return $this->getSharedComponent()->getFormatCode();
|
||||
}
|
||||
if ($this->_builtInFormatCode !== false)
|
||||
{
|
||||
return self::builtInFormatCode($this->_builtInFormatCode);
|
||||
}
|
||||
return $this->_formatCode;
|
||||
}
|
||||
if ($this->_builtInFormatCode !== false)
|
||||
{
|
||||
return self::builtInFormatCode($this->_builtInFormatCode);
|
||||
}
|
||||
return $this->_formatCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Format Code
|
||||
*
|
||||
* @param string $pValue
|
||||
* @return PHPExcel_Style_NumberFormat
|
||||
*/
|
||||
public function setFormatCode($pValue = PHPExcel_Style_NumberFormat::FORMAT_GENERAL) {
|
||||
if ($pValue == '') {
|
||||
$pValue = PHPExcel_Style_NumberFormat::FORMAT_GENERAL;
|
||||
}
|
||||
/**
|
||||
* Set Format Code
|
||||
*
|
||||
* @param string $pValue
|
||||
* @return PHPExcel_Style_NumberFormat
|
||||
*/
|
||||
public function setFormatCode($pValue = PHPExcel_Style_NumberFormat::FORMAT_GENERAL)
|
||||
{
|
||||
if ($pValue == '') {
|
||||
$pValue = PHPExcel_Style_NumberFormat::FORMAT_GENERAL;
|
||||
}
|
||||
if ($this->_isSupervisor) {
|
||||
$styleArray = $this->getStyleArray(array('code' => $pValue));
|
||||
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
|
||||
@@ -294,27 +279,29 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
|
||||
$this->_builtInFormatCode = self::builtInFormatCodeIndex($pValue);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Built-In Format Code
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getBuiltInFormatCode() {
|
||||
* Get Built-In Format Code
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getBuiltInFormatCode()
|
||||
{
|
||||
if ($this->_isSupervisor) {
|
||||
return $this->getSharedComponent()->getBuiltInFormatCode();
|
||||
}
|
||||
return $this->_builtInFormatCode;
|
||||
}
|
||||
return $this->_builtInFormatCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Built-In Format Code
|
||||
*
|
||||
* @param int $pValue
|
||||
* @return PHPExcel_Style_NumberFormat
|
||||
*/
|
||||
public function setBuiltInFormatCode($pValue = 0) {
|
||||
/**
|
||||
* Set Built-In Format Code
|
||||
*
|
||||
* @param int $pValue
|
||||
* @return PHPExcel_Style_NumberFormat
|
||||
*/
|
||||
public function setBuiltInFormatCode($pValue = 0)
|
||||
{
|
||||
|
||||
if ($this->_isSupervisor) {
|
||||
$styleArray = $this->getStyleArray(array('code' => self::builtInFormatCode($pValue)));
|
||||
@@ -324,15 +311,15 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
|
||||
$this->_formatCode = self::builtInFormatCode($pValue);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill built-in format codes
|
||||
*/
|
||||
private static function fillBuiltInFormatCodes()
|
||||
{
|
||||
// Built-in format codes
|
||||
if (is_null(self::$_builtInFormats)) {
|
||||
/**
|
||||
* Fill built-in format codes
|
||||
*/
|
||||
private static function fillBuiltInFormatCodes()
|
||||
{
|
||||
// Built-in format codes
|
||||
if (is_null(self::$_builtInFormats)) {
|
||||
self::$_builtInFormats = array();
|
||||
|
||||
// General
|
||||
@@ -388,68 +375,72 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
|
||||
|
||||
// Flip array (for faster lookups)
|
||||
self::$_flippedBuiltInFormats = array_flip(self::$_builtInFormats);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get built-in format code
|
||||
*
|
||||
* @param int $pIndex
|
||||
* @return string
|
||||
*/
|
||||
public static function builtInFormatCode($pIndex) {
|
||||
// Clean parameter
|
||||
/**
|
||||
* Get built-in format code
|
||||
*
|
||||
* @param int $pIndex
|
||||
* @return string
|
||||
*/
|
||||
public static function builtInFormatCode($pIndex)
|
||||
{
|
||||
// Clean parameter
|
||||
$pIndex = intval($pIndex);
|
||||
|
||||
// Ensure built-in format codes are available
|
||||
self::fillBuiltInFormatCodes();
|
||||
self::fillBuiltInFormatCodes();
|
||||
|
||||
// Lookup format code
|
||||
if (array_key_exists($pIndex, self::$_builtInFormats)) {
|
||||
return self::$_builtInFormats[$pIndex];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get built-in format code index
|
||||
*
|
||||
* @param string $formatCode
|
||||
* @return int|boolean
|
||||
*/
|
||||
public static function builtInFormatCodeIndex($formatCode) {
|
||||
// Ensure built-in format codes are available
|
||||
self::fillBuiltInFormatCodes();
|
||||
/**
|
||||
* Get built-in format code index
|
||||
*
|
||||
* @param string $formatCode
|
||||
* @return int|boolean
|
||||
*/
|
||||
public static function builtInFormatCodeIndex($formatCode)
|
||||
{
|
||||
// Ensure built-in format codes are available
|
||||
self::fillBuiltInFormatCodes();
|
||||
|
||||
// Lookup format code
|
||||
if (array_key_exists($formatCode, self::$_flippedBuiltInFormats)) {
|
||||
return self::$_flippedBuiltInFormats[$formatCode];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hash code
|
||||
*
|
||||
* @return string Hash code
|
||||
*/
|
||||
public function getHashCode() {
|
||||
public function getHashCode()
|
||||
{
|
||||
if ($this->_isSupervisor) {
|
||||
return $this->getSharedComponent()->getHashCode();
|
||||
}
|
||||
return md5(
|
||||
$this->_formatCode
|
||||
. $this->_builtInFormatCode
|
||||
. __CLASS__
|
||||
);
|
||||
}
|
||||
return md5(
|
||||
$this->_formatCode
|
||||
. $this->_builtInFormatCode
|
||||
. __CLASS__
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement PHP __clone to create a deep clone, not just a shallow copy.
|
||||
*/
|
||||
public function __clone() {
|
||||
public function __clone()
|
||||
{
|
||||
$vars = get_object_vars($this);
|
||||
foreach ($vars as $key => $value) {
|
||||
if (is_object($value)) {
|
||||
@@ -511,7 +502,8 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
|
||||
* @param array $callBack Callback function for additional formatting of string
|
||||
* @return string Formatted string
|
||||
*/
|
||||
public static function toFormattedString($value = '', $format = '', $callBack = null) {
|
||||
public static function toFormattedString($value = '', $format = '', $callBack = null)
|
||||
{
|
||||
// For now we do not treat strings although section 4 of a format code affects strings
|
||||
if (!is_numeric($value)) return $value;
|
||||
|
||||
@@ -587,7 +579,8 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
|
||||
$format = strtr($format,self::$_dateFormatReplacements12);
|
||||
}
|
||||
|
||||
$value = gmdate($format, PHPExcel_Shared_Date::ExcelToPHP($value));
|
||||
$dateObj = PHPExcel_Shared_Date::ExcelToPHPObject($value);
|
||||
$value = $dateObj->format($format);
|
||||
|
||||
} else if (preg_match('/%$/', $format)) { // % number format
|
||||
if ($format === self::FORMAT_PERCENTAGE) {
|
||||
@@ -606,31 +599,44 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
|
||||
}
|
||||
|
||||
} else {
|
||||
if (preg_match ("/^([0-9.,-]+)$/", $value)) {
|
||||
if ($format === self::FORMAT_CURRENCY_EUR_SIMPLE) {
|
||||
$value = 'EUR ' . sprintf('%1.2f', $value);
|
||||
if ($format === self::FORMAT_CURRENCY_EUR_SIMPLE) {
|
||||
$value = 'EUR ' . sprintf('%1.2f', $value);
|
||||
|
||||
} else {
|
||||
// In Excel formats, "_" is used to add spacing, which we can't do in HTML
|
||||
$format = preg_replace('/_./', '', $format);
|
||||
} else {
|
||||
// In Excel formats, "_" is used to add spacing, which we can't do in HTML
|
||||
$format = preg_replace('/_./', '', $format);
|
||||
|
||||
// Some non-number characters are escaped with \, which we don't need
|
||||
$format = preg_replace("/\\\\/", '', $format);
|
||||
// Some non-number characters are escaped with \, which we don't need
|
||||
$format = preg_replace("/\\\\/", '', $format);
|
||||
|
||||
// Some non-number strings are quoted, so we'll get rid of the quotes
|
||||
$format = preg_replace('/"/', '', $format);
|
||||
// Some non-number strings are quoted, so we'll get rid of the quotes
|
||||
$format = preg_replace('/"/', '', $format);
|
||||
|
||||
// TEMPORARY - Convert # to 0
|
||||
$format = preg_replace('/\\#/', '0', $format);
|
||||
// Find out if we need thousands separator
|
||||
// This is indicated by a comma enclosed by a digit placeholder:
|
||||
// #,# or 0,0
|
||||
$useThousands = preg_match('/(#,#|0,0)/', $format);
|
||||
if ($useThousands) {
|
||||
$format = preg_replace('/0,0/', '00', $format);
|
||||
$format = preg_replace('/#,#/', '##', $format);
|
||||
}
|
||||
|
||||
// Find out if we need thousands separator
|
||||
$useThousands = preg_match('/,/', $format);
|
||||
if ($useThousands) {
|
||||
$format = preg_replace('/,/', '', $format);
|
||||
}
|
||||
// Scale thousands, millions,...
|
||||
// This is indicated by a number of commas after a digit placeholder:
|
||||
// #, or 0.0,,
|
||||
$scale = 1; // same as no scale
|
||||
$matches = array();
|
||||
if (preg_match('/(#|0)(,+)/', $format, $matches)) {
|
||||
$scale = pow(1000, strlen($matches[2]));
|
||||
|
||||
if (preg_match('/0?.*\?\/\?/', $format, $m)) {
|
||||
//echo 'Format mask is fractional '.$format.' <br />';
|
||||
// strip the commas
|
||||
$format = preg_replace('/0,+/', '0', $format);
|
||||
$format = preg_replace('/#,+/', '#', $format);
|
||||
}
|
||||
|
||||
if (preg_match('/#?.*\?\/\?/', $format, $m)) {
|
||||
//echo 'Format mask is fractional '.$format.' <br />';
|
||||
if ($value != (int)$value) {
|
||||
$sign = ($value < 0) ? '-' : '';
|
||||
|
||||
$integerPart = floor(abs($value));
|
||||
@@ -650,28 +656,41 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
|
||||
$adjustedDecimalPart += $integerPart * $adjustedDecimalDivisor;
|
||||
$value = "$sign$adjustedDecimalPart/$adjustedDecimalDivisor";
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Handle the number itself
|
||||
$number_regex = "/(\d+)(\.?)(\d*)/";
|
||||
if (preg_match($number_regex, $format, $matches)) {
|
||||
$left = $matches[1];
|
||||
$dec = $matches[2];
|
||||
$right = $matches[3];
|
||||
if ($useThousands) {
|
||||
$value = number_format(
|
||||
$value
|
||||
, strlen($right)
|
||||
, PHPExcel_Shared_String::getDecimalSeparator()
|
||||
, PHPExcel_Shared_String::getThousandsSeparator()
|
||||
);
|
||||
} else {
|
||||
// Handle the number itself
|
||||
|
||||
} else {
|
||||
$sprintf_pattern = "%1." . strlen($right) . "f";
|
||||
$value = sprintf($sprintf_pattern, $value);
|
||||
}
|
||||
$value = preg_replace($number_regex, $value, $format);
|
||||
// scale number
|
||||
$value = $value / $scale;
|
||||
|
||||
// Strip #
|
||||
$format = preg_replace('/\\#/', '', $format);
|
||||
|
||||
$number_regex = "/(0+)(\.?)(0*)/";
|
||||
$matches = array();
|
||||
if (preg_match($number_regex, $format, $matches)) {
|
||||
$left = $matches[1];
|
||||
$dec = $matches[2];
|
||||
$right = $matches[3];
|
||||
|
||||
// minimun width of formatted number (including dot)
|
||||
$minWidth = strlen($left) + strlen($dec) + strlen($right);
|
||||
|
||||
if ($useThousands) {
|
||||
$value = number_format(
|
||||
$value
|
||||
, strlen($right)
|
||||
, PHPExcel_Shared_String::getDecimalSeparator()
|
||||
, PHPExcel_Shared_String::getThousandsSeparator()
|
||||
);
|
||||
|
||||
} else {
|
||||
$sprintf_pattern = "%0$minWidth." . strlen($right) . "f";
|
||||
$value = sprintf($sprintf_pattern, $value);
|
||||
}
|
||||
|
||||
$value = preg_replace($number_regex, $value, $format);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -685,4 +704,5 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user