diff --git a/Classes/PHPExcel/Calculation/DateTime.php b/Classes/PHPExcel/Calculation/DateTime.php index 9e7257e..59aae40 100644 --- a/Classes/PHPExcel/Calculation/DateTime.php +++ b/Classes/PHPExcel/Calculation/DateTime.php @@ -549,6 +549,8 @@ class PHPExcel_Calculation_DateTime { if ($retVal < 0) { $retVal += 365; } } break; + default: + $retVal = PHPExcel_Calculation_Functions::NaN(); } return $retVal; } // function DATEDIF() @@ -753,7 +755,7 @@ class PHPExcel_Calculation_DateTime { public static function WORKDAY($startDate,$endDays) { // Retrieve the mandatory start date and days that are referenced in the function definition $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate); - $endDays = (int) PHPExcel_Calculation_Functions::flattenSingleValue($endDays); + $endDays = PHPExcel_Calculation_Functions::flattenSingleValue($endDays); // Flush the mandatory start date and days that are referenced in the function definition, and get the optional days $dateArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); array_shift($dateArgs); @@ -763,6 +765,7 @@ class PHPExcel_Calculation_DateTime { return PHPExcel_Calculation_Functions::VALUE(); } $startDate = (float) floor($startDate); + $endDays = (int) floor($endDays); // If endDays is 0, we always return startDate if ($endDays == 0) { return $startDate; } diff --git a/Classes/PHPExcel/Calculation/Functions.php b/Classes/PHPExcel/Calculation/Functions.php index 22cb633..2e80b83 100644 --- a/Classes/PHPExcel/Calculation/Functions.php +++ b/Classes/PHPExcel/Calculation/Functions.php @@ -750,6 +750,12 @@ if (!function_exists('money_format')) { } $space = $locale["{$letter}_sep_by_space"] ? ' ' : ''; + if (!isset($locale['mon_decimal_point']) || empty($locale['mon_decimal_point'])) { + $locale['mon_decimal_point'] = (!isset($locale['decimal_point']) || empty($locale['decimal_point'])) ? + $locale['decimal_point'] : + '.'; + } + $number = number_format($number, $right, $locale['mon_decimal_point'], $flags['nogroup'] ? '' : $locale['mon_thousands_sep'] ); $number = explode($locale['mon_decimal_point'], $number); diff --git a/Classes/PHPExcel/Calculation/MathTrig.php b/Classes/PHPExcel/Calculation/MathTrig.php index a2a4ae7..a3fd92e 100644 --- a/Classes/PHPExcel/Calculation/MathTrig.php +++ b/Classes/PHPExcel/Calculation/MathTrig.php @@ -798,11 +798,12 @@ class PHPExcel_Calculation_MathTrig { public static function ROMAN($aValue, $style=0) { - $aValue = (integer) PHPExcel_Calculation_Functions::flattenSingleValue($aValue); + $aValue = PHPExcel_Calculation_Functions::flattenSingleValue($aValue); $style = (is_null($style)) ? 0 : (integer) PHPExcel_Calculation_Functions::flattenSingleValue($style); if ((!is_numeric($aValue)) || ($aValue < 0) || ($aValue >= 4000)) { return PHPExcel_Calculation_Functions::VALUE(); } + $aValue = (integer) $aValue; if ($aValue == 0) { return ''; } @@ -839,7 +840,7 @@ class PHPExcel_Calculation_MathTrig { $digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits); if ((is_numeric($number)) && (is_numeric($digits))) { - $significance = pow(10,$digits); + $significance = pow(10,(int) $digits); if ($number < 0.0) { return floor($number * $significance) / $significance; } else { @@ -864,7 +865,7 @@ class PHPExcel_Calculation_MathTrig { $digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits); if ((is_numeric($number)) && (is_numeric($digits))) { - $significance = pow(10,$digits); + $significance = pow(10,(int) $digits); if ($number < 0.0) { return ceil($number * $significance) / $significance; } else { diff --git a/Classes/PHPExcel/Calculation/TextData.php b/Classes/PHPExcel/Calculation/TextData.php index 2e676fc..d23bf9c 100644 --- a/Classes/PHPExcel/Calculation/TextData.php +++ b/Classes/PHPExcel/Calculation/TextData.php @@ -96,7 +96,7 @@ class PHPExcel_Calculation_TextData { $stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue); if (is_bool($stringValue)) { - $stringValue = ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); + return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); } if (self::$_invalidChars == Null) { @@ -106,7 +106,7 @@ class PHPExcel_Calculation_TextData { if (is_string($stringValue) || is_numeric($stringValue)) { return str_replace(self::$_invalidChars,'',trim($stringValue,"\x00..\x1F")); } - return Null; + return NULL; } // function TRIMNONPRINTABLE() @@ -119,10 +119,14 @@ class PHPExcel_Calculation_TextData { public static function TRIMSPACES($stringValue = '') { $stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue); - if (is_string($stringValue) || is_numeric($stringValue)) { - return trim(preg_replace('/ +/',' ',$stringValue)); + if (is_bool($stringValue)) { + return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); } - return Null; + + if (is_string($stringValue) || is_numeric($stringValue)) { + return trim(preg_replace('/ +/',' ',trim($stringValue,' '))); + } + return NULL; } // function TRIMSPACES() @@ -133,6 +137,8 @@ class PHPExcel_Calculation_TextData { * @return int */ public static function ASCIICODE($characters) { + if (($characters === NULL) || ($characters === '')) + return PHPExcel_Calculation_Functions::VALUE(); $characters = PHPExcel_Calculation_Functions::flattenSingleValue($characters); if (is_bool($characters)) { if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { @@ -287,10 +293,16 @@ class PHPExcel_Calculation_TextData { * @param mixed $value Value to check * @return boolean */ - public static function FIXEDFORMAT($value,$decimals=2,$no_commas=false) { + public static function FIXEDFORMAT($value, $decimals = 2, $no_commas = FALSE) { $value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $decimals = PHPExcel_Calculation_Functions::flattenSingleValue($decimals); - $no_commas = PHPExcel_Calculation_Functions::flattenSingleValue($no_commas); + $no_commas = PHPExcel_Calculation_Functions::flattenSingleValue($no_commas); + + // Validate parameters + if (!is_numeric($value) || !is_numeric($decimals)) { + return PHPExcel_Calculation_Functions::NaN(); + } + $decimals = floor($decimals); $valueResult = round($value,$decimals); if ($decimals < 0) { $decimals = 0; } @@ -540,7 +552,7 @@ class PHPExcel_Calculation_TextData { } } - return $left.$newText.$right; + return $text; } // function SUBSTITUTE() diff --git a/Classes/PHPExcel/Shared/Date.php b/Classes/PHPExcel/Shared/Date.php index 111b479..41085b6 100644 --- a/Classes/PHPExcel/Shared/Date.php +++ b/Classes/PHPExcel/Shared/Date.php @@ -40,6 +40,20 @@ class PHPExcel_Shared_Date const CALENDAR_WINDOWS_1900 = 1900; // Base date of 1st Jan 1900 = 1.0 const CALENDAR_MAC_1904 = 1904; // Base date of 2nd Jan 1904 = 1.0 + public static $_monthNames = array( 'Jan' => 'January', + 'Feb' => 'February', + 'Mar' => 'March', + 'Apr' => 'April', + 'May' => 'May', + 'Jun' => 'June', + 'Jul' => 'July', + 'Aug' => 'August', + 'Sep' => 'September', + 'Oct' => 'October', + 'Nov' => 'November', + 'Dec' => 'December' + ); + private static $ExcelBaseDate = self::CALENDAR_WINDOWS_1900; public static $dateTimeObjectType = 'DateTime';