mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-26 23:36:03 +03:00
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:
parent
c92f4560e6
commit
695edbf677
@ -549,6 +549,8 @@ class PHPExcel_Calculation_DateTime {
|
|||||||
if ($retVal < 0) { $retVal += 365; }
|
if ($retVal < 0) { $retVal += 365; }
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
$retVal = PHPExcel_Calculation_Functions::NaN();
|
||||||
}
|
}
|
||||||
return $retVal;
|
return $retVal;
|
||||||
} // function DATEDIF()
|
} // function DATEDIF()
|
||||||
@ -753,7 +755,7 @@ class PHPExcel_Calculation_DateTime {
|
|||||||
public static function WORKDAY($startDate,$endDays) {
|
public static function WORKDAY($startDate,$endDays) {
|
||||||
// Retrieve the mandatory start date and days that are referenced in the function definition
|
// Retrieve the mandatory start date and days that are referenced in the function definition
|
||||||
$startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
|
$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
|
// 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());
|
$dateArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
|
||||||
array_shift($dateArgs);
|
array_shift($dateArgs);
|
||||||
@ -763,6 +765,7 @@ class PHPExcel_Calculation_DateTime {
|
|||||||
return PHPExcel_Calculation_Functions::VALUE();
|
return PHPExcel_Calculation_Functions::VALUE();
|
||||||
}
|
}
|
||||||
$startDate = (float) floor($startDate);
|
$startDate = (float) floor($startDate);
|
||||||
|
$endDays = (int) floor($endDays);
|
||||||
// If endDays is 0, we always return startDate
|
// If endDays is 0, we always return startDate
|
||||||
if ($endDays == 0) { return $startDate; }
|
if ($endDays == 0) { return $startDate; }
|
||||||
|
|
||||||
|
@ -750,6 +750,12 @@ if (!function_exists('money_format')) {
|
|||||||
}
|
}
|
||||||
$space = $locale["{$letter}_sep_by_space"] ? ' ' : '';
|
$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 = number_format($number, $right, $locale['mon_decimal_point'], $flags['nogroup'] ? '' : $locale['mon_thousands_sep'] );
|
||||||
$number = explode($locale['mon_decimal_point'], $number);
|
$number = explode($locale['mon_decimal_point'], $number);
|
||||||
|
|
||||||
|
@ -798,11 +798,12 @@ class PHPExcel_Calculation_MathTrig {
|
|||||||
|
|
||||||
|
|
||||||
public static function ROMAN($aValue, $style=0) {
|
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);
|
$style = (is_null($style)) ? 0 : (integer) PHPExcel_Calculation_Functions::flattenSingleValue($style);
|
||||||
if ((!is_numeric($aValue)) || ($aValue < 0) || ($aValue >= 4000)) {
|
if ((!is_numeric($aValue)) || ($aValue < 0) || ($aValue >= 4000)) {
|
||||||
return PHPExcel_Calculation_Functions::VALUE();
|
return PHPExcel_Calculation_Functions::VALUE();
|
||||||
}
|
}
|
||||||
|
$aValue = (integer) $aValue;
|
||||||
if ($aValue == 0) {
|
if ($aValue == 0) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -839,7 +840,7 @@ class PHPExcel_Calculation_MathTrig {
|
|||||||
$digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits);
|
$digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits);
|
||||||
|
|
||||||
if ((is_numeric($number)) && (is_numeric($digits))) {
|
if ((is_numeric($number)) && (is_numeric($digits))) {
|
||||||
$significance = pow(10,$digits);
|
$significance = pow(10,(int) $digits);
|
||||||
if ($number < 0.0) {
|
if ($number < 0.0) {
|
||||||
return floor($number * $significance) / $significance;
|
return floor($number * $significance) / $significance;
|
||||||
} else {
|
} else {
|
||||||
@ -864,7 +865,7 @@ class PHPExcel_Calculation_MathTrig {
|
|||||||
$digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits);
|
$digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits);
|
||||||
|
|
||||||
if ((is_numeric($number)) && (is_numeric($digits))) {
|
if ((is_numeric($number)) && (is_numeric($digits))) {
|
||||||
$significance = pow(10,$digits);
|
$significance = pow(10,(int) $digits);
|
||||||
if ($number < 0.0) {
|
if ($number < 0.0) {
|
||||||
return ceil($number * $significance) / $significance;
|
return ceil($number * $significance) / $significance;
|
||||||
} else {
|
} else {
|
||||||
|
@ -96,7 +96,7 @@ class PHPExcel_Calculation_TextData {
|
|||||||
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue);
|
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue);
|
||||||
|
|
||||||
if (is_bool($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) {
|
if (self::$_invalidChars == Null) {
|
||||||
@ -106,7 +106,7 @@ class PHPExcel_Calculation_TextData {
|
|||||||
if (is_string($stringValue) || is_numeric($stringValue)) {
|
if (is_string($stringValue) || is_numeric($stringValue)) {
|
||||||
return str_replace(self::$_invalidChars,'',trim($stringValue,"\x00..\x1F"));
|
return str_replace(self::$_invalidChars,'',trim($stringValue,"\x00..\x1F"));
|
||||||
}
|
}
|
||||||
return Null;
|
return NULL;
|
||||||
} // function TRIMNONPRINTABLE()
|
} // function TRIMNONPRINTABLE()
|
||||||
|
|
||||||
|
|
||||||
@ -119,10 +119,14 @@ class PHPExcel_Calculation_TextData {
|
|||||||
public static function TRIMSPACES($stringValue = '') {
|
public static function TRIMSPACES($stringValue = '') {
|
||||||
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue);
|
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue);
|
||||||
|
|
||||||
if (is_string($stringValue) || is_numeric($stringValue)) {
|
if (is_bool($stringValue)) {
|
||||||
return trim(preg_replace('/ +/',' ',$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()
|
} // function TRIMSPACES()
|
||||||
|
|
||||||
|
|
||||||
@ -133,6 +137,8 @@ class PHPExcel_Calculation_TextData {
|
|||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function ASCIICODE($characters) {
|
public static function ASCIICODE($characters) {
|
||||||
|
if (($characters === NULL) || ($characters === ''))
|
||||||
|
return PHPExcel_Calculation_Functions::VALUE();
|
||||||
$characters = PHPExcel_Calculation_Functions::flattenSingleValue($characters);
|
$characters = PHPExcel_Calculation_Functions::flattenSingleValue($characters);
|
||||||
if (is_bool($characters)) {
|
if (is_bool($characters)) {
|
||||||
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
|
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
|
||||||
@ -287,11 +293,17 @@ class PHPExcel_Calculation_TextData {
|
|||||||
* @param mixed $value Value to check
|
* @param mixed $value Value to check
|
||||||
* @return boolean
|
* @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);
|
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||||
$decimals = PHPExcel_Calculation_Functions::flattenSingleValue($decimals);
|
$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);
|
$valueResult = round($value,$decimals);
|
||||||
if ($decimals < 0) { $decimals = 0; }
|
if ($decimals < 0) { $decimals = 0; }
|
||||||
if (!$no_commas) {
|
if (!$no_commas) {
|
||||||
@ -540,7 +552,7 @@ class PHPExcel_Calculation_TextData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $left.$newText.$right;
|
return $text;
|
||||||
} // function SUBSTITUTE()
|
} // function SUBSTITUTE()
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,6 +40,20 @@ class PHPExcel_Shared_Date
|
|||||||
const CALENDAR_WINDOWS_1900 = 1900; // Base date of 1st Jan 1900 = 1.0
|
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
|
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;
|
private static $ExcelBaseDate = self::CALENDAR_WINDOWS_1900;
|
||||||
|
|
||||||
public static $dateTimeObjectType = 'DateTime';
|
public static $dateTimeObjectType = 'DateTime';
|
||||||
|
Loading…
Reference in New Issue
Block a user