diff --git a/Classes/PHPExcel.php b/Classes/PHPExcel.php index 58b4479..a402214 100644 --- a/Classes/PHPExcel.php +++ b/Classes/PHPExcel.php @@ -349,13 +349,13 @@ class PHPExcel $this->_workSheetCollection, $oldIndex, 1 - ); + ); array_splice( $this->_workSheetCollection, $newIndex, 0, $pSheet - ); + ); return $newIndex; } diff --git a/Classes/PHPExcel/Autoloader.php b/Classes/PHPExcel/Autoloader.php index 6b6bf6d..3d49216 100644 --- a/Classes/PHPExcel/Autoloader.php +++ b/Classes/PHPExcel/Autoloader.php @@ -26,8 +26,8 @@ */ PHPExcel_Autoloader::Register(); -// As we always try to run the autoloader before anything else, we can use it to do a few -// simple checks and initialisations +// As we always try to run the autoloader before anything else, we can use it to do a few +// simple checks and initialisations PHPExcel_Shared_ZipStreamWrapper::register(); // check mbstring.func_overload if (ini_get('mbstring.func_overload') & 2) { @@ -39,47 +39,47 @@ PHPExcel_Shared_String::buildCharacterSets(); /** * PHPExcel_Autoloader * - * @category PHPExcel - * @package PHPExcel - * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) */ class PHPExcel_Autoloader { - /** - * Register the Autoloader with SPL - * - */ - public static function Register() { - if (function_exists('__autoload')) { - // Register any existing autoloader function with SPL, so we don't get any clashes - spl_autoload_register('__autoload'); - } - // Register ourselves with SPL - return spl_autoload_register(array('PHPExcel_Autoloader', 'Load')); - } // function Register() + /** + * Register the Autoloader with SPL + * + */ + public static function Register() { + if (function_exists('__autoload')) { + // Register any existing autoloader function with SPL, so we don't get any clashes + spl_autoload_register('__autoload'); + } + // Register ourselves with SPL + return spl_autoload_register(array('PHPExcel_Autoloader', 'Load')); + } // function Register() - /** - * Autoload a class identified by name - * - * @param string $pClassName Name of the object to load - */ - public static function Load($pClassName){ - if ((class_exists($pClassName,FALSE)) || (strpos($pClassName, 'PHPExcel') !== 0)) { - // Either already loaded, or not a PHPExcel class request - return FALSE; - } + /** + * Autoload a class identified by name + * + * @param string $pClassName Name of the object to load + */ + public static function Load($pClassName){ + if ((class_exists($pClassName,FALSE)) || (strpos($pClassName, 'PHPExcel') !== 0)) { + // Either already loaded, or not a PHPExcel class request + return FALSE; + } - $pClassFilePath = PHPEXCEL_ROOT . - str_replace('_',DIRECTORY_SEPARATOR,$pClassName) . - '.php'; + $pClassFilePath = PHPEXCEL_ROOT . + str_replace('_',DIRECTORY_SEPARATOR,$pClassName) . + '.php'; - if ((file_exists($pClassFilePath) === false) || (is_readable($pClassFilePath) === false)) { - // Can't load - return FALSE; - } + if ((file_exists($pClassFilePath) === false) || (is_readable($pClassFilePath) === false)) { + // Can't load + return FALSE; + } - require($pClassFilePath); - } // function Load() + require($pClassFilePath); + } // function Load() -} \ No newline at end of file +} diff --git a/Classes/PHPExcel/CachedObjectStorageFactory.php b/Classes/PHPExcel/CachedObjectStorageFactory.php index 59a9743..90f0af0 100644 --- a/Classes/PHPExcel/CachedObjectStorageFactory.php +++ b/Classes/PHPExcel/CachedObjectStorageFactory.php @@ -1,239 +1,239 @@ - array( - ), - self::cache_in_memory_gzip => array( - ), - self::cache_in_memory_serialized => array( - ), - self::cache_igbinary => array( - ), - self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB' - ), - self::cache_to_discISAM => array( 'dir' => NULL - ), - self::cache_to_apc => array( 'cacheTime' => 600 - ), - self::cache_to_memcache => array( 'memcacheServer' => 'localhost', - 'memcachePort' => 11211, - 'cacheTime' => 600 - ), - self::cache_to_wincache => array( 'cacheTime' => 600 - ), - self::cache_to_sqlite => array( - ), - self::cache_to_sqlite3 => array( - ), - ); - - - /** - * Arguments for the active cache storage method - * - * @var array of mixed array - */ - private static $_storageMethodParameters = array(); - - - /** - * Return the current cache storage method - * - * @return string|NULL - **/ - public static function getCacheStorageMethod() - { - return self::$_cacheStorageMethod; - } // function getCacheStorageMethod() - - - /** - * Return the current cache storage class - * - * @return PHPExcel_CachedObjectStorage_ICache|NULL - **/ - public static function getCacheStorageClass() - { - return self::$_cacheStorageClass; - } // function getCacheStorageClass() - - - /** - * Return the list of all possible cache storage methods - * - * @return string[] - **/ - public static function getAllCacheStorageMethods() - { - return self::$_storageMethods; - } // function getCacheStorageMethods() - - - /** - * Return the list of all available cache storage methods - * - * @return string[] - **/ - public static function getCacheStorageMethods() - { - $activeMethods = array(); - foreach(self::$_storageMethods as $storageMethod) { - $cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $storageMethod; - if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) { - $activeMethods[] = $storageMethod; - } - } - return $activeMethods; - } // function getCacheStorageMethods() - - - /** - * Identify the cache storage method to use - * - * @param string $method Name of the method to use for cell cacheing - * @param array of mixed $arguments Additional arguments to pass to the cell caching class - * when instantiating - * @return boolean - **/ - public static function initialize($method = self::cache_in_memory, $arguments = array()) - { - if (!in_array($method,self::$_storageMethods)) { - return FALSE; - } - - $cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method; - if (!call_user_func(array( $cacheStorageClass, - 'cacheMethodIsAvailable'))) { - return FALSE; - } - - self::$_storageMethodParameters[$method] = self::$_storageMethodDefaultParameters[$method]; - foreach($arguments as $k => $v) { - if (array_key_exists($k, self::$_storageMethodParameters[$method])) { - self::$_storageMethodParameters[$method][$k] = $v; - } - } - - if (self::$_cacheStorageMethod === NULL) { - self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method; - self::$_cacheStorageMethod = $method; - } - return TRUE; - } // function initialize() - - - /** - * Initialise the cache storage - * - * @param PHPExcel_Worksheet $parent Enable cell caching for this worksheet - * @return PHPExcel_CachedObjectStorage_ICache - **/ - public static function getInstance(PHPExcel_Worksheet $parent) - { - $cacheMethodIsAvailable = TRUE; - if (self::$_cacheStorageMethod === NULL) { - $cacheMethodIsAvailable = self::initialize(); - } - - if ($cacheMethodIsAvailable) { - $instance = new self::$_cacheStorageClass( $parent, - self::$_storageMethodParameters[self::$_cacheStorageMethod] - ); - if ($instance !== NULL) { - return $instance; - } - } - - return FALSE; - } // function getInstance() - -} \ No newline at end of file + array( + ), + self::cache_in_memory_gzip => array( + ), + self::cache_in_memory_serialized => array( + ), + self::cache_igbinary => array( + ), + self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB' + ), + self::cache_to_discISAM => array( 'dir' => NULL + ), + self::cache_to_apc => array( 'cacheTime' => 600 + ), + self::cache_to_memcache => array( 'memcacheServer' => 'localhost', + 'memcachePort' => 11211, + 'cacheTime' => 600 + ), + self::cache_to_wincache => array( 'cacheTime' => 600 + ), + self::cache_to_sqlite => array( + ), + self::cache_to_sqlite3 => array( + ), + ); + + + /** + * Arguments for the active cache storage method + * + * @var array of mixed array + */ + private static $_storageMethodParameters = array(); + + + /** + * Return the current cache storage method + * + * @return string|NULL + **/ + public static function getCacheStorageMethod() + { + return self::$_cacheStorageMethod; + } // function getCacheStorageMethod() + + + /** + * Return the current cache storage class + * + * @return PHPExcel_CachedObjectStorage_ICache|NULL + **/ + public static function getCacheStorageClass() + { + return self::$_cacheStorageClass; + } // function getCacheStorageClass() + + + /** + * Return the list of all possible cache storage methods + * + * @return string[] + **/ + public static function getAllCacheStorageMethods() + { + return self::$_storageMethods; + } // function getCacheStorageMethods() + + + /** + * Return the list of all available cache storage methods + * + * @return string[] + **/ + public static function getCacheStorageMethods() + { + $activeMethods = array(); + foreach(self::$_storageMethods as $storageMethod) { + $cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $storageMethod; + if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) { + $activeMethods[] = $storageMethod; + } + } + return $activeMethods; + } // function getCacheStorageMethods() + + + /** + * Identify the cache storage method to use + * + * @param string $method Name of the method to use for cell cacheing + * @param array of mixed $arguments Additional arguments to pass to the cell caching class + * when instantiating + * @return boolean + **/ + public static function initialize($method = self::cache_in_memory, $arguments = array()) + { + if (!in_array($method,self::$_storageMethods)) { + return FALSE; + } + + $cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method; + if (!call_user_func(array( $cacheStorageClass, + 'cacheMethodIsAvailable'))) { + return FALSE; + } + + self::$_storageMethodParameters[$method] = self::$_storageMethodDefaultParameters[$method]; + foreach($arguments as $k => $v) { + if (array_key_exists($k, self::$_storageMethodParameters[$method])) { + self::$_storageMethodParameters[$method][$k] = $v; + } + } + + if (self::$_cacheStorageMethod === NULL) { + self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method; + self::$_cacheStorageMethod = $method; + } + return TRUE; + } // function initialize() + + + /** + * Initialise the cache storage + * + * @param PHPExcel_Worksheet $parent Enable cell caching for this worksheet + * @return PHPExcel_CachedObjectStorage_ICache + **/ + public static function getInstance(PHPExcel_Worksheet $parent) + { + $cacheMethodIsAvailable = TRUE; + if (self::$_cacheStorageMethod === NULL) { + $cacheMethodIsAvailable = self::initialize(); + } + + if ($cacheMethodIsAvailable) { + $instance = new self::$_cacheStorageClass( $parent, + self::$_storageMethodParameters[self::$_cacheStorageMethod] + ); + if ($instance !== NULL) { + return $instance; + } + } + + return FALSE; + } // function getInstance() + +} diff --git a/Classes/PHPExcel/Calculation/DateTime.php b/Classes/PHPExcel/Calculation/DateTime.php index a24df5c..854f8f8 100644 --- a/Classes/PHPExcel/Calculation/DateTime.php +++ b/Classes/PHPExcel/Calculation/DateTime.php @@ -238,6 +238,10 @@ class PHPExcel_Calculation_DateTime { * Excel Function: * DATE(year,month,day) * + * PHPExcel is a lot more forgiving than MS Excel when passing non numeric values to this function. + * A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted, + * as will a day value with a suffix (e.g. '21st' rather than simply 21); again only English language. + * * @access public * @category Date/Time Functions * @param integer $year The value of the year argument can include one to four digits. @@ -278,6 +282,14 @@ class PHPExcel_Calculation_DateTime { $month = PHPExcel_Calculation_Functions::flattenSingleValue($month); $day = PHPExcel_Calculation_Functions::flattenSingleValue($day); + if (($month !== NULL) && (!is_numeric($month))) { + $month = PHPExcel_Shared_Date::monthStringToNumber($month); + } + + if (($day !== NULL) && (!is_numeric($day))) { + $day = PHPExcel_Shared_Date::dayStringToNumber($day); + } + $year = ($year !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($year) : 0; $month = ($month !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($month) : 0; $day = ($day !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($day) : 0; @@ -720,6 +732,10 @@ class PHPExcel_Calculation_DateTime { return PHPExcel_Calculation_Functions::VALUE(); } + if (!is_bool($method)) { + return PHPExcel_Calculation_Functions::VALUE(); + } + // Execute function $PHPStartDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($startDate); $startDay = $PHPStartDateObject->format('j'); diff --git a/Classes/PHPExcel/Shared/Date.php b/Classes/PHPExcel/Shared/Date.php index 43cf56d..d74e967 100644 --- a/Classes/PHPExcel/Shared/Date.php +++ b/Classes/PHPExcel/Shared/Date.php @@ -58,9 +58,22 @@ class PHPExcel_Shared_Date 'Sep' => 'September', 'Oct' => 'October', 'Nov' => 'November', - 'Dec' => 'December' + 'Dec' => 'December', ); + /* + * Names of the months of the year, indexed by shortname + * Planned usage for locale settings + * + * @public + * @var string[] + */ + public static $_numberSuffixes = array( 'st', + 'nd', + 'rd', + 'th', + ); + /* * Base calendar year to use for calculations * @@ -355,4 +368,23 @@ class PHPExcel_Shared_Date } + public static function monthStringToNumber($month) { + $monthIndex = 1; + foreach(self::$_monthNames as $shortMonthName => $longMonthName) { + if (($month === $longMonthName) || ($month === $shortMonthName)) { + return $monthIndex; + } + ++$monthIndex; + } + return $month; + } + + public static function dayStringToNumber($day) { + $strippedDayValue = (str_replace(self::$_numberSuffixes,'',$day)); + if (is_numeric($strippedDayValue)) { + return $strippedDayValue; + } + return $day; + } + } diff --git a/unitTests/rawTestData/Calculation/DateTime/DATE.data b/unitTests/rawTestData/Calculation/DateTime/DATE.data index 27a7c71..d7031e8 100644 --- a/unitTests/rawTestData/Calculation/DateTime/DATE.data +++ b/unitTests/rawTestData/Calculation/DateTime/DATE.data @@ -72,8 +72,8 @@ 2010, 0, -1, 40146 2010, 5, 31, 40329 2010, 1, '21st', 40199 // MS Excel will fail with a #VALUE return, but PHPExcel can parse this date -2010, "March",'21st', 40168 // MS Excel will fail with a #VALUE return, but PHPExcel can parse this date -2010, "March",21, 40168 // MS Excel will fail with a #VALUE return, but PHPExcel can parse this date +2010, "March",'21st', 40258 // MS Excel will fail with a #VALUE return, but PHPExcel can parse this date +2010, "March",21, 40258 // MS Excel will fail with a #VALUE return, but PHPExcel can parse this date "ABC", 1, 21, "#VALUE!" 2010, "DEF", 21, "#VALUE!" 2010, 3, "GHI", "#VALUE!" diff --git a/unitTests/rawTestData/Calculation/DateTime/DAYS360.data b/unitTests/rawTestData/Calculation/DateTime/DAYS360.data index ef1af47..7f36686 100644 --- a/unitTests/rawTestData/Calculation/DateTime/DAYS360.data +++ b/unitTests/rawTestData/Calculation/DateTime/DAYS360.data @@ -1,7 +1,7 @@ "ABC", "2007-1-10", FALSE, "#VALUE!" "2007-1-1", "DEF", TRUE, "#VALUE!" "2007-1-1", "2007-1-10", "XYZ", "#VALUE!" -"2007-1-10", "2007-1-1", "Y", "#NUM!" +"2007-1-10", "2007-1-1", "Y", "#VALUE!" "2007-1-1", "2007-1-10", FALSE, 9 "2007-1-1", "2007-1-10", TRUE, 9 "2007-1-1", "2007-12-31", FALSE, 360