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
|
||||
|
||||
/**
|
||||
* PHPExcel
|
||||
* PHPExcel_Shared_CodePage
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
|
@ -21,86 +22,76 @@
|
|||
* @category PHPExcel
|
||||
* @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
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @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
|
||||
{
|
||||
/**
|
||||
* Convert Microsoft Code Page Identifier to Code Page Name which iconv
|
||||
* and mbstring understands
|
||||
*
|
||||
* @param integer $codePage Microsoft Code Page Indentifier
|
||||
* @return string Code Page Name
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public static function NumberToName($codePage = 1252)
|
||||
{
|
||||
switch ($codePage) {
|
||||
case 367: return 'ASCII'; break; // ASCII
|
||||
case 437: return 'CP437'; break; // OEM US
|
||||
case 720: throw new PHPExcel_Exception('Code page 720 not supported.');
|
||||
break; // OEM Arabic
|
||||
case 737: return 'CP737'; break; // OEM Greek
|
||||
case 775: return 'CP775'; break; // OEM Baltic
|
||||
case 850: return 'CP850'; break; // OEM Latin I
|
||||
case 852: return 'CP852'; break; // OEM Latin II (Central European)
|
||||
case 855: return 'CP855'; break; // OEM Cyrillic
|
||||
case 857: return 'CP857'; break; // OEM Turkish
|
||||
case 858: return 'CP858'; break; // OEM Multilingual Latin I with Euro
|
||||
case 860: return 'CP860'; break; // OEM Portugese
|
||||
case 861: return 'CP861'; break; // OEM Icelandic
|
||||
case 862: return 'CP862'; break; // OEM Hebrew
|
||||
case 863: return 'CP863'; break; // OEM Canadian (French)
|
||||
case 864: return 'CP864'; break; // OEM Arabic
|
||||
case 865: return 'CP865'; break; // OEM Nordic
|
||||
case 866: return 'CP866'; break; // OEM Cyrillic (Russian)
|
||||
case 869: return 'CP869'; break; // OEM Greek (Modern)
|
||||
case 874: return 'CP874'; break; // ANSI Thai
|
||||
case 932: return 'CP932'; break; // ANSI Japanese Shift-JIS
|
||||
case 936: return 'CP936'; break; // ANSI Chinese Simplified GBK
|
||||
case 949: return 'CP949'; break; // ANSI Korean (Wansung)
|
||||
case 950: return 'CP950'; break; // ANSI Chinese Traditional BIG5
|
||||
case 1200: return 'UTF-16LE'; break; // UTF-16 (BIFF8)
|
||||
case 1250: return 'CP1250'; break; // ANSI Latin II (Central European)
|
||||
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 1252: return 'CP1252'; break; // ANSI Latin I (BIFF4-BIFF7)
|
||||
case 1253: return 'CP1253'; break; // ANSI Greek
|
||||
case 1254: return 'CP1254'; break; // ANSI Turkish
|
||||
case 1255: return 'CP1255'; break; // ANSI Hebrew
|
||||
case 1256: return 'CP1256'; break; // ANSI Arabic
|
||||
case 1257: return 'CP1257'; break; // ANSI Baltic
|
||||
case 1258: return 'CP1258'; break; // ANSI Vietnamese
|
||||
case 1361: return 'CP1361'; break; // ANSI Korean (Johab)
|
||||
case 10000: return 'MAC'; break; // Apple Roman
|
||||
case 10001: return 'CP932'; break; // Macintosh Japanese
|
||||
case 10002: return 'CP950'; break; // Macintosh Chinese Traditional
|
||||
case 10003: return 'CP1361'; break; // Macintosh Korean
|
||||
case 10006: return 'MACGREEK'; break; // Macintosh Greek
|
||||
case 10007: return 'MACCYRILLIC'; break; // Macintosh Cyrillic
|
||||
case 10008: return 'CP936'; break; // Macintosh - Simplified Chinese (GB 2312)
|
||||
case 10029: return 'MACCENTRALEUROPE'; break; // Macintosh Central Europe
|
||||
case 10079: return 'MACICELAND'; break; // Macintosh Icelandic
|
||||
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 32768: return 'MAC'; break; // Apple Roman
|
||||
case 32769: throw new PHPExcel_Exception('Code page 32769 not supported.');
|
||||
break; // ANSI Latin I (BIFF2-BIFF3)
|
||||
case 65000: return 'UTF-7'; break; // Unicode (UTF-7)
|
||||
case 65001: return 'UTF-8'; break; // Unicode (UTF-8)
|
||||
}
|
||||
|
||||
throw new PHPExcel_Exception('Unknown codepage: ' . $codePage);
|
||||
}
|
||||
/**
|
||||
* Convert Microsoft Code Page Identifier to Code Page Name which iconv
|
||||
* and mbstring understands
|
||||
*
|
||||
* @param integer $codePage Microsoft Code Page Indentifier
|
||||
* @return string Code Page Name
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public static function NumberToName($codePage = 1252)
|
||||
{
|
||||
switch ($codePage) {
|
||||
case 367: return 'ASCII'; break; // ASCII
|
||||
case 437: return 'CP437'; break; // OEM US
|
||||
case 720: throw new PHPExcel_Exception('Code page 720 not supported.');
|
||||
break; // OEM Arabic
|
||||
case 737: return 'CP737'; break; // OEM Greek
|
||||
case 775: return 'CP775'; break; // OEM Baltic
|
||||
case 850: return 'CP850'; break; // OEM Latin I
|
||||
case 852: return 'CP852'; break; // OEM Latin II (Central European)
|
||||
case 855: return 'CP855'; break; // OEM Cyrillic
|
||||
case 857: return 'CP857'; break; // OEM Turkish
|
||||
case 858: return 'CP858'; break; // OEM Multilingual Latin I with Euro
|
||||
case 860: return 'CP860'; break; // OEM Portugese
|
||||
case 861: return 'CP861'; break; // OEM Icelandic
|
||||
case 862: return 'CP862'; break; // OEM Hebrew
|
||||
case 863: return 'CP863'; break; // OEM Canadian (French)
|
||||
case 864: return 'CP864'; break; // OEM Arabic
|
||||
case 865: return 'CP865'; break; // OEM Nordic
|
||||
case 866: return 'CP866'; break; // OEM Cyrillic (Russian)
|
||||
case 869: return 'CP869'; break; // OEM Greek (Modern)
|
||||
case 874: return 'CP874'; break; // ANSI Thai
|
||||
case 932: return 'CP932'; break; // ANSI Japanese Shift-JIS
|
||||
case 936: return 'CP936'; break; // ANSI Chinese Simplified GBK
|
||||
case 949: return 'CP949'; break; // ANSI Korean (Wansung)
|
||||
case 950: return 'CP950'; break; // ANSI Chinese Traditional BIG5
|
||||
case 1200: return 'UTF-16LE'; break; // UTF-16 (BIFF8)
|
||||
case 1250: return 'CP1250'; break; // ANSI Latin II (Central European)
|
||||
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 1252: return 'CP1252'; break; // ANSI Latin I (BIFF4-BIFF7)
|
||||
case 1253: return 'CP1253'; break; // ANSI Greek
|
||||
case 1254: return 'CP1254'; break; // ANSI Turkish
|
||||
case 1255: return 'CP1255'; break; // ANSI Hebrew
|
||||
case 1256: return 'CP1256'; break; // ANSI Arabic
|
||||
case 1257: return 'CP1257'; break; // ANSI Baltic
|
||||
case 1258: return 'CP1258'; break; // ANSI Vietnamese
|
||||
case 1361: return 'CP1361'; break; // ANSI Korean (Johab)
|
||||
case 10000: return 'MAC'; break; // Apple Roman
|
||||
case 10001: return 'CP932'; break; // Macintosh Japanese
|
||||
case 10002: return 'CP950'; break; // Macintosh Chinese Traditional
|
||||
case 10003: return 'CP1361'; break; // Macintosh Korean
|
||||
case 10006: return 'MACGREEK'; break; // Macintosh Greek
|
||||
case 10007: return 'MACCYRILLIC'; break; // Macintosh Cyrillic
|
||||
case 10008: return 'CP936'; break; // Macintosh - Simplified Chinese (GB 2312)
|
||||
case 10029: return 'MACCENTRALEUROPE'; break; // Macintosh Central Europe
|
||||
case 10079: return 'MACICELAND'; break; // Macintosh Icelandic
|
||||
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 32768: return 'MAC'; break; // Apple Roman
|
||||
case 32769: throw new PHPExcel_Exception('Code page 32769 not supported.');
|
||||
break; // ANSI Latin I (BIFF2-BIFF3)
|
||||
case 65000: return 'UTF-7'; break; // Unicode (UTF-7)
|
||||
case 65001: return 'UTF-8'; break; // Unicode (UTF-8)
|
||||
}
|
||||
|
||||
throw new PHPExcel_Exception('Unknown codepage: ' . $codePage);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel
|
||||
* PHPExcel_Shared_Date
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
|
@ -20,360 +20,363 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @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
|
||||
* @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##
|
||||
*/
|
||||
class PHPExcel_Shared_Date
|
||||
{
|
||||
/** constants */
|
||||
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
|
||||
/** constants */
|
||||
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
|
||||
|
||||
/*
|
||||
* Names of the months of the year, indexed by shortname
|
||||
* Planned usage for locale settings
|
||||
*
|
||||
* @public
|
||||
* @var string[]
|
||||
*/
|
||||
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',
|
||||
);
|
||||
/*
|
||||
* Names of the months of the year, indexed by shortname
|
||||
* Planned usage for locale settings
|
||||
*
|
||||
* @public
|
||||
* @var string[]
|
||||
*/
|
||||
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',
|
||||
);
|
||||
|
||||
/*
|
||||
* 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',
|
||||
);
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* @private
|
||||
* @var int
|
||||
*/
|
||||
protected static $_excelBaseDate = self::CALENDAR_WINDOWS_1900;
|
||||
/*
|
||||
* Base calendar year to use for calculations
|
||||
*
|
||||
* @private
|
||||
* @var int
|
||||
*/
|
||||
protected static $excelBaseDate = self::CALENDAR_WINDOWS_1900;
|
||||
|
||||
/**
|
||||
* Set the Excel calendar (Windows 1900 or Mac 1904)
|
||||
*
|
||||
* @param integer $baseDate Excel base date (1900 or 1904)
|
||||
* @return boolean Success or failure
|
||||
*/
|
||||
public static function setExcelCalendar($baseDate) {
|
||||
if (($baseDate == self::CALENDAR_WINDOWS_1900) ||
|
||||
($baseDate == self::CALENDAR_MAC_1904)) {
|
||||
self::$_excelBaseDate = $baseDate;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
} // function setExcelCalendar()
|
||||
/**
|
||||
* Set the Excel calendar (Windows 1900 or Mac 1904)
|
||||
*
|
||||
* @param integer $baseDate Excel base date (1900 or 1904)
|
||||
* @return boolean Success or failure
|
||||
*/
|
||||
public static function setExcelCalendar($baseDate)
|
||||
{
|
||||
if (($baseDate == self::CALENDAR_WINDOWS_1900) ||
|
||||
($baseDate == self::CALENDAR_MAC_1904)) {
|
||||
self::$excelBaseDate = $baseDate;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the Excel calendar (Windows 1900 or Mac 1904)
|
||||
*
|
||||
* @return integer Excel base date (1900 or 1904)
|
||||
*/
|
||||
public static function getExcelCalendar() {
|
||||
return self::$_excelBaseDate;
|
||||
} // function getExcelCalendar()
|
||||
/**
|
||||
* Return the Excel calendar (Windows 1900 or Mac 1904)
|
||||
*
|
||||
* @return integer Excel base date (1900 or 1904)
|
||||
*/
|
||||
public static function getExcelCalendar()
|
||||
{
|
||||
return self::$excelBaseDate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a date from Excel to PHP
|
||||
*
|
||||
* @param long $dateValue Excel date/time value
|
||||
* @param boolean $adjustToTimezone Flag indicating whether $dateValue should be treated as
|
||||
* a UST timestamp, or adjusted to UST
|
||||
* @param string $timezone The timezone for finding the adjustment from UST
|
||||
* @return long PHP serialized date/time
|
||||
*/
|
||||
public static function ExcelToPHP($dateValue = 0, $adjustToTimezone = FALSE, $timezone = NULL) {
|
||||
if (self::$_excelBaseDate == self::CALENDAR_WINDOWS_1900) {
|
||||
$my_excelBaseDate = 25569;
|
||||
// Adjust for the spurious 29-Feb-1900 (Day 60)
|
||||
if ($dateValue < 60) {
|
||||
--$my_excelBaseDate;
|
||||
}
|
||||
} else {
|
||||
$my_excelBaseDate = 24107;
|
||||
}
|
||||
/**
|
||||
* Convert a date from Excel to PHP
|
||||
*
|
||||
* @param long $dateValue Excel date/time value
|
||||
* @param boolean $adjustToTimezone Flag indicating whether $dateValue should be treated as
|
||||
* a UST timestamp, or adjusted to UST
|
||||
* @param string $timezone The timezone for finding the adjustment from UST
|
||||
* @return long PHP serialized date/time
|
||||
*/
|
||||
public static function ExcelToPHP($dateValue = 0, $adjustToTimezone = false, $timezone = null)
|
||||
{
|
||||
if (self::$excelBaseDate == self::CALENDAR_WINDOWS_1900) {
|
||||
$myexcelBaseDate = 25569;
|
||||
// Adjust for the spurious 29-Feb-1900 (Day 60)
|
||||
if ($dateValue < 60) {
|
||||
--$myexcelBaseDate;
|
||||
}
|
||||
} else {
|
||||
$myexcelBaseDate = 24107;
|
||||
}
|
||||
|
||||
// Perform conversion
|
||||
if ($dateValue >= 1) {
|
||||
$utcDays = $dateValue - $my_excelBaseDate;
|
||||
$returnValue = round($utcDays * 86400);
|
||||
if (($returnValue <= PHP_INT_MAX) && ($returnValue >= -PHP_INT_MAX)) {
|
||||
$returnValue = (integer) $returnValue;
|
||||
}
|
||||
} else {
|
||||
$hours = round($dateValue * 24);
|
||||
$mins = round($dateValue * 1440) - round($hours * 60);
|
||||
$secs = round($dateValue * 86400) - round($hours * 3600) - round($mins * 60);
|
||||
$returnValue = (integer) gmmktime($hours, $mins, $secs);
|
||||
}
|
||||
// Perform conversion
|
||||
if ($dateValue >= 1) {
|
||||
$utcDays = $dateValue - $myexcelBaseDate;
|
||||
$returnValue = round($utcDays * 86400);
|
||||
if (($returnValue <= PHP_INT_MAX) && ($returnValue >= -PHP_INT_MAX)) {
|
||||
$returnValue = (integer) $returnValue;
|
||||
}
|
||||
} else {
|
||||
$hours = round($dateValue * 24);
|
||||
$mins = round($dateValue * 1440) - round($hours * 60);
|
||||
$secs = round($dateValue * 86400) - round($hours * 3600) - round($mins * 60);
|
||||
$returnValue = (integer) gmmktime($hours, $mins, $secs);
|
||||
}
|
||||
|
||||
$timezoneAdjustment = ($adjustToTimezone) ?
|
||||
PHPExcel_Shared_TimeZone::getTimezoneAdjustment($timezone, $returnValue) :
|
||||
0;
|
||||
$timezoneAdjustment = ($adjustToTimezone) ?
|
||||
PHPExcel_Shared_TimeZone::getTimezoneAdjustment($timezone, $returnValue) :
|
||||
0;
|
||||
|
||||
// Return
|
||||
return $returnValue + $timezoneAdjustment;
|
||||
} // function ExcelToPHP()
|
||||
return $returnValue + $timezoneAdjustment;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a date from Excel to a PHP Date/Time object
|
||||
*
|
||||
* @param integer $dateValue Excel date/time value
|
||||
* @return DateTime PHP date/time object
|
||||
*/
|
||||
public static function ExcelToPHPObject($dateValue = 0) {
|
||||
$dateTime = self::ExcelToPHP($dateValue);
|
||||
$days = floor($dateTime / 86400);
|
||||
$time = round((($dateTime / 86400) - $days) * 86400);
|
||||
$hours = round($time / 3600);
|
||||
$minutes = round($time / 60) - ($hours * 60);
|
||||
$seconds = round($time) - ($hours * 3600) - ($minutes * 60);
|
||||
/**
|
||||
* Convert a date from Excel to a PHP Date/Time object
|
||||
*
|
||||
* @param integer $dateValue Excel date/time value
|
||||
* @return DateTime PHP date/time object
|
||||
*/
|
||||
public static function ExcelToPHPObject($dateValue = 0)
|
||||
{
|
||||
$dateTime = self::ExcelToPHP($dateValue);
|
||||
$days = floor($dateTime / 86400);
|
||||
$time = round((($dateTime / 86400) - $days) * 86400);
|
||||
$hours = round($time / 3600);
|
||||
$minutes = round($time / 60) - ($hours * 60);
|
||||
$seconds = round($time) - ($hours * 3600) - ($minutes * 60);
|
||||
|
||||
$dateObj = date_create('1-Jan-1970+'.$days.' days');
|
||||
$dateObj->setTime($hours,$minutes,$seconds);
|
||||
$dateObj = date_create('1-Jan-1970+'.$days.' days');
|
||||
$dateObj->setTime($hours,$minutes,$seconds);
|
||||
|
||||
return $dateObj;
|
||||
} // function ExcelToPHPObject()
|
||||
return $dateObj;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a date from PHP to Excel
|
||||
*
|
||||
* @param mixed $dateValue PHP serialized date/time or date object
|
||||
* @param boolean $adjustToTimezone Flag indicating whether $dateValue should be treated as
|
||||
* a UST timestamp, or adjusted to UST
|
||||
* @param string $timezone The timezone for finding the adjustment from UST
|
||||
* @return mixed Excel date/time value
|
||||
* or boolean FALSE on failure
|
||||
*/
|
||||
public static function PHPToExcel($dateValue = 0, $adjustToTimezone = FALSE, $timezone = NULL) {
|
||||
$saveTimeZone = date_default_timezone_get();
|
||||
date_default_timezone_set('UTC');
|
||||
$retValue = FALSE;
|
||||
if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) {
|
||||
$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),
|
||||
date('H',$dateValue), date('i',$dateValue), date('s',$dateValue)
|
||||
);
|
||||
}
|
||||
date_default_timezone_set($saveTimeZone);
|
||||
/**
|
||||
* Convert a date from PHP to Excel
|
||||
*
|
||||
* @param mixed $dateValue PHP serialized date/time or date object
|
||||
* @param boolean $adjustToTimezone Flag indicating whether $dateValue should be treated as
|
||||
* a UST timestamp, or adjusted to UST
|
||||
* @param string $timezone The timezone for finding the adjustment from UST
|
||||
* @return mixed Excel date/time value
|
||||
* or boolean FALSE on failure
|
||||
*/
|
||||
public static function PHPToExcel($dateValue = 0, $adjustToTimezone = false, $timezone = null)
|
||||
{
|
||||
$saveTimeZone = date_default_timezone_get();
|
||||
date_default_timezone_set('UTC');
|
||||
$retValue = false;
|
||||
if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) {
|
||||
$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),
|
||||
date('H',$dateValue), date('i',$dateValue), date('s',$dateValue)
|
||||
);
|
||||
}
|
||||
date_default_timezone_set($saveTimeZone);
|
||||
|
||||
return $retValue;
|
||||
} // function PHPToExcel()
|
||||
return $retValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* FormattedPHPToExcel
|
||||
*
|
||||
* @param long $year
|
||||
* @param long $month
|
||||
* @param long $day
|
||||
* @param long $hours
|
||||
* @param long $minutes
|
||||
* @param long $seconds
|
||||
* @return long Excel date/time value
|
||||
*/
|
||||
public static function FormattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0) {
|
||||
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
|
||||
//
|
||||
$excel1900isLeapYear = TRUE;
|
||||
if (($year == 1900) && ($month <= 2)) { $excel1900isLeapYear = FALSE; }
|
||||
$my_excelBaseDate = 2415020;
|
||||
} else {
|
||||
$my_excelBaseDate = 2416481;
|
||||
$excel1900isLeapYear = FALSE;
|
||||
}
|
||||
/**
|
||||
* FormattedPHPToExcel
|
||||
*
|
||||
* @param long $year
|
||||
* @param long $month
|
||||
* @param long $day
|
||||
* @param long $hours
|
||||
* @param long $minutes
|
||||
* @param long $seconds
|
||||
* @return long Excel date/time value
|
||||
*/
|
||||
public static function FormattedPHPToExcel($year, $month, $day, $hours = 0, $minutes = 0, $seconds = 0)
|
||||
{
|
||||
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
|
||||
//
|
||||
$excel1900isLeapYear = true;
|
||||
if (($year == 1900) && ($month <= 2)) {
|
||||
$excel1900isLeapYear = false;
|
||||
}
|
||||
$myexcelBaseDate = 2415020;
|
||||
} else {
|
||||
$myexcelBaseDate = 2416481;
|
||||
$excel1900isLeapYear = false;
|
||||
}
|
||||
|
||||
// Julian base date Adjustment
|
||||
if ($month > 2) {
|
||||
$month -= 3;
|
||||
} else {
|
||||
$month += 9;
|
||||
--$year;
|
||||
}
|
||||
// Julian base date Adjustment
|
||||
if ($month > 2) {
|
||||
$month -= 3;
|
||||
} else {
|
||||
$month += 9;
|
||||
--$year;
|
||||
}
|
||||
|
||||
// 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);
|
||||
$decade = substr($year,2,2);
|
||||
$excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $my_excelBaseDate + $excel1900isLeapYear;
|
||||
// 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);
|
||||
$decade = substr($year,2,2);
|
||||
$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;
|
||||
} // function FormattedPHPToExcel()
|
||||
return (float) $excelDate + $excelTime;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is a given cell a date/time?
|
||||
*
|
||||
* @param PHPExcel_Cell $pCell
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isDateTime(PHPExcel_Cell $pCell) {
|
||||
return self::isDateTimeFormat(
|
||||
$pCell->getWorksheet()->getStyle(
|
||||
$pCell->getCoordinate()
|
||||
)->getNumberFormat()
|
||||
);
|
||||
} // function isDateTime()
|
||||
/**
|
||||
* Is a given cell a date/time?
|
||||
*
|
||||
* @param PHPExcel_Cell $pCell
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isDateTime(PHPExcel_Cell $pCell)
|
||||
{
|
||||
return self::isDateTimeFormat(
|
||||
$pCell->getWorksheet()->getStyle(
|
||||
$pCell->getCoordinate()
|
||||
)->getNumberFormat()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is a given number format a date/time?
|
||||
*
|
||||
* @param PHPExcel_Style_NumberFormat $pFormat
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isDateTimeFormat(PHPExcel_Style_NumberFormat $pFormat) {
|
||||
return self::isDateTimeFormatCode($pFormat->getFormatCode());
|
||||
} // function isDateTimeFormat()
|
||||
/**
|
||||
* Is a given number format a date/time?
|
||||
*
|
||||
* @param PHPExcel_Style_NumberFormat $pFormat
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isDateTimeFormat(PHPExcel_Style_NumberFormat $pFormat)
|
||||
{
|
||||
return self::isDateTimeFormatCode($pFormat->getFormatCode());
|
||||
}
|
||||
|
||||
|
||||
private static $possibleDateFormatCharacters = 'eymdHs';
|
||||
private static $possibleDateFormatCharacters = 'eymdHs';
|
||||
|
||||
/**
|
||||
* Is a given number format code a date/time?
|
||||
*
|
||||
* @param string $pFormatCode
|
||||
* @return boolean
|
||||
*/
|
||||
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)
|
||||
return FALSE;
|
||||
/**
|
||||
* Is a given number format code a date/time?
|
||||
*
|
||||
* @param string $pFormatCode
|
||||
* @return boolean
|
||||
*/
|
||||
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)
|
||||
return false;
|
||||
if (preg_match('/[0#]E[+-]0/i', $pFormatCode))
|
||||
// Scientific format
|
||||
return FALSE;
|
||||
// Switch on formatcode
|
||||
switch ($pFormatCode) {
|
||||
// Explicitly defined date formats
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYMINUS:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMMINUS:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_MYMINUS:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME1:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME2:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME5:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME6:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME7:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME8:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX14:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX16:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX17:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22:
|
||||
return TRUE;
|
||||
}
|
||||
// Scientific format
|
||||
return false;
|
||||
// Switch on formatcode
|
||||
switch ($pFormatCode) {
|
||||
// Explicitly defined date formats
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYMINUS:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMMINUS:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_MYMINUS:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME1:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME2:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME5:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME6:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME7:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME8:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX14:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX16:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX17:
|
||||
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22:
|
||||
return true;
|
||||
}
|
||||
|
||||
// Typically number, currency or accounting (or occasionally fraction) formats
|
||||
if ((substr($pFormatCode,0,1) == '_') || (substr($pFormatCode,0,2) == '0 ')) {
|
||||
return FALSE;
|
||||
}
|
||||
// Try checking for any of the date formatting characters that don't appear within square braces
|
||||
if (preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i',$pFormatCode)) {
|
||||
// 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
|
||||
if (strpos($pFormatCode,'"') !== FALSE) {
|
||||
$segMatcher = FALSE;
|
||||
foreach(explode('"',$pFormatCode) as $subVal) {
|
||||
// Only test in alternate array entries (the non-quoted blocks)
|
||||
if (($segMatcher = !$segMatcher) &&
|
||||
(preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i',$subVal))) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
// Typically number, currency or accounting (or occasionally fraction) formats
|
||||
if ((substr($pFormatCode, 0, 1) == '_') || (substr($pFormatCode, 0, 2) == '0 ')) {
|
||||
return false;
|
||||
}
|
||||
// Try checking for any of the date formatting characters that don't appear within square braces
|
||||
if (preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i', $pFormatCode)) {
|
||||
// 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
|
||||
if (strpos($pFormatCode, '"') !== false) {
|
||||
$segMatcher = false;
|
||||
foreach(explode('"', $pFormatCode) as $subVal) {
|
||||
// Only test in alternate array entries (the non-quoted blocks)
|
||||
if (($segMatcher = !$segMatcher) &&
|
||||
(preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i', $subVal))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// No date...
|
||||
return FALSE;
|
||||
} // function isDateTimeFormatCode()
|
||||
// No date...
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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'
|
||||
* @return float|FALSE Excel date/time serial value
|
||||
*/
|
||||
public static function stringToExcel($dateValue = '') {
|
||||
if (strlen($dateValue) < 2)
|
||||
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;
|
||||
/**
|
||||
* 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'
|
||||
* @return float|FALSE Excel date/time serial value
|
||||
*/
|
||||
public static function stringToExcel($dateValue = '')
|
||||
{
|
||||
if (strlen($dateValue) < 2)
|
||||
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()) {
|
||||
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 ($dateValueNew === PHPExcel_Calculation_Functions::VALUE()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
foreach(self::$_monthNames as $shortMonthName => $longMonthName) {
|
||||
foreach(self::$monthNames as $shortMonthName => $longMonthName) {
|
||||
if (($month === $longMonthName) || ($month === $shortMonthName)) {
|
||||
return $monthIndex;
|
||||
}
|
||||
|
@ -382,12 +385,12 @@ class PHPExcel_Shared_Date
|
|||
return $month;
|
||||
}
|
||||
|
||||
public static function dayStringToNumber($day) {
|
||||
$strippedDayValue = (str_replace(self::$_numberSuffixes,'',$day));
|
||||
if (is_numeric($strippedDayValue)) {
|
||||
return $strippedDayValue;
|
||||
}
|
||||
return $day;
|
||||
public static function dayStringToNumber($day)
|
||||
{
|
||||
$strippedDayValue = (str_replace(self::$numberSuffixes, '', $day));
|
||||
if (is_numeric($strippedDayValue)) {
|
||||
return $strippedDayValue;
|
||||
}
|
||||
return $day;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
<?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
|
||||
*
|
||||
|
@ -21,95 +27,81 @@
|
|||
* @category PHPExcel
|
||||
* @package PHPExcel_Shared_ZipArchive
|
||||
* @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##
|
||||
*/
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
/** constants */
|
||||
const OVERWRITE = 'OVERWRITE';
|
||||
const CREATE = 'CREATE';
|
||||
|
||||
|
||||
/**
|
||||
* Temporary storage directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_tempDir;
|
||||
|
||||
/**
|
||||
* Zip Archive Stream Handle
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_zip;
|
||||
/** constants */
|
||||
const OVERWRITE = 'OVERWRITE';
|
||||
const CREATE = 'CREATE';
|
||||
|
||||
|
||||
/**
|
||||
* Open a new zip archive
|
||||
*
|
||||
* @param string $fileName Filename for the zip archive
|
||||
* @return boolean
|
||||
* Temporary storage directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public function open($fileName)
|
||||
{
|
||||
$this->_tempDir = PHPExcel_Shared_File::sys_get_temp_dir();
|
||||
private $_tempDir;
|
||||
|
||||
$this->_zip = new PclZip($fileName);
|
||||
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Zip Archive Stream Handle
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @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
|
||||
* Close this zip archive
|
||||
*
|
||||
*/
|
||||
public function addFromString($localname, $contents)
|
||||
{
|
||||
$filenameParts = pathinfo($localname);
|
||||
public function close()
|
||||
{
|
||||
}
|
||||
|
||||
$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));
|
||||
}
|
||||
/**
|
||||
* Add a new file to the zip archive from a string of raw data.
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
$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())
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel
|
||||
* PHPExcel_Shared_ZipStreamWrapper
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
|
@ -24,21 +25,12 @@
|
|||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @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 {
|
||||
/**
|
||||
* Internal ZipAcrhive
|
||||
*
|
||||
* @var ZipAcrhive
|
||||
*/
|
||||
/**
|
||||
* Internal ZipAcrhive
|
||||
*
|
||||
* @var ZipAcrhive
|
||||
*/
|
||||
private $_archive;
|
||||
|
||||
/**
|
||||
|
@ -66,18 +58,18 @@ class PHPExcel_Shared_ZipStreamWrapper {
|
|||
* Register wrapper
|
||||
*/
|
||||
public static function register() {
|
||||
@stream_wrapper_unregister("zip");
|
||||
@stream_wrapper_register("zip", __CLASS__);
|
||||
@stream_wrapper_unregister("zip");
|
||||
@stream_wrapper_register("zip", __CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements support for fopen().
|
||||
*
|
||||
* @param string $path resource name including scheme, e.g.
|
||||
* @param string $mode only "r" is supported
|
||||
* @param int $options mask of STREAM_REPORT_ERRORS and STREAM_USE_PATH
|
||||
* @param string &$openedPath absolute path of the opened stream (out parameter)
|
||||
* @return bool true on success
|
||||
* Implements support for fopen().
|
||||
*
|
||||
* @param string $path resource name including scheme, e.g.
|
||||
* @param string $mode only "r" is supported
|
||||
* @param int $options mask of STREAM_REPORT_ERRORS and STREAM_USE_PATH
|
||||
* @param string &$openedPath absolute path of the opened stream (out parameter)
|
||||
* @return bool true on success
|
||||
*/
|
||||
public function stream_open($path, $mode, $options, &$opened_path) {
|
||||
// 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.');
|
||||
}
|
||||
|
||||
$pos = strrpos($path, '#');
|
||||
$url['host'] = substr($path, 6, $pos - 6); // 6: strlen('zip://')
|
||||
$url['fragment'] = substr($path, $pos + 1);
|
||||
$pos = strrpos($path, '#');
|
||||
$url['host'] = substr($path, 6, $pos - 6); // 6: strlen('zip://')
|
||||
$url['fragment'] = substr($path, $pos + 1);
|
||||
|
||||
// Open archive
|
||||
$this->_archive = new ZipArchive();
|
||||
|
@ -101,37 +93,37 @@ class PHPExcel_Shared_ZipStreamWrapper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements support for fstat().
|
||||
*
|
||||
* @return boolean
|
||||
* Implements support for fstat().
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function statName() {
|
||||
return $this->_fileNameInArchive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements support for fstat().
|
||||
*
|
||||
* @return boolean
|
||||
* Implements support for fstat().
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function url_stat() {
|
||||
return $this->statName( $this->_fileNameInArchive );
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements support for fstat().
|
||||
*
|
||||
* @return boolean
|
||||
* Implements support for fstat().
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function stream_stat() {
|
||||
return $this->_archive->statName( $this->_fileNameInArchive );
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements support for fread(), fgets() etc.
|
||||
*
|
||||
* @param int $count maximum number of bytes to read
|
||||
* @return string
|
||||
* Implements support for fread(), fgets() etc.
|
||||
*
|
||||
* @param int $count maximum number of bytes to read
|
||||
* @return string
|
||||
*/
|
||||
function stream_read($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
|
||||
* stream. Implements support for ftell().
|
||||
*
|
||||
* @return int
|
||||
* Returns the position of the file pointer, i.e. its offset into the file
|
||||
* stream. Implements support for ftell().
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function stream_tell() {
|
||||
return $this->_position;
|
||||
|
@ -151,8 +143,8 @@ class PHPExcel_Shared_ZipStreamWrapper {
|
|||
|
||||
/**
|
||||
* EOF stream
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function stream_eof() {
|
||||
return $this->_position >= strlen($this->_data);
|
||||
|
@ -160,10 +152,10 @@ class PHPExcel_Shared_ZipStreamWrapper {
|
|||
|
||||
/**
|
||||
* Seek stream
|
||||
*
|
||||
* @param int $offset byte offset
|
||||
* @param int $whence SEEK_SET, SEEK_CUR or SEEK_END
|
||||
* @return bool
|
||||
*
|
||||
* @param int $offset byte offset
|
||||
* @param int $whence SEEK_SET, SEEK_CUR or SEEK_END
|
||||
* @return bool
|
||||
*/
|
||||
public function stream_seek($offset, $whence) {
|
||||
switch ($whence) {
|
||||
|
|
Loading…
Reference in New Issue