Minor tweaks to Excel functions to handle envelope cases

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@85852 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2012-01-29 14:25:25 +00:00
parent c92f4560e6
commit 695edbf677
5 changed files with 48 additions and 12 deletions

View File

@ -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; }

View File

@ -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);

View File

@ -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 {

View File

@ -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,11 +293,17 @@ 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);
// 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; }
if (!$no_commas) {
@ -540,7 +552,7 @@ class PHPExcel_Calculation_TextData {
}
}
return $left.$newText.$right;
return $text;
} // function SUBSTITUTE()

View File

@ -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';