mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-25 14:56:04 +03:00
More PSR-2 goodness.... getting there slowly
This commit is contained in:
parent
a86cbaa230
commit
f7296f58b4
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHPExcel
|
* PHPExcel_Shared_CodePage
|
||||||
*
|
*
|
||||||
* Copyright (c) 2006 - 2015 PHPExcel
|
* Copyright (c) 2006 - 2015 PHPExcel
|
||||||
*
|
*
|
||||||
@ -21,86 +22,76 @@
|
|||||||
* @category PHPExcel
|
* @category PHPExcel
|
||||||
* @package PHPExcel_Shared
|
* @package PHPExcel_Shared
|
||||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
* @version ##VERSION##, ##DATE##
|
* @version ##VERSION##, ##DATE##
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PHPExcel_Shared_CodePage
|
|
||||||
*
|
|
||||||
* @category PHPExcel
|
|
||||||
* @package PHPExcel_Shared
|
|
||||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
|
||||||
*/
|
|
||||||
class PHPExcel_Shared_CodePage
|
class PHPExcel_Shared_CodePage
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Convert Microsoft Code Page Identifier to Code Page Name which iconv
|
* Convert Microsoft Code Page Identifier to Code Page Name which iconv
|
||||||
* and mbstring understands
|
* and mbstring understands
|
||||||
*
|
*
|
||||||
* @param integer $codePage Microsoft Code Page Indentifier
|
* @param integer $codePage Microsoft Code Page Indentifier
|
||||||
* @return string Code Page Name
|
* @return string Code Page Name
|
||||||
* @throws PHPExcel_Exception
|
* @throws PHPExcel_Exception
|
||||||
*/
|
*/
|
||||||
public static function NumberToName($codePage = 1252)
|
public static function NumberToName($codePage = 1252)
|
||||||
{
|
{
|
||||||
switch ($codePage) {
|
switch ($codePage) {
|
||||||
case 367: return 'ASCII'; break; // ASCII
|
case 367: return 'ASCII'; break; // ASCII
|
||||||
case 437: return 'CP437'; break; // OEM US
|
case 437: return 'CP437'; break; // OEM US
|
||||||
case 720: throw new PHPExcel_Exception('Code page 720 not supported.');
|
case 720: throw new PHPExcel_Exception('Code page 720 not supported.');
|
||||||
break; // OEM Arabic
|
break; // OEM Arabic
|
||||||
case 737: return 'CP737'; break; // OEM Greek
|
case 737: return 'CP737'; break; // OEM Greek
|
||||||
case 775: return 'CP775'; break; // OEM Baltic
|
case 775: return 'CP775'; break; // OEM Baltic
|
||||||
case 850: return 'CP850'; break; // OEM Latin I
|
case 850: return 'CP850'; break; // OEM Latin I
|
||||||
case 852: return 'CP852'; break; // OEM Latin II (Central European)
|
case 852: return 'CP852'; break; // OEM Latin II (Central European)
|
||||||
case 855: return 'CP855'; break; // OEM Cyrillic
|
case 855: return 'CP855'; break; // OEM Cyrillic
|
||||||
case 857: return 'CP857'; break; // OEM Turkish
|
case 857: return 'CP857'; break; // OEM Turkish
|
||||||
case 858: return 'CP858'; break; // OEM Multilingual Latin I with Euro
|
case 858: return 'CP858'; break; // OEM Multilingual Latin I with Euro
|
||||||
case 860: return 'CP860'; break; // OEM Portugese
|
case 860: return 'CP860'; break; // OEM Portugese
|
||||||
case 861: return 'CP861'; break; // OEM Icelandic
|
case 861: return 'CP861'; break; // OEM Icelandic
|
||||||
case 862: return 'CP862'; break; // OEM Hebrew
|
case 862: return 'CP862'; break; // OEM Hebrew
|
||||||
case 863: return 'CP863'; break; // OEM Canadian (French)
|
case 863: return 'CP863'; break; // OEM Canadian (French)
|
||||||
case 864: return 'CP864'; break; // OEM Arabic
|
case 864: return 'CP864'; break; // OEM Arabic
|
||||||
case 865: return 'CP865'; break; // OEM Nordic
|
case 865: return 'CP865'; break; // OEM Nordic
|
||||||
case 866: return 'CP866'; break; // OEM Cyrillic (Russian)
|
case 866: return 'CP866'; break; // OEM Cyrillic (Russian)
|
||||||
case 869: return 'CP869'; break; // OEM Greek (Modern)
|
case 869: return 'CP869'; break; // OEM Greek (Modern)
|
||||||
case 874: return 'CP874'; break; // ANSI Thai
|
case 874: return 'CP874'; break; // ANSI Thai
|
||||||
case 932: return 'CP932'; break; // ANSI Japanese Shift-JIS
|
case 932: return 'CP932'; break; // ANSI Japanese Shift-JIS
|
||||||
case 936: return 'CP936'; break; // ANSI Chinese Simplified GBK
|
case 936: return 'CP936'; break; // ANSI Chinese Simplified GBK
|
||||||
case 949: return 'CP949'; break; // ANSI Korean (Wansung)
|
case 949: return 'CP949'; break; // ANSI Korean (Wansung)
|
||||||
case 950: return 'CP950'; break; // ANSI Chinese Traditional BIG5
|
case 950: return 'CP950'; break; // ANSI Chinese Traditional BIG5
|
||||||
case 1200: return 'UTF-16LE'; break; // UTF-16 (BIFF8)
|
case 1200: return 'UTF-16LE'; break; // UTF-16 (BIFF8)
|
||||||
case 1250: return 'CP1250'; break; // ANSI Latin II (Central European)
|
case 1250: return 'CP1250'; break; // ANSI Latin II (Central European)
|
||||||
case 1251: return 'CP1251'; break; // ANSI Cyrillic
|
case 1251: return 'CP1251'; break; // ANSI Cyrillic
|
||||||
case 0: // CodePage is not always correctly set when the xls file was saved by Apple's Numbers program
|
case 0: // CodePage is not always correctly set when the xls file was saved by Apple's Numbers program
|
||||||
case 1252: return 'CP1252'; break; // ANSI Latin I (BIFF4-BIFF7)
|
case 1252: return 'CP1252'; break; // ANSI Latin I (BIFF4-BIFF7)
|
||||||
case 1253: return 'CP1253'; break; // ANSI Greek
|
case 1253: return 'CP1253'; break; // ANSI Greek
|
||||||
case 1254: return 'CP1254'; break; // ANSI Turkish
|
case 1254: return 'CP1254'; break; // ANSI Turkish
|
||||||
case 1255: return 'CP1255'; break; // ANSI Hebrew
|
case 1255: return 'CP1255'; break; // ANSI Hebrew
|
||||||
case 1256: return 'CP1256'; break; // ANSI Arabic
|
case 1256: return 'CP1256'; break; // ANSI Arabic
|
||||||
case 1257: return 'CP1257'; break; // ANSI Baltic
|
case 1257: return 'CP1257'; break; // ANSI Baltic
|
||||||
case 1258: return 'CP1258'; break; // ANSI Vietnamese
|
case 1258: return 'CP1258'; break; // ANSI Vietnamese
|
||||||
case 1361: return 'CP1361'; break; // ANSI Korean (Johab)
|
case 1361: return 'CP1361'; break; // ANSI Korean (Johab)
|
||||||
case 10000: return 'MAC'; break; // Apple Roman
|
case 10000: return 'MAC'; break; // Apple Roman
|
||||||
case 10001: return 'CP932'; break; // Macintosh Japanese
|
case 10001: return 'CP932'; break; // Macintosh Japanese
|
||||||
case 10002: return 'CP950'; break; // Macintosh Chinese Traditional
|
case 10002: return 'CP950'; break; // Macintosh Chinese Traditional
|
||||||
case 10003: return 'CP1361'; break; // Macintosh Korean
|
case 10003: return 'CP1361'; break; // Macintosh Korean
|
||||||
case 10006: return 'MACGREEK'; break; // Macintosh Greek
|
case 10006: return 'MACGREEK'; break; // Macintosh Greek
|
||||||
case 10007: return 'MACCYRILLIC'; break; // Macintosh Cyrillic
|
case 10007: return 'MACCYRILLIC'; break; // Macintosh Cyrillic
|
||||||
case 10008: return 'CP936'; break; // Macintosh - Simplified Chinese (GB 2312)
|
case 10008: return 'CP936'; break; // Macintosh - Simplified Chinese (GB 2312)
|
||||||
case 10029: return 'MACCENTRALEUROPE'; break; // Macintosh Central Europe
|
case 10029: return 'MACCENTRALEUROPE'; break; // Macintosh Central Europe
|
||||||
case 10079: return 'MACICELAND'; break; // Macintosh Icelandic
|
case 10079: return 'MACICELAND'; break; // Macintosh Icelandic
|
||||||
case 10081: return 'MACTURKISH'; break; // Macintosh Turkish
|
case 10081: return 'MACTURKISH'; break; // Macintosh Turkish
|
||||||
case 21010: return 'UTF-16LE'; break; // UTF-16 (BIFF8) This isn't correct, but some Excel writer libraries erroneously use Codepage 21010 for UTF-16LE
|
case 21010: return 'UTF-16LE'; break; // UTF-16 (BIFF8) This isn't correct, but some Excel writer libraries erroneously use Codepage 21010 for UTF-16LE
|
||||||
case 32768: return 'MAC'; break; // Apple Roman
|
case 32768: return 'MAC'; break; // Apple Roman
|
||||||
case 32769: throw new PHPExcel_Exception('Code page 32769 not supported.');
|
case 32769: throw new PHPExcel_Exception('Code page 32769 not supported.');
|
||||||
break; // ANSI Latin I (BIFF2-BIFF3)
|
break; // ANSI Latin I (BIFF2-BIFF3)
|
||||||
case 65000: return 'UTF-7'; break; // Unicode (UTF-7)
|
case 65000: return 'UTF-7'; break; // Unicode (UTF-7)
|
||||||
case 65001: return 'UTF-8'; break; // Unicode (UTF-8)
|
case 65001: return 'UTF-8'; break; // Unicode (UTF-8)
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new PHPExcel_Exception('Unknown codepage: ' . $codePage);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
throw new PHPExcel_Exception('Unknown codepage: ' . $codePage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHPExcel
|
* PHPExcel_Shared_Date
|
||||||
*
|
*
|
||||||
* Copyright (c) 2006 - 2015 PHPExcel
|
* Copyright (c) 2006 - 2015 PHPExcel
|
||||||
*
|
*
|
||||||
@ -20,360 +20,363 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*
|
*
|
||||||
* @category PHPExcel
|
* @category PHPExcel
|
||||||
* @package PHPExcel_Shared
|
* @package PHPExcel_Shared
|
||||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
|
||||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
|
||||||
* @version ##VERSION##, ##DATE##
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PHPExcel_Shared_Date
|
|
||||||
*
|
|
||||||
* @category PHPExcel
|
|
||||||
* @package PHPExcel_Shared
|
|
||||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version ##VERSION##, ##DATE##
|
||||||
*/
|
*/
|
||||||
class PHPExcel_Shared_Date
|
class PHPExcel_Shared_Date
|
||||||
{
|
{
|
||||||
/** constants */
|
/** constants */
|
||||||
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
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Names of the months of the year, indexed by shortname
|
* Names of the months of the year, indexed by shortname
|
||||||
* Planned usage for locale settings
|
* Planned usage for locale settings
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
public static $_monthNames = array( 'Jan' => 'January',
|
public static $monthNames = array(
|
||||||
'Feb' => 'February',
|
'Jan' => 'January',
|
||||||
'Mar' => 'March',
|
'Feb' => 'February',
|
||||||
'Apr' => 'April',
|
'Mar' => 'March',
|
||||||
'May' => 'May',
|
'Apr' => 'April',
|
||||||
'Jun' => 'June',
|
'May' => 'May',
|
||||||
'Jul' => 'July',
|
'Jun' => 'June',
|
||||||
'Aug' => 'August',
|
'Jul' => 'July',
|
||||||
'Sep' => 'September',
|
'Aug' => 'August',
|
||||||
'Oct' => 'October',
|
'Sep' => 'September',
|
||||||
'Nov' => 'November',
|
'Oct' => 'October',
|
||||||
'Dec' => 'December',
|
'Nov' => 'November',
|
||||||
);
|
'Dec' => 'December',
|
||||||
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Names of the months of the year, indexed by shortname
|
* Names of the months of the year, indexed by shortname
|
||||||
* Planned usage for locale settings
|
* Planned usage for locale settings
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
public static $_numberSuffixes = array( 'st',
|
public static $numberSuffixes = array(
|
||||||
'nd',
|
'st',
|
||||||
'rd',
|
'nd',
|
||||||
'th',
|
'rd',
|
||||||
);
|
'th',
|
||||||
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Base calendar year to use for calculations
|
* Base calendar year to use for calculations
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected static $_excelBaseDate = self::CALENDAR_WINDOWS_1900;
|
protected static $excelBaseDate = self::CALENDAR_WINDOWS_1900;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Excel calendar (Windows 1900 or Mac 1904)
|
* Set the Excel calendar (Windows 1900 or Mac 1904)
|
||||||
*
|
*
|
||||||
* @param integer $baseDate Excel base date (1900 or 1904)
|
* @param integer $baseDate Excel base date (1900 or 1904)
|
||||||
* @return boolean Success or failure
|
* @return boolean Success or failure
|
||||||
*/
|
*/
|
||||||
public static function setExcelCalendar($baseDate) {
|
public static function setExcelCalendar($baseDate)
|
||||||
if (($baseDate == self::CALENDAR_WINDOWS_1900) ||
|
{
|
||||||
($baseDate == self::CALENDAR_MAC_1904)) {
|
if (($baseDate == self::CALENDAR_WINDOWS_1900) ||
|
||||||
self::$_excelBaseDate = $baseDate;
|
($baseDate == self::CALENDAR_MAC_1904)) {
|
||||||
return TRUE;
|
self::$excelBaseDate = $baseDate;
|
||||||
}
|
return true;
|
||||||
return FALSE;
|
}
|
||||||
} // function setExcelCalendar()
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the Excel calendar (Windows 1900 or Mac 1904)
|
* Return the Excel calendar (Windows 1900 or Mac 1904)
|
||||||
*
|
*
|
||||||
* @return integer Excel base date (1900 or 1904)
|
* @return integer Excel base date (1900 or 1904)
|
||||||
*/
|
*/
|
||||||
public static function getExcelCalendar() {
|
public static function getExcelCalendar()
|
||||||
return self::$_excelBaseDate;
|
{
|
||||||
} // function getExcelCalendar()
|
return self::$excelBaseDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a date from Excel to PHP
|
* Convert a date from Excel to PHP
|
||||||
*
|
*
|
||||||
* @param long $dateValue Excel date/time value
|
* @param long $dateValue Excel date/time value
|
||||||
* @param boolean $adjustToTimezone Flag indicating whether $dateValue should be treated as
|
* @param boolean $adjustToTimezone Flag indicating whether $dateValue should be treated as
|
||||||
* a UST timestamp, or adjusted to UST
|
* a UST timestamp, or adjusted to UST
|
||||||
* @param string $timezone The timezone for finding the adjustment from UST
|
* @param string $timezone The timezone for finding the adjustment from UST
|
||||||
* @return long PHP serialized date/time
|
* @return long PHP serialized date/time
|
||||||
*/
|
*/
|
||||||
public static function ExcelToPHP($dateValue = 0, $adjustToTimezone = FALSE, $timezone = NULL) {
|
public static function ExcelToPHP($dateValue = 0, $adjustToTimezone = false, $timezone = null)
|
||||||
if (self::$_excelBaseDate == self::CALENDAR_WINDOWS_1900) {
|
{
|
||||||
$my_excelBaseDate = 25569;
|
if (self::$excelBaseDate == self::CALENDAR_WINDOWS_1900) {
|
||||||
// Adjust for the spurious 29-Feb-1900 (Day 60)
|
$myexcelBaseDate = 25569;
|
||||||
if ($dateValue < 60) {
|
// Adjust for the spurious 29-Feb-1900 (Day 60)
|
||||||
--$my_excelBaseDate;
|
if ($dateValue < 60) {
|
||||||
}
|
--$myexcelBaseDate;
|
||||||
} else {
|
}
|
||||||
$my_excelBaseDate = 24107;
|
} else {
|
||||||
}
|
$myexcelBaseDate = 24107;
|
||||||
|
}
|
||||||
|
|
||||||
// Perform conversion
|
// Perform conversion
|
||||||
if ($dateValue >= 1) {
|
if ($dateValue >= 1) {
|
||||||
$utcDays = $dateValue - $my_excelBaseDate;
|
$utcDays = $dateValue - $myexcelBaseDate;
|
||||||
$returnValue = round($utcDays * 86400);
|
$returnValue = round($utcDays * 86400);
|
||||||
if (($returnValue <= PHP_INT_MAX) && ($returnValue >= -PHP_INT_MAX)) {
|
if (($returnValue <= PHP_INT_MAX) && ($returnValue >= -PHP_INT_MAX)) {
|
||||||
$returnValue = (integer) $returnValue;
|
$returnValue = (integer) $returnValue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$hours = round($dateValue * 24);
|
$hours = round($dateValue * 24);
|
||||||
$mins = round($dateValue * 1440) - round($hours * 60);
|
$mins = round($dateValue * 1440) - round($hours * 60);
|
||||||
$secs = round($dateValue * 86400) - round($hours * 3600) - round($mins * 60);
|
$secs = round($dateValue * 86400) - round($hours * 3600) - round($mins * 60);
|
||||||
$returnValue = (integer) gmmktime($hours, $mins, $secs);
|
$returnValue = (integer) gmmktime($hours, $mins, $secs);
|
||||||
}
|
}
|
||||||
|
|
||||||
$timezoneAdjustment = ($adjustToTimezone) ?
|
$timezoneAdjustment = ($adjustToTimezone) ?
|
||||||
PHPExcel_Shared_TimeZone::getTimezoneAdjustment($timezone, $returnValue) :
|
PHPExcel_Shared_TimeZone::getTimezoneAdjustment($timezone, $returnValue) :
|
||||||
0;
|
0;
|
||||||
|
|
||||||
// Return
|
return $returnValue + $timezoneAdjustment;
|
||||||
return $returnValue + $timezoneAdjustment;
|
}
|
||||||
} // function ExcelToPHP()
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a date from Excel to a PHP Date/Time object
|
* Convert a date from Excel to a PHP Date/Time object
|
||||||
*
|
*
|
||||||
* @param integer $dateValue Excel date/time value
|
* @param integer $dateValue Excel date/time value
|
||||||
* @return DateTime PHP date/time object
|
* @return DateTime PHP date/time object
|
||||||
*/
|
*/
|
||||||
public static function ExcelToPHPObject($dateValue = 0) {
|
public static function ExcelToPHPObject($dateValue = 0)
|
||||||
$dateTime = self::ExcelToPHP($dateValue);
|
{
|
||||||
$days = floor($dateTime / 86400);
|
$dateTime = self::ExcelToPHP($dateValue);
|
||||||
$time = round((($dateTime / 86400) - $days) * 86400);
|
$days = floor($dateTime / 86400);
|
||||||
$hours = round($time / 3600);
|
$time = round((($dateTime / 86400) - $days) * 86400);
|
||||||
$minutes = round($time / 60) - ($hours * 60);
|
$hours = round($time / 3600);
|
||||||
$seconds = round($time) - ($hours * 3600) - ($minutes * 60);
|
$minutes = round($time / 60) - ($hours * 60);
|
||||||
|
$seconds = round($time) - ($hours * 3600) - ($minutes * 60);
|
||||||
|
|
||||||
$dateObj = date_create('1-Jan-1970+'.$days.' days');
|
$dateObj = date_create('1-Jan-1970+'.$days.' days');
|
||||||
$dateObj->setTime($hours,$minutes,$seconds);
|
$dateObj->setTime($hours,$minutes,$seconds);
|
||||||
|
|
||||||
return $dateObj;
|
return $dateObj;
|
||||||
} // function ExcelToPHPObject()
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a date from PHP to Excel
|
* Convert a date from PHP to Excel
|
||||||
*
|
*
|
||||||
* @param mixed $dateValue PHP serialized date/time or date object
|
* @param mixed $dateValue PHP serialized date/time or date object
|
||||||
* @param boolean $adjustToTimezone Flag indicating whether $dateValue should be treated as
|
* @param boolean $adjustToTimezone Flag indicating whether $dateValue should be treated as
|
||||||
* a UST timestamp, or adjusted to UST
|
* a UST timestamp, or adjusted to UST
|
||||||
* @param string $timezone The timezone for finding the adjustment from UST
|
* @param string $timezone The timezone for finding the adjustment from UST
|
||||||
* @return mixed Excel date/time value
|
* @return mixed Excel date/time value
|
||||||
* or boolean FALSE on failure
|
* or boolean FALSE on failure
|
||||||
*/
|
*/
|
||||||
public static function PHPToExcel($dateValue = 0, $adjustToTimezone = FALSE, $timezone = NULL) {
|
public static function PHPToExcel($dateValue = 0, $adjustToTimezone = false, $timezone = null)
|
||||||
$saveTimeZone = date_default_timezone_get();
|
{
|
||||||
date_default_timezone_set('UTC');
|
$saveTimeZone = date_default_timezone_get();
|
||||||
$retValue = FALSE;
|
date_default_timezone_set('UTC');
|
||||||
if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) {
|
$retValue = false;
|
||||||
$retValue = self::FormattedPHPToExcel( $dateValue->format('Y'), $dateValue->format('m'), $dateValue->format('d'),
|
if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) {
|
||||||
$dateValue->format('H'), $dateValue->format('i'), $dateValue->format('s')
|
$retValue = self::FormattedPHPToExcel( $dateValue->format('Y'), $dateValue->format('m'), $dateValue->format('d'),
|
||||||
);
|
$dateValue->format('H'), $dateValue->format('i'), $dateValue->format('s')
|
||||||
} elseif (is_numeric($dateValue)) {
|
);
|
||||||
$retValue = self::FormattedPHPToExcel( date('Y',$dateValue), date('m',$dateValue), date('d',$dateValue),
|
} elseif (is_numeric($dateValue)) {
|
||||||
date('H',$dateValue), date('i',$dateValue), date('s',$dateValue)
|
$retValue = self::FormattedPHPToExcel( date('Y',$dateValue), date('m',$dateValue), date('d',$dateValue),
|
||||||
);
|
date('H',$dateValue), date('i',$dateValue), date('s',$dateValue)
|
||||||
}
|
);
|
||||||
date_default_timezone_set($saveTimeZone);
|
}
|
||||||
|
date_default_timezone_set($saveTimeZone);
|
||||||
|
|
||||||
return $retValue;
|
return $retValue;
|
||||||
} // function PHPToExcel()
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FormattedPHPToExcel
|
* FormattedPHPToExcel
|
||||||
*
|
*
|
||||||
* @param long $year
|
* @param long $year
|
||||||
* @param long $month
|
* @param long $month
|
||||||
* @param long $day
|
* @param long $day
|
||||||
* @param long $hours
|
* @param long $hours
|
||||||
* @param long $minutes
|
* @param long $minutes
|
||||||
* @param long $seconds
|
* @param long $seconds
|
||||||
* @return long Excel date/time value
|
* @return long Excel date/time value
|
||||||
*/
|
*/
|
||||||
public static function FormattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0) {
|
public static function FormattedPHPToExcel($year, $month, $day, $hours = 0, $minutes = 0, $seconds = 0)
|
||||||
if (self::$_excelBaseDate == self::CALENDAR_WINDOWS_1900) {
|
{
|
||||||
//
|
if (self::$excelBaseDate == self::CALENDAR_WINDOWS_1900) {
|
||||||
// Fudge factor for the erroneous fact that the year 1900 is treated as a Leap Year in MS Excel
|
//
|
||||||
// This affects every date following 28th February 1900
|
// Fudge factor for the erroneous fact that the year 1900 is treated as a Leap Year in MS Excel
|
||||||
//
|
// This affects every date following 28th February 1900
|
||||||
$excel1900isLeapYear = TRUE;
|
//
|
||||||
if (($year == 1900) && ($month <= 2)) { $excel1900isLeapYear = FALSE; }
|
$excel1900isLeapYear = true;
|
||||||
$my_excelBaseDate = 2415020;
|
if (($year == 1900) && ($month <= 2)) {
|
||||||
} else {
|
$excel1900isLeapYear = false;
|
||||||
$my_excelBaseDate = 2416481;
|
}
|
||||||
$excel1900isLeapYear = FALSE;
|
$myexcelBaseDate = 2415020;
|
||||||
}
|
} else {
|
||||||
|
$myexcelBaseDate = 2416481;
|
||||||
|
$excel1900isLeapYear = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Julian base date Adjustment
|
// Julian base date Adjustment
|
||||||
if ($month > 2) {
|
if ($month > 2) {
|
||||||
$month -= 3;
|
$month -= 3;
|
||||||
} else {
|
} else {
|
||||||
$month += 9;
|
$month += 9;
|
||||||
--$year;
|
--$year;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0)
|
// Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0)
|
||||||
$century = substr($year,0,2);
|
$century = substr($year,0,2);
|
||||||
$decade = substr($year,2,2);
|
$decade = substr($year,2,2);
|
||||||
$excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $my_excelBaseDate + $excel1900isLeapYear;
|
$excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $myexcelBaseDate + $excel1900isLeapYear;
|
||||||
|
|
||||||
$excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400;
|
$excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400;
|
||||||
|
|
||||||
return (float) $excelDate + $excelTime;
|
return (float) $excelDate + $excelTime;
|
||||||
} // function FormattedPHPToExcel()
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is a given cell a date/time?
|
* Is a given cell a date/time?
|
||||||
*
|
*
|
||||||
* @param PHPExcel_Cell $pCell
|
* @param PHPExcel_Cell $pCell
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function isDateTime(PHPExcel_Cell $pCell) {
|
public static function isDateTime(PHPExcel_Cell $pCell)
|
||||||
return self::isDateTimeFormat(
|
{
|
||||||
$pCell->getWorksheet()->getStyle(
|
return self::isDateTimeFormat(
|
||||||
$pCell->getCoordinate()
|
$pCell->getWorksheet()->getStyle(
|
||||||
)->getNumberFormat()
|
$pCell->getCoordinate()
|
||||||
);
|
)->getNumberFormat()
|
||||||
} // function isDateTime()
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is a given number format a date/time?
|
* Is a given number format a date/time?
|
||||||
*
|
*
|
||||||
* @param PHPExcel_Style_NumberFormat $pFormat
|
* @param PHPExcel_Style_NumberFormat $pFormat
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function isDateTimeFormat(PHPExcel_Style_NumberFormat $pFormat) {
|
public static function isDateTimeFormat(PHPExcel_Style_NumberFormat $pFormat)
|
||||||
return self::isDateTimeFormatCode($pFormat->getFormatCode());
|
{
|
||||||
} // function isDateTimeFormat()
|
return self::isDateTimeFormatCode($pFormat->getFormatCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static $possibleDateFormatCharacters = 'eymdHs';
|
private static $possibleDateFormatCharacters = 'eymdHs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is a given number format code a date/time?
|
* Is a given number format code a date/time?
|
||||||
*
|
*
|
||||||
* @param string $pFormatCode
|
* @param string $pFormatCode
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function isDateTimeFormatCode($pFormatCode = '') {
|
public static function isDateTimeFormatCode($pFormatCode = '')
|
||||||
if (strtolower($pFormatCode) === strtolower(PHPExcel_Style_NumberFormat::FORMAT_GENERAL))
|
{
|
||||||
// "General" contains an epoch letter 'e', so we trap for it explicitly here (case-insensitive check)
|
if (strtolower($pFormatCode) === strtolower(PHPExcel_Style_NumberFormat::FORMAT_GENERAL))
|
||||||
return FALSE;
|
// "General" contains an epoch letter 'e', so we trap for it explicitly here (case-insensitive check)
|
||||||
|
return false;
|
||||||
if (preg_match('/[0#]E[+-]0/i', $pFormatCode))
|
if (preg_match('/[0#]E[+-]0/i', $pFormatCode))
|
||||||
// Scientific format
|
// Scientific format
|
||||||
return FALSE;
|
return false;
|
||||||
// Switch on formatcode
|
// Switch on formatcode
|
||||||
switch ($pFormatCode) {
|
switch ($pFormatCode) {
|
||||||
// Explicitly defined date formats
|
// Explicitly defined date formats
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYMINUS:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYMINUS:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMMINUS:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMMINUS:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_MYMINUS:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_MYMINUS:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME1:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME1:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME2:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME2:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME5:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME5:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME6:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME6:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME7:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME7:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME8:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME8:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX14:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX14:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX16:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX16:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX17:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX17:
|
||||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22:
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22:
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Typically number, currency or accounting (or occasionally fraction) formats
|
// Typically number, currency or accounting (or occasionally fraction) formats
|
||||||
if ((substr($pFormatCode,0,1) == '_') || (substr($pFormatCode,0,2) == '0 ')) {
|
if ((substr($pFormatCode, 0, 1) == '_') || (substr($pFormatCode, 0, 2) == '0 ')) {
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
// Try checking for any of the date formatting characters that don't appear within square braces
|
// Try checking for any of the date formatting characters that don't appear within square braces
|
||||||
if (preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i',$pFormatCode)) {
|
if (preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i', $pFormatCode)) {
|
||||||
// We might also have a format mask containing quoted strings...
|
// We might also have a format mask containing quoted strings...
|
||||||
// we don't want to test for any of our characters within the quoted blocks
|
// we don't want to test for any of our characters within the quoted blocks
|
||||||
if (strpos($pFormatCode,'"') !== FALSE) {
|
if (strpos($pFormatCode, '"') !== false) {
|
||||||
$segMatcher = FALSE;
|
$segMatcher = false;
|
||||||
foreach(explode('"',$pFormatCode) as $subVal) {
|
foreach(explode('"', $pFormatCode) as $subVal) {
|
||||||
// Only test in alternate array entries (the non-quoted blocks)
|
// Only test in alternate array entries (the non-quoted blocks)
|
||||||
if (($segMatcher = !$segMatcher) &&
|
if (($segMatcher = !$segMatcher) &&
|
||||||
(preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i',$subVal))) {
|
(preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i', $subVal))) {
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No date...
|
// No date...
|
||||||
return FALSE;
|
return false;
|
||||||
} // function isDateTimeFormatCode()
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a date/time string to Excel time
|
* Convert a date/time string to Excel time
|
||||||
*
|
*
|
||||||
* @param string $dateValue Examples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10'
|
* @param string $dateValue Examples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10'
|
||||||
* @return float|FALSE Excel date/time serial value
|
* @return float|FALSE Excel date/time serial value
|
||||||
*/
|
*/
|
||||||
public static function stringToExcel($dateValue = '') {
|
public static function stringToExcel($dateValue = '')
|
||||||
if (strlen($dateValue) < 2)
|
{
|
||||||
return FALSE;
|
if (strlen($dateValue) < 2)
|
||||||
if (!preg_match('/^(\d{1,4}[ \.\/\-][A-Z]{3,9}([ \.\/\-]\d{1,4})?|[A-Z]{3,9}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?|\d{1,4}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?)( \d{1,2}:\d{1,2}(:\d{1,2})?)?$/iu', $dateValue))
|
return false;
|
||||||
return FALSE;
|
if (!preg_match('/^(\d{1,4}[ \.\/\-][A-Z]{3,9}([ \.\/\-]\d{1,4})?|[A-Z]{3,9}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?|\d{1,4}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?)( \d{1,2}:\d{1,2}(:\d{1,2})?)?$/iu', $dateValue))
|
||||||
|
return false;
|
||||||
|
|
||||||
$dateValueNew = PHPExcel_Calculation_DateTime::DATEVALUE($dateValue);
|
$dateValueNew = PHPExcel_Calculation_DateTime::DATEVALUE($dateValue);
|
||||||
|
|
||||||
if ($dateValueNew === PHPExcel_Calculation_Functions::VALUE()) {
|
if ($dateValueNew === PHPExcel_Calculation_Functions::VALUE()) {
|
||||||
return FALSE;
|
return false;
|
||||||
} else {
|
}
|
||||||
if (strpos($dateValue, ':') !== FALSE) {
|
|
||||||
$timeValue = PHPExcel_Calculation_DateTime::TIMEVALUE($dateValue);
|
|
||||||
if ($timeValue === PHPExcel_Calculation_Functions::VALUE()) {
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
$dateValueNew += $timeValue;
|
|
||||||
}
|
|
||||||
return $dateValueNew;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (strpos($dateValue, ':') !== false) {
|
||||||
|
$timeValue = PHPExcel_Calculation_DateTime::TIMEVALUE($dateValue);
|
||||||
|
if ($timeValue === PHPExcel_Calculation_Functions::VALUE()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$dateValueNew += $timeValue;
|
||||||
|
}
|
||||||
|
return $dateValueNew;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public static function monthStringToNumber($month)
|
||||||
|
{
|
||||||
public static function monthStringToNumber($month) {
|
|
||||||
$monthIndex = 1;
|
$monthIndex = 1;
|
||||||
foreach(self::$_monthNames as $shortMonthName => $longMonthName) {
|
foreach(self::$monthNames as $shortMonthName => $longMonthName) {
|
||||||
if (($month === $longMonthName) || ($month === $shortMonthName)) {
|
if (($month === $longMonthName) || ($month === $shortMonthName)) {
|
||||||
return $monthIndex;
|
return $monthIndex;
|
||||||
}
|
}
|
||||||
@ -382,12 +385,12 @@ class PHPExcel_Shared_Date
|
|||||||
return $month;
|
return $month;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function dayStringToNumber($day) {
|
public static function dayStringToNumber($day)
|
||||||
$strippedDayValue = (str_replace(self::$_numberSuffixes,'',$day));
|
{
|
||||||
if (is_numeric($strippedDayValue)) {
|
$strippedDayValue = (str_replace(self::$numberSuffixes, '', $day));
|
||||||
return $strippedDayValue;
|
if (is_numeric($strippedDayValue)) {
|
||||||
}
|
return $strippedDayValue;
|
||||||
return $day;
|
}
|
||||||
|
return $day;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
if (!defined('PCLZIP_TEMPORARY_DIR')) {
|
||||||
|
define('PCLZIP_TEMPORARY_DIR', PHPExcel_Shared_File::sys_get_temp_dir() . DIRECTORY_SEPARATOR);
|
||||||
|
}
|
||||||
|
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/PCLZip/pclzip.lib.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHPExcel
|
* PHPExcel_Shared_ZipArchive
|
||||||
*
|
*
|
||||||
* Copyright (c) 2006 - 2015 PHPExcel
|
* Copyright (c) 2006 - 2015 PHPExcel
|
||||||
*
|
*
|
||||||
@ -21,95 +27,81 @@
|
|||||||
* @category PHPExcel
|
* @category PHPExcel
|
||||||
* @package PHPExcel_Shared_ZipArchive
|
* @package PHPExcel_Shared_ZipArchive
|
||||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
* @version ##VERSION##, ##DATE##
|
* @version ##VERSION##, ##DATE##
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('PCLZIP_TEMPORARY_DIR')) {
|
|
||||||
define('PCLZIP_TEMPORARY_DIR', PHPExcel_Shared_File::sys_get_temp_dir() . DIRECTORY_SEPARATOR);
|
|
||||||
}
|
|
||||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/PCLZip/pclzip.lib.php';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PHPExcel_Shared_ZipArchive
|
|
||||||
*
|
|
||||||
* @category PHPExcel
|
|
||||||
* @package PHPExcel_Shared_ZipArchive
|
|
||||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
|
||||||
*/
|
|
||||||
class PHPExcel_Shared_ZipArchive
|
class PHPExcel_Shared_ZipArchive
|
||||||
{
|
{
|
||||||
|
|
||||||
/** constants */
|
/** constants */
|
||||||
const OVERWRITE = 'OVERWRITE';
|
const OVERWRITE = 'OVERWRITE';
|
||||||
const CREATE = 'CREATE';
|
const CREATE = 'CREATE';
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Temporary storage directory
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $_tempDir;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Zip Archive Stream Handle
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $_zip;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a new zip archive
|
* Temporary storage directory
|
||||||
*
|
*
|
||||||
* @param string $fileName Filename for the zip archive
|
* @var string
|
||||||
* @return boolean
|
|
||||||
*/
|
*/
|
||||||
public function open($fileName)
|
private $_tempDir;
|
||||||
{
|
|
||||||
$this->_tempDir = PHPExcel_Shared_File::sys_get_temp_dir();
|
|
||||||
|
|
||||||
$this->_zip = new PclZip($fileName);
|
/**
|
||||||
|
* Zip Archive Stream Handle
|
||||||
return true;
|
*
|
||||||
}
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_zip;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close this zip archive
|
* Open a new zip archive
|
||||||
*
|
*
|
||||||
|
* @param string $fileName Filename for the zip archive
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function close()
|
public function open($fileName)
|
||||||
{
|
{
|
||||||
}
|
$this->_tempDir = PHPExcel_Shared_File::sys_get_temp_dir();
|
||||||
|
|
||||||
|
$this->_zip = new PclZip($fileName);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new file to the zip archive from a string of raw data.
|
* Close this zip archive
|
||||||
*
|
*
|
||||||
* @param string $localname Directory/Name of the file to add to the zip archive
|
|
||||||
* @param string $contents String of data to add to the zip archive
|
|
||||||
*/
|
*/
|
||||||
public function addFromString($localname, $contents)
|
public function close()
|
||||||
{
|
{
|
||||||
$filenameParts = pathinfo($localname);
|
}
|
||||||
|
|
||||||
$handle = fopen($this->_tempDir.'/'.$filenameParts["basename"], "wb");
|
|
||||||
fwrite($handle, $contents);
|
|
||||||
fclose($handle);
|
|
||||||
|
|
||||||
$res = $this->_zip->add($this->_tempDir.'/'.$filenameParts["basename"],
|
/**
|
||||||
PCLZIP_OPT_REMOVE_PATH, $this->_tempDir,
|
* Add a new file to the zip archive from a string of raw data.
|
||||||
PCLZIP_OPT_ADD_PATH, $filenameParts["dirname"]
|
*
|
||||||
);
|
* @param string $localname Directory/Name of the file to add to the zip archive
|
||||||
if ($res == 0) {
|
* @param string $contents String of data to add to the zip archive
|
||||||
throw new PHPExcel_Writer_Exception("Error zipping files : " . $this->_zip->errorInfo(true));
|
*/
|
||||||
}
|
public function addFromString($localname, $contents)
|
||||||
|
{
|
||||||
|
$filenameParts = pathinfo($localname);
|
||||||
|
|
||||||
unlink($this->_tempDir.'/'.$filenameParts["basename"]);
|
$handle = fopen($this->_tempDir.'/'.$filenameParts["basename"], "wb");
|
||||||
}
|
fwrite($handle, $contents);
|
||||||
|
fclose($handle);
|
||||||
|
|
||||||
|
$res = $this->_zip->add($this->_tempDir.'/'.$filenameParts["basename"],
|
||||||
|
PCLZIP_OPT_REMOVE_PATH, $this->_tempDir,
|
||||||
|
PCLZIP_OPT_ADD_PATH, $filenameParts["dirname"]
|
||||||
|
);
|
||||||
|
if ($res == 0) {
|
||||||
|
throw new PHPExcel_Writer_Exception("Error zipping files : " . $this->_zip->errorInfo(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
unlink($this->_tempDir.'/'.$filenameParts["basename"]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find if given fileName exist in archive (Emulate ZipArchive locateName())
|
* Find if given fileName exist in archive (Emulate ZipArchive locateName())
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHPExcel
|
* PHPExcel_Shared_ZipStreamWrapper
|
||||||
*
|
*
|
||||||
* Copyright (c) 2006 - 2015 PHPExcel
|
* Copyright (c) 2006 - 2015 PHPExcel
|
||||||
*
|
*
|
||||||
@ -24,21 +25,12 @@
|
|||||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
* @version ##VERSION##, ##DATE##
|
* @version ##VERSION##, ##DATE##
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PHPExcel_Shared_ZipStreamWrapper
|
|
||||||
*
|
|
||||||
* @category PHPExcel
|
|
||||||
* @package PHPExcel_Shared
|
|
||||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
|
||||||
*/
|
|
||||||
class PHPExcel_Shared_ZipStreamWrapper {
|
class PHPExcel_Shared_ZipStreamWrapper {
|
||||||
/**
|
/**
|
||||||
* Internal ZipAcrhive
|
* Internal ZipAcrhive
|
||||||
*
|
*
|
||||||
* @var ZipAcrhive
|
* @var ZipAcrhive
|
||||||
*/
|
*/
|
||||||
private $_archive;
|
private $_archive;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,18 +58,18 @@ class PHPExcel_Shared_ZipStreamWrapper {
|
|||||||
* Register wrapper
|
* Register wrapper
|
||||||
*/
|
*/
|
||||||
public static function register() {
|
public static function register() {
|
||||||
@stream_wrapper_unregister("zip");
|
@stream_wrapper_unregister("zip");
|
||||||
@stream_wrapper_register("zip", __CLASS__);
|
@stream_wrapper_register("zip", __CLASS__);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements support for fopen().
|
* Implements support for fopen().
|
||||||
*
|
*
|
||||||
* @param string $path resource name including scheme, e.g.
|
* @param string $path resource name including scheme, e.g.
|
||||||
* @param string $mode only "r" is supported
|
* @param string $mode only "r" is supported
|
||||||
* @param int $options mask of STREAM_REPORT_ERRORS and STREAM_USE_PATH
|
* @param int $options mask of STREAM_REPORT_ERRORS and STREAM_USE_PATH
|
||||||
* @param string &$openedPath absolute path of the opened stream (out parameter)
|
* @param string &$openedPath absolute path of the opened stream (out parameter)
|
||||||
* @return bool true on success
|
* @return bool true on success
|
||||||
*/
|
*/
|
||||||
public function stream_open($path, $mode, $options, &$opened_path) {
|
public function stream_open($path, $mode, $options, &$opened_path) {
|
||||||
// Check for mode
|
// Check for mode
|
||||||
@ -85,9 +77,9 @@ class PHPExcel_Shared_ZipStreamWrapper {
|
|||||||
throw new PHPExcel_Reader_Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.');
|
throw new PHPExcel_Reader_Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$pos = strrpos($path, '#');
|
$pos = strrpos($path, '#');
|
||||||
$url['host'] = substr($path, 6, $pos - 6); // 6: strlen('zip://')
|
$url['host'] = substr($path, 6, $pos - 6); // 6: strlen('zip://')
|
||||||
$url['fragment'] = substr($path, $pos + 1);
|
$url['fragment'] = substr($path, $pos + 1);
|
||||||
|
|
||||||
// Open archive
|
// Open archive
|
||||||
$this->_archive = new ZipArchive();
|
$this->_archive = new ZipArchive();
|
||||||
@ -101,37 +93,37 @@ class PHPExcel_Shared_ZipStreamWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements support for fstat().
|
* Implements support for fstat().
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function statName() {
|
public function statName() {
|
||||||
return $this->_fileNameInArchive;
|
return $this->_fileNameInArchive;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements support for fstat().
|
* Implements support for fstat().
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function url_stat() {
|
public function url_stat() {
|
||||||
return $this->statName( $this->_fileNameInArchive );
|
return $this->statName( $this->_fileNameInArchive );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements support for fstat().
|
* Implements support for fstat().
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function stream_stat() {
|
public function stream_stat() {
|
||||||
return $this->_archive->statName( $this->_fileNameInArchive );
|
return $this->_archive->statName( $this->_fileNameInArchive );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements support for fread(), fgets() etc.
|
* Implements support for fread(), fgets() etc.
|
||||||
*
|
*
|
||||||
* @param int $count maximum number of bytes to read
|
* @param int $count maximum number of bytes to read
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function stream_read($count) {
|
function stream_read($count) {
|
||||||
$ret = substr($this->_data, $this->_position, $count);
|
$ret = substr($this->_data, $this->_position, $count);
|
||||||
@ -140,10 +132,10 @@ class PHPExcel_Shared_ZipStreamWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the position of the file pointer, i.e. its offset into the file
|
* Returns the position of the file pointer, i.e. its offset into the file
|
||||||
* stream. Implements support for ftell().
|
* stream. Implements support for ftell().
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function stream_tell() {
|
public function stream_tell() {
|
||||||
return $this->_position;
|
return $this->_position;
|
||||||
@ -151,8 +143,8 @@ class PHPExcel_Shared_ZipStreamWrapper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* EOF stream
|
* EOF stream
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function stream_eof() {
|
public function stream_eof() {
|
||||||
return $this->_position >= strlen($this->_data);
|
return $this->_position >= strlen($this->_data);
|
||||||
@ -160,10 +152,10 @@ class PHPExcel_Shared_ZipStreamWrapper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Seek stream
|
* Seek stream
|
||||||
*
|
*
|
||||||
* @param int $offset byte offset
|
* @param int $offset byte offset
|
||||||
* @param int $whence SEEK_SET, SEEK_CUR or SEEK_END
|
* @param int $whence SEEK_SET, SEEK_CUR or SEEK_END
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function stream_seek($offset, $whence) {
|
public function stream_seek($offset, $whence) {
|
||||||
switch ($whence) {
|
switch ($whence) {
|
||||||
|
Loading…
Reference in New Issue
Block a user