composer update

This commit is contained in:
Manish Verma
2018-12-05 10:50:52 +05:30
parent 9eabcacfa7
commit 4addd1e9c6
3328 changed files with 156676 additions and 138988 deletions

View File

@@ -1,8 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_CodePage
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,87 +21,136 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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_CodePage
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 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'; // ASCII
case 437:
return 'CP437'; // OEM US
case 720:
throw new PHPExcel_Exception('Code page 720 not supported.'); // OEM Arabic
case 737:
return 'CP737'; // OEM Greek
case 775:
return 'CP775'; // OEM Baltic
case 850:
return 'CP850'; // OEM Latin I
case 852:
return 'CP852'; // OEM Latin II (Central European)
case 855:
return 'CP855'; // OEM Cyrillic
case 857:
return 'CP857'; // OEM Turkish
case 858:
return 'CP858'; // OEM Multilingual Latin I with Euro
case 860:
return 'CP860'; // OEM Portugese
case 861:
return 'CP861'; // OEM Icelandic
case 862:
return 'CP862'; // OEM Hebrew
case 863:
return 'CP863'; // OEM Canadian (French)
case 864:
return 'CP864'; // OEM Arabic
case 865:
return 'CP865'; // OEM Nordic
case 866:
return 'CP866'; // OEM Cyrillic (Russian)
case 869:
return 'CP869'; // OEM Greek (Modern)
case 874:
return 'CP874'; // ANSI Thai
case 932:
return 'CP932'; // ANSI Japanese Shift-JIS
case 936:
return 'CP936'; // ANSI Chinese Simplified GBK
case 949:
return 'CP949'; // ANSI Korean (Wansung)
case 950:
return 'CP950'; // ANSI Chinese Traditional BIG5
case 1200:
return 'UTF-16LE'; // UTF-16 (BIFF8)
case 1250:
return 'CP1250'; // ANSI Latin II (Central European)
case 1251:
return 'CP1251'; // 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'; // ANSI Latin I (BIFF4-BIFF7)
case 1253:
return 'CP1253'; // ANSI Greek
case 1254:
return 'CP1254'; // ANSI Turkish
case 1255:
return 'CP1255'; // ANSI Hebrew
case 1256:
return 'CP1256'; // ANSI Arabic
case 1257:
return 'CP1257'; // ANSI Baltic
case 1258:
return 'CP1258'; // ANSI Vietnamese
case 1361:
return 'CP1361'; // ANSI Korean (Johab)
case 10000:
return 'MAC'; // Apple Roman
case 10001:
return 'CP932'; // Macintosh Japanese
case 10002:
return 'CP950'; // Macintosh Chinese Traditional
case 10003:
return 'CP1361'; // Macintosh Korean
case 10004:
return 'MACARABIC'; // Apple Arabic
case 10005:
return 'MACHEBREW'; // Apple Hebrew
case 10006:
return 'MACGREEK'; // Macintosh Greek
case 10007:
return 'MACCYRILLIC'; // Macintosh Cyrillic
case 10008:
return 'CP936'; // Macintosh - Simplified Chinese (GB 2312)
case 10010:
return 'MACROMANIA'; // Macintosh Romania
case 10017:
return 'MACUKRAINE'; // Macintosh Ukraine
case 10021:
return 'MACTHAI'; // Macintosh Thai
case 10029:
return 'MACCENTRALEUROPE'; // Macintosh Central Europe
case 10079:
return 'MACICELAND'; // Macintosh Icelandic
case 10081:
return 'MACTURKISH'; // Macintosh Turkish
case 10082:
return 'MACCROATIAN'; // Macintosh Croatian
case 21010:
return 'UTF-16LE'; // UTF-16 (BIFF8) This isn't correct, but some Excel writer libraries erroneously use Codepage 21010 for UTF-16LE
case 32768:
return 'MAC'; // Apple Roman
case 32769:
throw new PHPExcel_Exception('Code page 32769 not supported.'); // ANSI Latin I (BIFF2-BIFF3)
case 65000:
return 'UTF-7'; // Unicode (UTF-7)
case 65001:
return 'UTF-8'; // Unicode (UTF-8)
}
throw new PHPExcel_Exception('Unknown codepage: ' . $codePage);
}
}

View File

@@ -1,9 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_Date
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,360 +20,379 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 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 - 2014 PHPExcel (http://www.codeplex.com/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##
*/
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 integer $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 integer 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');
return $retValue;
} // function PHPToExcel()
$timezoneAdjustment = ($adjustToTimezone) ?
PHPExcel_Shared_TimeZone::getTimezoneAdjustment($timezone ? $timezone : $saveTimeZone, $dateValue) :
0;
$retValue = false;
if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) {
$dateValue->add(new DateInterval('PT' . $timezoneAdjustment . '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)) {
$dateValue += $timezoneAdjustment;
$retValue = self::FormattedPHPToExcel(date('Y', $dateValue), date('m', $dateValue), date('d', $dateValue), date('H', $dateValue), date('i', $dateValue), date('s', $dateValue));
} elseif (is_string($dateValue)) {
$retValue = self::stringToExcel($dateValue);
}
date_default_timezone_set($saveTimeZone);
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 integer $year
* @param integer $month
* @param integer $day
* @param integer $hours
* @param integer $minutes
* @param integer $seconds
* @return integer 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;
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;
}
/**
* 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;
}
// 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;
}
// 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;
}
// No date...
return FALSE;
} // function isDateTimeFormatCode()
// 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;
}
/**
* 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) {
/**
* Converts a month name (either a long or a short name) to a month number
*
* @param string $month Month name or abbreviation
* @return integer|string Month number (1 - 12), or the original string argument if it isn't a valid month name
*/
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 +401,18 @@ 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;
/**
* Strips an ordinal froma numeric value
*
* @param string $day Day number with an ordinal
* @return integer|string The integer value with any ordinal stripped, or the original string argument if it isn't a valid numeric
*/
public static function dayStringToNumber($day)
{
$strippedDayValue = (str_replace(self::$numberSuffixes, '', $day));
if (is_numeric($strippedDayValue)) {
return (integer) $strippedDayValue;
}
return $day;
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,8 +20,8 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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##
*/
@@ -31,242 +31,240 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Drawing
{
/**
* Convert pixels to EMU
*
* @param int $pValue Value in pixels
* @return int Value in EMU
*/
public static function pixelsToEMU($pValue = 0) {
return round($pValue * 9525);
}
/**
* Convert pixels to EMU
*
* @param int $pValue Value in pixels
* @return int Value in EMU
*/
public static function pixelsToEMU($pValue = 0)
{
return round($pValue * 9525);
}
/**
* Convert EMU to pixels
*
* @param int $pValue Value in EMU
* @return int Value in pixels
*/
public static function EMUToPixels($pValue = 0) {
if ($pValue != 0) {
return round($pValue / 9525);
} else {
return 0;
}
}
/**
* Convert EMU to pixels
*
* @param int $pValue Value in EMU
* @return int Value in pixels
*/
public static function EMUToPixels($pValue = 0)
{
if ($pValue != 0) {
return round($pValue / 9525);
} else {
return 0;
}
}
/**
* Convert pixels to column width. Exact algorithm not known.
* By inspection of a real Excel file using Calibri 11, one finds 1000px ~ 142.85546875
* This gives a conversion factor of 7. Also, we assume that pixels and font size are proportional.
*
* @param int $pValue Value in pixels
* @param PHPExcel_Style_Font $pDefaultFont Default font of the workbook
* @return int Value in cell dimension
*/
public static function pixelsToCellDimension($pValue = 0, PHPExcel_Style_Font $pDefaultFont) {
// Font name and size
$name = $pDefaultFont->getName();
$size = $pDefaultFont->getSize();
/**
* Convert pixels to column width. Exact algorithm not known.
* By inspection of a real Excel file using Calibri 11, one finds 1000px ~ 142.85546875
* This gives a conversion factor of 7. Also, we assume that pixels and font size are proportional.
*
* @param int $pValue Value in pixels
* @param PHPExcel_Style_Font $pDefaultFont Default font of the workbook
* @return int Value in cell dimension
*/
public static function pixelsToCellDimension($pValue = 0, PHPExcel_Style_Font $pDefaultFont)
{
// Font name and size
$name = $pDefaultFont->getName();
$size = $pDefaultFont->getSize();
if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {
// Exact width can be determined
$colWidth = $pValue
* PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width']
/ PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px'];
} else {
// We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
$colWidth = $pValue * 11
* PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width']
/ PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px'] / $size;
}
if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {
// Exact width can be determined
$colWidth = $pValue * PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width'] / PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px'];
} else {
// We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
$colWidth = $pValue * 11 * PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width'] / PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px'] / $size;
}
return $colWidth;
}
return $colWidth;
}
/**
* Convert column width from (intrinsic) Excel units to pixels
*
* @param float $pValue Value in cell dimension
* @param PHPExcel_Style_Font $pDefaultFont Default font of the workbook
* @return int Value in pixels
*/
public static function cellDimensionToPixels($pValue = 0, PHPExcel_Style_Font $pDefaultFont) {
// Font name and size
$name = $pDefaultFont->getName();
$size = $pDefaultFont->getSize();
/**
* Convert column width from (intrinsic) Excel units to pixels
*
* @param float $pValue Value in cell dimension
* @param PHPExcel_Style_Font $pDefaultFont Default font of the workbook
* @return int Value in pixels
*/
public static function cellDimensionToPixels($pValue = 0, PHPExcel_Style_Font $pDefaultFont)
{
// Font name and size
$name = $pDefaultFont->getName();
$size = $pDefaultFont->getSize();
if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {
// Exact width can be determined
$colWidth = $pValue
* PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px']
/ PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width'];
if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {
// Exact width can be determined
$colWidth = $pValue * PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px'] / PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width'];
} else {
// We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
$colWidth = $pValue * $size * PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px'] / PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width'] / 11;
}
} else {
// We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
$colWidth = $pValue * $size
* PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px']
/ PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width'] / 11;
}
// Round pixels to closest integer
$colWidth = (int) round($colWidth);
// Round pixels to closest integer
$colWidth = (int) round($colWidth);
return $colWidth;
}
return $colWidth;
}
/**
* Convert pixels to points
*
* @param int $pValue Value in pixels
* @return int Value in points
*/
public static function pixelsToPoints($pValue = 0)
{
return $pValue * 0.67777777;
}
/**
* Convert pixels to points
*
* @param int $pValue Value in pixels
* @return int Value in points
*/
public static function pixelsToPoints($pValue = 0) {
return $pValue * 0.67777777;
}
/**
* Convert points to pixels
*
* @param int $pValue Value in points
* @return int Value in pixels
*/
public static function pointsToPixels($pValue = 0)
{
if ($pValue != 0) {
return (int) ceil($pValue * 1.333333333);
} else {
return 0;
}
}
/**
* Convert points to pixels
*
* @param int $pValue Value in points
* @return int Value in pixels
*/
public static function pointsToPixels($pValue = 0) {
if ($pValue != 0) {
return (int) ceil($pValue * 1.333333333);
} else {
return 0;
}
}
/**
* Convert degrees to angle
*
* @param int $pValue Degrees
* @return int Angle
*/
public static function degreesToAngle($pValue = 0)
{
return (int)round($pValue * 60000);
}
/**
* Convert degrees to angle
*
* @param int $pValue Degrees
* @return int Angle
*/
public static function degreesToAngle($pValue = 0) {
return (int)round($pValue * 60000);
}
/**
* Convert angle to degrees
*
* @param int $pValue Angle
* @return int Degrees
*/
public static function angleToDegrees($pValue = 0)
{
if ($pValue != 0) {
return round($pValue / 60000);
} else {
return 0;
}
}
/**
* Convert angle to degrees
*
* @param int $pValue Angle
* @return int Degrees
*/
public static function angleToDegrees($pValue = 0) {
if ($pValue != 0) {
return round($pValue / 60000);
} else {
return 0;
}
}
/**
* Create a new image from file. By alexander at alexauto dot nl
*
* @link http://www.php.net/manual/en/function.imagecreatefromwbmp.php#86214
* @param string $filename Path to Windows DIB (BMP) image
* @return resource
*/
public static function imagecreatefrombmp($p_sFile)
{
/**
* Create a new image from file. By alexander at alexauto dot nl
*
* @link http://www.php.net/manual/en/function.imagecreatefromwbmp.php#86214
* @param string $filename Path to Windows DIB (BMP) image
* @return resource
*/
public static function imagecreatefrombmp($p_sFile)
{
// Load the image into a string
$file = fopen($p_sFile,"rb");
$read = fread($file,10);
while(!feof($file)&&($read<>""))
$read .= fread($file,1024);
$file = fopen($p_sFile, "rb");
$read = fread($file, 10);
while (!feof($file) && ($read<>"")) {
$read .= fread($file, 1024);
}
$temp = unpack("H*",$read);
$hex = $temp[1];
$header = substr($hex,0,108);
$temp = unpack("H*", $read);
$hex = $temp[1];
$header = substr($hex, 0, 108);
// Process the header
// Structure: http://www.fastgraph.com/help/bmp_header_format.html
if (substr($header,0,4)=="424d")
{
if (substr($header, 0, 4)=="424d") {
// Cut it in parts of 2 bytes
$header_parts = str_split($header,2);
$header_parts = str_split($header, 2);
// Get the width 4 bytes
$width = hexdec($header_parts[19].$header_parts[18]);
$width = hexdec($header_parts[19].$header_parts[18]);
// Get the height 4 bytes
$height = hexdec($header_parts[23].$header_parts[22]);
$height = hexdec($header_parts[23].$header_parts[22]);
// Unset the header params
unset($header_parts);
}
// Define starting X and Y
$x = 0;
$y = 1;
$x = 0;
$y = 1;
// Create newimage
$image = imagecreatetruecolor($width,$height);
$image = imagecreatetruecolor($width, $height);
// Grab the body from the image
$body = substr($hex,108);
$body = substr($hex, 108);
// Calculate if padding at the end-line is needed
// Divided by two to keep overview.
// 1 byte = 2 HEX-chars
$body_size = (strlen($body)/2);
$header_size = ($width*$height);
$body_size = (strlen($body)/2);
$header_size = ($width*$height);
// Use end-line padding? Only when needed
$usePadding = ($body_size>($header_size*3)+4);
$usePadding = ($body_size>($header_size*3)+4);
// Using a for-loop with index-calculation instaid of str_split to avoid large memory consumption
// Calculate the next DWORD-position in the body
for ($i=0;$i<$body_size;$i+=3)
{
for ($i = 0; $i < $body_size; $i += 3) {
// Calculate line-ending and padding
if ($x>=$width)
{
// If padding needed, ignore image-padding
// Shift i to the ending of the current 32-bit-block
if ($usePadding)
$i += $width%4;
if ($x >= $width) {
// If padding needed, ignore image-padding
// Shift i to the ending of the current 32-bit-block
if ($usePadding) {
$i += $width%4;
}
// Reset horizontal position
$x = 0;
$x = 0;
// Raise the height-position (bottom-up)
$y++;
// Reached the image-height? Break the for-loop
if ($y>$height)
if ($y > $height) {
break;
}
}
// Calculation of the RGB-pixel (defined as BGR in image-data)
// Define $i_pos as absolute position in the body
$i_pos = $i*2;
$r = hexdec($body[$i_pos+4].$body[$i_pos+5]);
$g = hexdec($body[$i_pos+2].$body[$i_pos+3]);
$b = hexdec($body[$i_pos].$body[$i_pos+1]);
// Calculation of the RGB-pixel (defined as BGR in image-data)
// Define $i_pos as absolute position in the body
$i_pos = $i * 2;
$r = hexdec($body[$i_pos+4].$body[$i_pos+5]);
$g = hexdec($body[$i_pos+2].$body[$i_pos+3]);
$b = hexdec($body[$i_pos].$body[$i_pos+1]);
// Calculate and draw the pixel
$color = imagecolorallocate($image,$r,$g,$b);
imagesetpixel($image,$x,$height-$y,$color);
// Calculate and draw the pixel
$color = imagecolorallocate($image, $r, $g, $b);
imagesetpixel($image, $x, $height-$y, $color);
// Raise the horizontal position
// Raise the horizontal position
$x++;
}
// Unset the body / free the memory
// Unset the body / free the memory
unset($body);
// Return image-object
return $image;
}
}
}

View File

@@ -1,8 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_Escher
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,72 +21,63 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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_Escher
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher
{
/**
* Drawing Group Container
*
* @var PHPExcel_Shared_Escher_DggContainer
*/
private $_dggContainer;
/**
* Drawing Group Container
*
* @var PHPExcel_Shared_Escher_DggContainer
*/
private $dggContainer;
/**
* Drawing Container
*
* @var PHPExcel_Shared_Escher_DgContainer
*/
private $_dgContainer;
/**
* Drawing Container
*
* @var PHPExcel_Shared_Escher_DgContainer
*/
private $dgContainer;
/**
* Get Drawing Group Container
*
* @return PHPExcel_Shared_Escher_DgContainer
*/
public function getDggContainer()
{
return $this->_dggContainer;
}
/**
* Get Drawing Group Container
*
* @return PHPExcel_Shared_Escher_DgContainer
*/
public function getDggContainer()
{
return $this->dggContainer;
}
/**
* Set Drawing Group Container
*
* @param PHPExcel_Shared_Escher_DggContainer $dggContainer
*/
public function setDggContainer($dggContainer)
{
return $this->_dggContainer = $dggContainer;
}
/**
* Set Drawing Group Container
*
* @param PHPExcel_Shared_Escher_DggContainer $dggContainer
*/
public function setDggContainer($dggContainer)
{
return $this->dggContainer = $dggContainer;
}
/**
* Get Drawing Container
*
* @return PHPExcel_Shared_Escher_DgContainer
*/
public function getDgContainer()
{
return $this->_dgContainer;
}
/**
* Set Drawing Container
*
* @param PHPExcel_Shared_Escher_DgContainer $dgContainer
*/
public function setDgContainer($dgContainer)
{
return $this->_dgContainer = $dgContainer;
}
/**
* Get Drawing Container
*
* @return PHPExcel_Shared_Escher_DgContainer
*/
public function getDgContainer()
{
return $this->dgContainer;
}
/**
* Set Drawing Container
*
* @param PHPExcel_Shared_Escher_DgContainer $dgContainer
*/
public function setDgContainer($dgContainer)
{
return $this->dgContainer = $dgContainer;
}
}

View File

@@ -1,8 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_Escher_DgContainer
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,64 +21,55 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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_Escher_DgContainer
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DgContainer
{
/**
* Drawing index, 1-based.
*
* @var int
*/
private $_dgId;
/**
* Drawing index, 1-based.
*
* @var int
*/
private $dgId;
/**
* Last shape index in this drawing
*
* @var int
*/
private $_lastSpId;
/**
* Last shape index in this drawing
*
* @var int
*/
private $lastSpId;
private $_spgrContainer = null;
private $spgrContainer = null;
public function getDgId()
{
return $this->_dgId;
}
public function getDgId()
{
return $this->dgId;
}
public function setDgId($value)
{
$this->_dgId = $value;
}
public function setDgId($value)
{
$this->dgId = $value;
}
public function getLastSpId()
{
return $this->_lastSpId;
}
public function getLastSpId()
{
return $this->lastSpId;
}
public function setLastSpId($value)
{
$this->_lastSpId = $value;
}
public function setLastSpId($value)
{
$this->lastSpId = $value;
}
public function getSpgrContainer()
{
return $this->_spgrContainer;
}
public function setSpgrContainer($spgrContainer)
{
return $this->_spgrContainer = $spgrContainer;
}
public function getSpgrContainer()
{
return $this->spgrContainer;
}
public function setSpgrContainer($spgrContainer)
{
return $this->spgrContainer = $spgrContainer;
}
}

View File

@@ -1,8 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_Escher_DgContainer_SpgrContainer
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,90 +21,82 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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_Escher_DgContainer_SpgrContainer
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DgContainer_SpgrContainer
{
/**
* Parent Shape Group Container
*
* @var PHPExcel_Shared_Escher_DgContainer_SpgrContainer
*/
private $_parent;
/**
* Parent Shape Group Container
*
* @var PHPExcel_Shared_Escher_DgContainer_SpgrContainer
*/
private $parent;
/**
* Shape Container collection
*
* @var array
*/
private $_children = array();
/**
* Shape Container collection
*
* @var array
*/
private $children = array();
/**
* Set parent Shape Group Container
*
* @param PHPExcel_Shared_Escher_DgContainer_SpgrContainer $parent
*/
public function setParent($parent)
{
$this->_parent = $parent;
}
/**
* Set parent Shape Group Container
*
* @param PHPExcel_Shared_Escher_DgContainer_SpgrContainer $parent
*/
public function setParent($parent)
{
$this->parent = $parent;
}
/**
* Get the parent Shape Group Container if any
*
* @return PHPExcel_Shared_Escher_DgContainer_SpgrContainer|null
*/
public function getParent()
{
return $this->_parent;
}
/**
* Get the parent Shape Group Container if any
*
* @return PHPExcel_Shared_Escher_DgContainer_SpgrContainer|null
*/
public function getParent()
{
return $this->parent;
}
/**
* Add a child. This will be either spgrContainer or spContainer
*
* @param mixed $child
*/
public function addChild($child)
{
$this->_children[] = $child;
$child->setParent($this);
}
/**
* Add a child. This will be either spgrContainer or spContainer
*
* @param mixed $child
*/
public function addChild($child)
{
$this->children[] = $child;
$child->setParent($this);
}
/**
* Get collection of Shape Containers
*/
public function getChildren()
{
return $this->_children;
}
/**
* Get collection of Shape Containers
*/
public function getChildren()
{
return $this->children;
}
/**
* Recursively get all spContainers within this spgrContainer
*
* @return PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer[]
*/
public function getAllSpContainers()
{
$allSpContainers = array();
/**
* Recursively get all spContainers within this spgrContainer
*
* @return PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer[]
*/
public function getAllSpContainers()
{
$allSpContainers = array();
foreach ($this->_children as $child) {
if ($child instanceof PHPExcel_Shared_Escher_DgContainer_SpgrContainer) {
$allSpContainers = array_merge($allSpContainers, $child->getAllSpContainers());
} else {
$allSpContainers[] = $child;
}
}
foreach ($this->children as $child) {
if ($child instanceof PHPExcel_Shared_Escher_DgContainer_SpgrContainer) {
$allSpContainers = array_merge($allSpContainers, $child->getAllSpContainers());
} else {
$allSpContainers[] = $child;
}
}
return $allSpContainers;
}
return $allSpContainers;
}
}

View File

@@ -1,8 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,376 +21,368 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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_Escher_DgContainer_SpgrContainer_SpContainer
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer
{
/**
* Parent Shape Group Container
*
* @var PHPExcel_Shared_Escher_DgContainer_SpgrContainer
*/
private $_parent;
/**
* Parent Shape Group Container
*
* @var PHPExcel_Shared_Escher_DgContainer_SpgrContainer
*/
private $parent;
/**
* Is this a group shape?
*
* @var boolean
*/
private $_spgr = false;
/**
* Is this a group shape?
*
* @var boolean
*/
private $spgr = false;
/**
* Shape type
*
* @var int
*/
private $_spType;
/**
* Shape type
*
* @var int
*/
private $spType;
/**
* Shape flag
*
* @var int
*/
private $_spFlag;
/**
* Shape flag
*
* @var int
*/
private $spFlag;
/**
* Shape index (usually group shape has index 0, and the rest: 1,2,3...)
*
* @var boolean
*/
private $_spId;
/**
* Shape index (usually group shape has index 0, and the rest: 1,2,3...)
*
* @var boolean
*/
private $spId;
/**
* Array of options
*
* @var array
*/
private $_OPT;
/**
* Array of options
*
* @var array
*/
private $OPT;
/**
* Cell coordinates of upper-left corner of shape, e.g. 'A1'
*
* @var string
*/
private $_startCoordinates;
/**
* Cell coordinates of upper-left corner of shape, e.g. 'A1'
*
* @var string
*/
private $startCoordinates;
/**
* Horizontal offset of upper-left corner of shape measured in 1/1024 of column width
*
* @var int
*/
private $_startOffsetX;
/**
* Horizontal offset of upper-left corner of shape measured in 1/1024 of column width
*
* @var int
*/
private $startOffsetX;
/**
* Vertical offset of upper-left corner of shape measured in 1/256 of row height
*
* @var int
*/
private $_startOffsetY;
/**
* Vertical offset of upper-left corner of shape measured in 1/256 of row height
*
* @var int
*/
private $startOffsetY;
/**
* Cell coordinates of bottom-right corner of shape, e.g. 'B2'
*
* @var string
*/
private $_endCoordinates;
/**
* Cell coordinates of bottom-right corner of shape, e.g. 'B2'
*
* @var string
*/
private $endCoordinates;
/**
* Horizontal offset of bottom-right corner of shape measured in 1/1024 of column width
*
* @var int
*/
private $_endOffsetX;
/**
* Horizontal offset of bottom-right corner of shape measured in 1/1024 of column width
*
* @var int
*/
private $endOffsetX;
/**
* Vertical offset of bottom-right corner of shape measured in 1/256 of row height
*
* @var int
*/
private $_endOffsetY;
/**
* Vertical offset of bottom-right corner of shape measured in 1/256 of row height
*
* @var int
*/
private $endOffsetY;
/**
* Set parent Shape Group Container
*
* @param PHPExcel_Shared_Escher_DgContainer_SpgrContainer $parent
*/
public function setParent($parent)
{
$this->_parent = $parent;
}
/**
* Set parent Shape Group Container
*
* @param PHPExcel_Shared_Escher_DgContainer_SpgrContainer $parent
*/
public function setParent($parent)
{
$this->parent = $parent;
}
/**
* Get the parent Shape Group Container
*
* @return PHPExcel_Shared_Escher_DgContainer_SpgrContainer
*/
public function getParent()
{
return $this->_parent;
}
/**
* Get the parent Shape Group Container
*
* @return PHPExcel_Shared_Escher_DgContainer_SpgrContainer
*/
public function getParent()
{
return $this->parent;
}
/**
* Set whether this is a group shape
*
* @param boolean $value
*/
public function setSpgr($value = false)
{
$this->_spgr = $value;
}
/**
* Set whether this is a group shape
*
* @param boolean $value
*/
public function setSpgr($value = false)
{
$this->spgr = $value;
}
/**
* Get whether this is a group shape
*
* @return boolean
*/
public function getSpgr()
{
return $this->_spgr;
}
/**
* Get whether this is a group shape
*
* @return boolean
*/
public function getSpgr()
{
return $this->spgr;
}
/**
* Set the shape type
*
* @param int $value
*/
public function setSpType($value)
{
$this->_spType = $value;
}
/**
* Set the shape type
*
* @param int $value
*/
public function setSpType($value)
{
$this->spType = $value;
}
/**
* Get the shape type
*
* @return int
*/
public function getSpType()
{
return $this->_spType;
}
/**
* Get the shape type
*
* @return int
*/
public function getSpType()
{
return $this->spType;
}
/**
* Set the shape flag
*
* @param int $value
*/
public function setSpFlag($value)
{
$this->_spFlag = $value;
}
/**
* Set the shape flag
*
* @param int $value
*/
public function setSpFlag($value)
{
$this->spFlag = $value;
}
/**
* Get the shape flag
*
* @return int
*/
public function getSpFlag()
{
return $this->_spFlag;
}
/**
* Get the shape flag
*
* @return int
*/
public function getSpFlag()
{
return $this->spFlag;
}
/**
* Set the shape index
*
* @param int $value
*/
public function setSpId($value)
{
$this->_spId = $value;
}
/**
* Set the shape index
*
* @param int $value
*/
public function setSpId($value)
{
$this->spId = $value;
}
/**
* Get the shape index
*
* @return int
*/
public function getSpId()
{
return $this->_spId;
}
/**
* Get the shape index
*
* @return int
*/
public function getSpId()
{
return $this->spId;
}
/**
* Set an option for the Shape Group Container
*
* @param int $property The number specifies the option
* @param mixed $value
*/
public function setOPT($property, $value)
{
$this->_OPT[$property] = $value;
}
/**
* Set an option for the Shape Group Container
*
* @param int $property The number specifies the option
* @param mixed $value
*/
public function setOPT($property, $value)
{
$this->OPT[$property] = $value;
}
/**
* Get an option for the Shape Group Container
*
* @param int $property The number specifies the option
* @return mixed
*/
public function getOPT($property)
{
if (isset($this->_OPT[$property])) {
return $this->_OPT[$property];
}
return null;
}
/**
* Get an option for the Shape Group Container
*
* @param int $property The number specifies the option
* @return mixed
*/
public function getOPT($property)
{
if (isset($this->OPT[$property])) {
return $this->OPT[$property];
}
return null;
}
/**
* Get the collection of options
*
* @return array
*/
public function getOPTCollection()
{
return $this->_OPT;
}
/**
* Get the collection of options
*
* @return array
*/
public function getOPTCollection()
{
return $this->OPT;
}
/**
* Set cell coordinates of upper-left corner of shape
*
* @param string $value
*/
public function setStartCoordinates($value = 'A1')
{
$this->_startCoordinates = $value;
}
/**
* Set cell coordinates of upper-left corner of shape
*
* @param string $value
*/
public function setStartCoordinates($value = 'A1')
{
$this->startCoordinates = $value;
}
/**
* Get cell coordinates of upper-left corner of shape
*
* @return string
*/
public function getStartCoordinates()
{
return $this->_startCoordinates;
}
/**
* Get cell coordinates of upper-left corner of shape
*
* @return string
*/
public function getStartCoordinates()
{
return $this->startCoordinates;
}
/**
* Set offset in x-direction of upper-left corner of shape measured in 1/1024 of column width
*
* @param int $startOffsetX
*/
public function setStartOffsetX($startOffsetX = 0)
{
$this->_startOffsetX = $startOffsetX;
}
/**
* Set offset in x-direction of upper-left corner of shape measured in 1/1024 of column width
*
* @param int $startOffsetX
*/
public function setStartOffsetX($startOffsetX = 0)
{
$this->startOffsetX = $startOffsetX;
}
/**
* Get offset in x-direction of upper-left corner of shape measured in 1/1024 of column width
*
* @return int
*/
public function getStartOffsetX()
{
return $this->_startOffsetX;
}
/**
* Get offset in x-direction of upper-left corner of shape measured in 1/1024 of column width
*
* @return int
*/
public function getStartOffsetX()
{
return $this->startOffsetX;
}
/**
* Set offset in y-direction of upper-left corner of shape measured in 1/256 of row height
*
* @param int $startOffsetY
*/
public function setStartOffsetY($startOffsetY = 0)
{
$this->_startOffsetY = $startOffsetY;
}
/**
* Set offset in y-direction of upper-left corner of shape measured in 1/256 of row height
*
* @param int $startOffsetY
*/
public function setStartOffsetY($startOffsetY = 0)
{
$this->startOffsetY = $startOffsetY;
}
/**
* Get offset in y-direction of upper-left corner of shape measured in 1/256 of row height
*
* @return int
*/
public function getStartOffsetY()
{
return $this->_startOffsetY;
}
/**
* Get offset in y-direction of upper-left corner of shape measured in 1/256 of row height
*
* @return int
*/
public function getStartOffsetY()
{
return $this->startOffsetY;
}
/**
* Set cell coordinates of bottom-right corner of shape
*
* @param string $value
*/
public function setEndCoordinates($value = 'A1')
{
$this->_endCoordinates = $value;
}
/**
* Set cell coordinates of bottom-right corner of shape
*
* @param string $value
*/
public function setEndCoordinates($value = 'A1')
{
$this->endCoordinates = $value;
}
/**
* Get cell coordinates of bottom-right corner of shape
*
* @return string
*/
public function getEndCoordinates()
{
return $this->_endCoordinates;
}
/**
* Get cell coordinates of bottom-right corner of shape
*
* @return string
*/
public function getEndCoordinates()
{
return $this->endCoordinates;
}
/**
* Set offset in x-direction of bottom-right corner of shape measured in 1/1024 of column width
*
* @param int $startOffsetX
*/
public function setEndOffsetX($endOffsetX = 0)
{
$this->_endOffsetX = $endOffsetX;
}
/**
* Set offset in x-direction of bottom-right corner of shape measured in 1/1024 of column width
*
* @param int $startOffsetX
*/
public function setEndOffsetX($endOffsetX = 0)
{
$this->endOffsetX = $endOffsetX;
}
/**
* Get offset in x-direction of bottom-right corner of shape measured in 1/1024 of column width
*
* @return int
*/
public function getEndOffsetX()
{
return $this->_endOffsetX;
}
/**
* Get offset in x-direction of bottom-right corner of shape measured in 1/1024 of column width
*
* @return int
*/
public function getEndOffsetX()
{
return $this->endOffsetX;
}
/**
* Set offset in y-direction of bottom-right corner of shape measured in 1/256 of row height
*
* @param int $endOffsetY
*/
public function setEndOffsetY($endOffsetY = 0)
{
$this->_endOffsetY = $endOffsetY;
}
/**
* Set offset in y-direction of bottom-right corner of shape measured in 1/256 of row height
*
* @param int $endOffsetY
*/
public function setEndOffsetY($endOffsetY = 0)
{
$this->endOffsetY = $endOffsetY;
}
/**
* Get offset in y-direction of bottom-right corner of shape measured in 1/256 of row height
*
* @return int
*/
public function getEndOffsetY()
{
return $this->_endOffsetY;
}
/**
* Get offset in y-direction of bottom-right corner of shape measured in 1/256 of row height
*
* @return int
*/
public function getEndOffsetY()
{
return $this->endOffsetY;
}
/**
* Get the nesting level of this spContainer. This is the number of spgrContainers between this spContainer and
* the dgContainer. A value of 1 = immediately within first spgrContainer
* Higher nesting level occurs if and only if spContainer is part of a shape group
*
* @return int Nesting level
*/
public function getNestingLevel()
{
$nestingLevel = 0;
/**
* Get the nesting level of this spContainer. This is the number of spgrContainers between this spContainer and
* the dgContainer. A value of 1 = immediately within first spgrContainer
* Higher nesting level occurs if and only if spContainer is part of a shape group
*
* @return int Nesting level
*/
public function getNestingLevel()
{
$nestingLevel = 0;
$parent = $this->getParent();
while ($parent instanceof PHPExcel_Shared_Escher_DgContainer_SpgrContainer) {
++$nestingLevel;
$parent = $parent->getParent();
}
$parent = $this->getParent();
while ($parent instanceof PHPExcel_Shared_Escher_DgContainer_SpgrContainer) {
++$nestingLevel;
$parent = $parent->getParent();
}
return $nestingLevel;
}
return $nestingLevel;
}
}

View File

@@ -1,8 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_Escher_DggContainer
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,184 +21,176 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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_Escher_DggContainer
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DggContainer
{
/**
* Maximum shape index of all shapes in all drawings increased by one
*
* @var int
*/
private $_spIdMax;
/**
* Maximum shape index of all shapes in all drawings increased by one
*
* @var int
*/
private $spIdMax;
/**
* Total number of drawings saved
*
* @var int
*/
private $_cDgSaved;
/**
* Total number of drawings saved
*
* @var int
*/
private $cDgSaved;
/**
* Total number of shapes saved (including group shapes)
*
* @var int
*/
private $_cSpSaved;
/**
* Total number of shapes saved (including group shapes)
*
* @var int
*/
private $cSpSaved;
/**
* BLIP Store Container
*
* @var PHPExcel_Shared_Escher_DggContainer_BstoreContainer
*/
private $_bstoreContainer;
/**
* BLIP Store Container
*
* @var PHPExcel_Shared_Escher_DggContainer_BstoreContainer
*/
private $bstoreContainer;
/**
* Array of options for the drawing group
*
* @var array
*/
private $_OPT = array();
/**
* Array of options for the drawing group
*
* @var array
*/
private $OPT = array();
/**
* Array of identifier clusters containg information about the maximum shape identifiers
*
* @var array
*/
private $_IDCLs = array();
/**
* Array of identifier clusters containg information about the maximum shape identifiers
*
* @var array
*/
private $IDCLs = array();
/**
* Get maximum shape index of all shapes in all drawings (plus one)
*
* @return int
*/
public function getSpIdMax()
{
return $this->_spIdMax;
}
/**
* Get maximum shape index of all shapes in all drawings (plus one)
*
* @return int
*/
public function getSpIdMax()
{
return $this->spIdMax;
}
/**
* Set maximum shape index of all shapes in all drawings (plus one)
*
* @param int
*/
public function setSpIdMax($value)
{
$this->_spIdMax = $value;
}
/**
* Set maximum shape index of all shapes in all drawings (plus one)
*
* @param int
*/
public function setSpIdMax($value)
{
$this->spIdMax = $value;
}
/**
* Get total number of drawings saved
*
* @return int
*/
public function getCDgSaved()
{
return $this->_cDgSaved;
}
/**
* Get total number of drawings saved
*
* @return int
*/
public function getCDgSaved()
{
return $this->cDgSaved;
}
/**
* Set total number of drawings saved
*
* @param int
*/
public function setCDgSaved($value)
{
$this->_cDgSaved = $value;
}
/**
* Set total number of drawings saved
*
* @param int
*/
public function setCDgSaved($value)
{
$this->cDgSaved = $value;
}
/**
* Get total number of shapes saved (including group shapes)
*
* @return int
*/
public function getCSpSaved()
{
return $this->_cSpSaved;
}
/**
* Get total number of shapes saved (including group shapes)
*
* @return int
*/
public function getCSpSaved()
{
return $this->cSpSaved;
}
/**
* Set total number of shapes saved (including group shapes)
*
* @param int
*/
public function setCSpSaved($value)
{
$this->_cSpSaved = $value;
}
/**
* Set total number of shapes saved (including group shapes)
*
* @param int
*/
public function setCSpSaved($value)
{
$this->cSpSaved = $value;
}
/**
* Get BLIP Store Container
*
* @return PHPExcel_Shared_Escher_DggContainer_BstoreContainer
*/
public function getBstoreContainer()
{
return $this->_bstoreContainer;
}
/**
* Get BLIP Store Container
*
* @return PHPExcel_Shared_Escher_DggContainer_BstoreContainer
*/
public function getBstoreContainer()
{
return $this->bstoreContainer;
}
/**
* Set BLIP Store Container
*
* @param PHPExcel_Shared_Escher_DggContainer_BstoreContainer $bstoreContainer
*/
public function setBstoreContainer($bstoreContainer)
{
$this->_bstoreContainer = $bstoreContainer;
}
/**
* Set BLIP Store Container
*
* @param PHPExcel_Shared_Escher_DggContainer_BstoreContainer $bstoreContainer
*/
public function setBstoreContainer($bstoreContainer)
{
$this->bstoreContainer = $bstoreContainer;
}
/**
* Set an option for the drawing group
*
* @param int $property The number specifies the option
* @param mixed $value
*/
public function setOPT($property, $value)
{
$this->_OPT[$property] = $value;
}
/**
* Set an option for the drawing group
*
* @param int $property The number specifies the option
* @param mixed $value
*/
public function setOPT($property, $value)
{
$this->OPT[$property] = $value;
}
/**
* Get an option for the drawing group
*
* @param int $property The number specifies the option
* @return mixed
*/
public function getOPT($property)
{
if (isset($this->_OPT[$property])) {
return $this->_OPT[$property];
}
return null;
}
/**
* Get an option for the drawing group
*
* @param int $property The number specifies the option
* @return mixed
*/
public function getOPT($property)
{
if (isset($this->OPT[$property])) {
return $this->OPT[$property];
}
return null;
}
/**
* Get identifier clusters
*
* @return array
*/
public function getIDCLs()
{
return $this->_IDCLs;
}
/**
* Get identifier clusters
*
* @return array
*/
public function getIDCLs()
{
return $this->IDCLs;
}
/**
* Set identifier clusters. array(<drawingId> => <max shape id>, ...)
*
* @param array $pValue
*/
public function setIDCLs($pValue)
{
$this->_IDCLs = $pValue;
}
/**
* Set identifier clusters. array(<drawingId> => <max shape id>, ...)
*
* @param array $pValue
*/
public function setIDCLs($pValue)
{
$this->IDCLs = $pValue;
}
}

View File

@@ -1,8 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_Escher_DggContainer_BstoreContainer
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,46 +21,37 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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_Escher_DggContainer_BstoreContainer
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DggContainer_BstoreContainer
{
/**
* BLIP Store Entries. Each of them holds one BLIP (Big Large Image or Picture)
*
* @var array
*/
private $_BSECollection = array();
/**
* BLIP Store Entries. Each of them holds one BLIP (Big Large Image or Picture)
*
* @var array
*/
private $BSECollection = array();
/**
* Add a BLIP Store Entry
*
* @param PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE $BSE
*/
public function addBSE($BSE)
{
$this->_BSECollection[] = $BSE;
$BSE->setParent($this);
}
/**
* Get the collection of BLIP Store Entries
*
* @return PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE[]
*/
public function getBSECollection()
{
return $this->_BSECollection;
}
/**
* Add a BLIP Store Entry
*
* @param PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE $BSE
*/
public function addBSE($BSE)
{
$this->BSECollection[] = $BSE;
$BSE->setParent($this);
}
/**
* Get the collection of BLIP Store Entries
*
* @return PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE[]
*/
public function getBSECollection()
{
return $this->BSECollection;
}
}

View File

@@ -1,8 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,101 +21,92 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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_Escher_DggContainer_BstoreContainer_BSE
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE
{
const BLIPTYPE_ERROR = 0x00;
const BLIPTYPE_UNKNOWN = 0x01;
const BLIPTYPE_EMF = 0x02;
const BLIPTYPE_WMF = 0x03;
const BLIPTYPE_PICT = 0x04;
const BLIPTYPE_JPEG = 0x05;
const BLIPTYPE_PNG = 0x06;
const BLIPTYPE_DIB = 0x07;
const BLIPTYPE_TIFF = 0x11;
const BLIPTYPE_CMYKJPEG = 0x12;
const BLIPTYPE_ERROR = 0x00;
const BLIPTYPE_UNKNOWN = 0x01;
const BLIPTYPE_EMF = 0x02;
const BLIPTYPE_WMF = 0x03;
const BLIPTYPE_PICT = 0x04;
const BLIPTYPE_JPEG = 0x05;
const BLIPTYPE_PNG = 0x06;
const BLIPTYPE_DIB = 0x07;
const BLIPTYPE_TIFF = 0x11;
const BLIPTYPE_CMYKJPEG = 0x12;
/**
* The parent BLIP Store Entry Container
*
* @var PHPExcel_Shared_Escher_DggContainer_BstoreContainer
*/
private $_parent;
/**
* The parent BLIP Store Entry Container
*
* @var PHPExcel_Shared_Escher_DggContainer_BstoreContainer
*/
private $parent;
/**
* The BLIP (Big Large Image or Picture)
*
* @var PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip
*/
private $_blip;
/**
* The BLIP (Big Large Image or Picture)
*
* @var PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip
*/
private $blip;
/**
* The BLIP type
*
* @var int
*/
private $_blipType;
/**
* The BLIP type
*
* @var int
*/
private $blipType;
/**
* Set parent BLIP Store Entry Container
*
* @param PHPExcel_Shared_Escher_DggContainer_BstoreContainer $parent
*/
public function setParent($parent)
{
$this->_parent = $parent;
}
/**
* Set parent BLIP Store Entry Container
*
* @param PHPExcel_Shared_Escher_DggContainer_BstoreContainer $parent
*/
public function setParent($parent)
{
$this->parent = $parent;
}
/**
* Get the BLIP
*
* @return PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip
*/
public function getBlip()
{
return $this->_blip;
}
/**
* Get the BLIP
*
* @return PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip
*/
public function getBlip()
{
return $this->blip;
}
/**
* Set the BLIP
*
* @param PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip $blip
*/
public function setBlip($blip)
{
$this->_blip = $blip;
$blip->setParent($this);
}
/**
* Set the BLIP
*
* @param PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip $blip
*/
public function setBlip($blip)
{
$this->blip = $blip;
$blip->setParent($this);
}
/**
* Get the BLIP type
*
* @return int
*/
public function getBlipType()
{
return $this->_blipType;
}
/**
* Set the BLIP type
*
* @param int
*/
public function setBlipType($blipType)
{
$this->_blipType = $blipType;
}
/**
* Get the BLIP type
*
* @return int
*/
public function getBlipType()
{
return $this->blipType;
}
/**
* Set the BLIP type
*
* @param int
*/
public function setBlipType($blipType)
{
$this->blipType = $blipType;
}
}

View File

@@ -1,8 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,72 +21,63 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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_Escher_DggContainer_BstoreContainer_BSE_Blip
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip
{
/**
* The parent BSE
*
* @var PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE
*/
private $_parent;
/**
* The parent BSE
*
* @var PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE
*/
private $parent;
/**
* Raw image data
*
* @var string
*/
private $_data;
/**
* Raw image data
*
* @var string
*/
private $data;
/**
* Get the raw image data
*
* @return string
*/
public function getData()
{
return $this->_data;
}
/**
* Get the raw image data
*
* @return string
*/
public function getData()
{
return $this->data;
}
/**
* Set the raw image data
*
* @param string
*/
public function setData($data)
{
$this->_data = $data;
}
/**
* Set the raw image data
*
* @param string
*/
public function setData($data)
{
$this->data = $data;
}
/**
* Set parent BSE
*
* @param PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE $parent
*/
public function setParent($parent)
{
$this->_parent = $parent;
}
/**
* Get parent BSE
*
* @return PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE $parent
*/
public function getParent()
{
return $this->_parent;
}
/**
* Set parent BSE
*
* @param PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE $parent
*/
public function setParent($parent)
{
$this->parent = $parent;
}
/**
* Get parent BSE
*
* @return PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE $parent
*/
public function getParent()
{
return $this->parent;
}
}

View File

@@ -1,8 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_Excel5
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,298 +21,278 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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_Excel5
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Excel5
{
/**
* Get the width of a column in pixels. We use the relationship y = ceil(7x) where
* x is the width in intrinsic Excel units (measuring width in number of normal characters)
* This holds for Arial 10
*
* @param PHPExcel_Worksheet $sheet The sheet
* @param string $col The column
* @return integer The width in pixels
*/
public static function sizeCol($sheet, $col = 'A')
{
// default font of the workbook
$font = $sheet->getParent()->getDefaultStyle()->getFont();
/**
* Get the width of a column in pixels. We use the relationship y = ceil(7x) where
* x is the width in intrinsic Excel units (measuring width in number of normal characters)
* This holds for Arial 10
*
* @param PHPExcel_Worksheet $sheet The sheet
* @param string $col The column
* @return integer The width in pixels
*/
public static function sizeCol($sheet, $col = 'A')
{
// default font of the workbook
$font = $sheet->getParent()->getDefaultStyle()->getFont();
$columnDimensions = $sheet->getColumnDimensions();
$columnDimensions = $sheet->getColumnDimensions();
// first find the true column width in pixels (uncollapsed and unhidden)
if ( isset($columnDimensions[$col]) and $columnDimensions[$col]->getWidth() != -1 ) {
// first find the true column width in pixels (uncollapsed and unhidden)
if (isset($columnDimensions[$col]) and $columnDimensions[$col]->getWidth() != -1) {
// then we have column dimension with explicit width
$columnDimension = $columnDimensions[$col];
$width = $columnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
} elseif ($sheet->getDefaultColumnDimension()->getWidth() != -1) {
// then we have default column dimension with explicit width
$defaultColumnDimension = $sheet->getDefaultColumnDimension();
$width = $defaultColumnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
} else {
// we don't even have any default column dimension. Width depends on default font
$pixelWidth = PHPExcel_Shared_Font::getDefaultColumnWidthByFont($font, true);
}
// then we have column dimension with explicit width
$columnDimension = $columnDimensions[$col];
$width = $columnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
// now find the effective column width in pixels
if (isset($columnDimensions[$col]) and !$columnDimensions[$col]->getVisible()) {
$effectivePixelWidth = 0;
} else {
$effectivePixelWidth = $pixelWidth;
}
} else if ($sheet->getDefaultColumnDimension()->getWidth() != -1) {
return $effectivePixelWidth;
}
// then we have default column dimension with explicit width
$defaultColumnDimension = $sheet->getDefaultColumnDimension();
$width = $defaultColumnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
/**
* Convert the height of a cell from user's units to pixels. By interpolation
* the relationship is: y = 4/3x. If the height hasn't been set by the user we
* use the default value. If the row is hidden we use a value of zero.
*
* @param PHPExcel_Worksheet $sheet The sheet
* @param integer $row The row index (1-based)
* @return integer The width in pixels
*/
public static function sizeRow($sheet, $row = 1)
{
// default font of the workbook
$font = $sheet->getParent()->getDefaultStyle()->getFont();
} else {
$rowDimensions = $sheet->getRowDimensions();
// we don't even have any default column dimension. Width depends on default font
$pixelWidth = PHPExcel_Shared_Font::getDefaultColumnWidthByFont($font, true);
}
// first find the true row height in pixels (uncollapsed and unhidden)
if (isset($rowDimensions[$row]) and $rowDimensions[$row]->getRowHeight() != -1) {
// then we have a row dimension
$rowDimension = $rowDimensions[$row];
$rowHeight = $rowDimension->getRowHeight();
$pixelRowHeight = (int) ceil(4 * $rowHeight / 3); // here we assume Arial 10
} elseif ($sheet->getDefaultRowDimension()->getRowHeight() != -1) {
// then we have a default row dimension with explicit height
$defaultRowDimension = $sheet->getDefaultRowDimension();
$rowHeight = $defaultRowDimension->getRowHeight();
$pixelRowHeight = PHPExcel_Shared_Drawing::pointsToPixels($rowHeight);
} else {
// we don't even have any default row dimension. Height depends on default font
$pointRowHeight = PHPExcel_Shared_Font::getDefaultRowHeightByFont($font);
$pixelRowHeight = PHPExcel_Shared_Font::fontSizeToPixels($pointRowHeight);
}
// now find the effective column width in pixels
if (isset($columnDimensions[$col]) and !$columnDimensions[$col]->getVisible()) {
$effectivePixelWidth = 0;
} else {
$effectivePixelWidth = $pixelWidth;
}
// now find the effective row height in pixels
if (isset($rowDimensions[$row]) and !$rowDimensions[$row]->getVisible()) {
$effectivePixelRowHeight = 0;
} else {
$effectivePixelRowHeight = $pixelRowHeight;
}
return $effectivePixelWidth;
}
return $effectivePixelRowHeight;
}
/**
* Convert the height of a cell from user's units to pixels. By interpolation
* the relationship is: y = 4/3x. If the height hasn't been set by the user we
* use the default value. If the row is hidden we use a value of zero.
*
* @param PHPExcel_Worksheet $sheet The sheet
* @param integer $row The row index (1-based)
* @return integer The width in pixels
*/
public static function sizeRow($sheet, $row = 1)
{
// default font of the workbook
$font = $sheet->getParent()->getDefaultStyle()->getFont();
/**
* Get the horizontal distance in pixels between two anchors
* The distanceX is found as sum of all the spanning columns widths minus correction for the two offsets
*
* @param PHPExcel_Worksheet $sheet
* @param string $startColumn
* @param integer $startOffsetX Offset within start cell measured in 1/1024 of the cell width
* @param string $endColumn
* @param integer $endOffsetX Offset within end cell measured in 1/1024 of the cell width
* @return integer Horizontal measured in pixels
*/
public static function getDistanceX(PHPExcel_Worksheet $sheet, $startColumn = 'A', $startOffsetX = 0, $endColumn = 'A', $endOffsetX = 0)
{
$distanceX = 0;
$rowDimensions = $sheet->getRowDimensions();
// add the widths of the spanning columns
$startColumnIndex = PHPExcel_Cell::columnIndexFromString($startColumn) - 1; // 1-based
$endColumnIndex = PHPExcel_Cell::columnIndexFromString($endColumn) - 1; // 1-based
for ($i = $startColumnIndex; $i <= $endColumnIndex; ++$i) {
$distanceX += self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($i));
}
// first find the true row height in pixels (uncollapsed and unhidden)
if ( isset($rowDimensions[$row]) and $rowDimensions[$row]->getRowHeight() != -1) {
// correct for offsetX in startcell
$distanceX -= (int) floor(self::sizeCol($sheet, $startColumn) * $startOffsetX / 1024);
// then we have a row dimension
$rowDimension = $rowDimensions[$row];
$rowHeight = $rowDimension->getRowHeight();
$pixelRowHeight = (int) ceil(4 * $rowHeight / 3); // here we assume Arial 10
// correct for offsetX in endcell
$distanceX -= (int) floor(self::sizeCol($sheet, $endColumn) * (1 - $endOffsetX / 1024));
} else if ($sheet->getDefaultRowDimension()->getRowHeight() != -1) {
return $distanceX;
}
// then we have a default row dimension with explicit height
$defaultRowDimension = $sheet->getDefaultRowDimension();
$rowHeight = $defaultRowDimension->getRowHeight();
$pixelRowHeight = PHPExcel_Shared_Drawing::pointsToPixels($rowHeight);
/**
* Get the vertical distance in pixels between two anchors
* The distanceY is found as sum of all the spanning rows minus two offsets
*
* @param PHPExcel_Worksheet $sheet
* @param integer $startRow (1-based)
* @param integer $startOffsetY Offset within start cell measured in 1/256 of the cell height
* @param integer $endRow (1-based)
* @param integer $endOffsetY Offset within end cell measured in 1/256 of the cell height
* @return integer Vertical distance measured in pixels
*/
public static function getDistanceY(PHPExcel_Worksheet $sheet, $startRow = 1, $startOffsetY = 0, $endRow = 1, $endOffsetY = 0)
{
$distanceY = 0;
} else {
// add the widths of the spanning rows
for ($row = $startRow; $row <= $endRow; ++$row) {
$distanceY += self::sizeRow($sheet, $row);
}
// we don't even have any default row dimension. Height depends on default font
$pointRowHeight = PHPExcel_Shared_Font::getDefaultRowHeightByFont($font);
$pixelRowHeight = PHPExcel_Shared_Font::fontSizeToPixels($pointRowHeight);
// correct for offsetX in startcell
$distanceY -= (int) floor(self::sizeRow($sheet, $startRow) * $startOffsetY / 256);
}
// correct for offsetX in endcell
$distanceY -= (int) floor(self::sizeRow($sheet, $endRow) * (1 - $endOffsetY / 256));
// now find the effective row height in pixels
if ( isset($rowDimensions[$row]) and !$rowDimensions[$row]->getVisible() ) {
$effectivePixelRowHeight = 0;
} else {
$effectivePixelRowHeight = $pixelRowHeight;
}
return $distanceY;
}
return $effectivePixelRowHeight;
}
/**
* Convert 1-cell anchor coordinates to 2-cell anchor coordinates
* This function is ported from PEAR Spreadsheet_Writer_Excel with small modifications
*
* Calculate the vertices that define the position of the image as required by
* the OBJ record.
*
* +------------+------------+
* | A | B |
* +-----+------------+------------+
* | |(x1,y1) | |
* | 1 |(A1)._______|______ |
* | | | | |
* | | | | |
* +-----+----| BITMAP |-----+
* | | | | |
* | 2 | |______________. |
* | | | (B2)|
* | | | (x2,y2)|
* +---- +------------+------------+
*
* Example of a bitmap that covers some of the area from cell A1 to cell B2.
*
* Based on the width and height of the bitmap we need to calculate 8 vars:
* $col_start, $row_start, $col_end, $row_end, $x1, $y1, $x2, $y2.
* The width and height of the cells are also variable and have to be taken into
* account.
* The values of $col_start and $row_start are passed in from the calling
* function. The values of $col_end and $row_end are calculated by subtracting
* the width and height of the bitmap from the width and height of the
* underlying cells.
* The vertices are expressed as a percentage of the underlying cell width as
* follows (rhs values are in pixels):
*
* x1 = X / W *1024
* y1 = Y / H *256
* x2 = (X-1) / W *1024
* y2 = (Y-1) / H *256
*
* Where: X is distance from the left side of the underlying cell
* Y is distance from the top of the underlying cell
* W is the width of the cell
* H is the height of the cell
*
* @param PHPExcel_Worksheet $sheet
* @param string $coordinates E.g. 'A1'
* @param integer $offsetX Horizontal offset in pixels
* @param integer $offsetY Vertical offset in pixels
* @param integer $width Width in pixels
* @param integer $height Height in pixels
* @return array
*/
public static function oneAnchor2twoAnchor($sheet, $coordinates, $offsetX, $offsetY, $width, $height)
{
list($column, $row) = PHPExcel_Cell::coordinateFromString($coordinates);
$col_start = PHPExcel_Cell::columnIndexFromString($column) - 1;
$row_start = $row - 1;
/**
* Get the horizontal distance in pixels between two anchors
* The distanceX is found as sum of all the spanning columns widths minus correction for the two offsets
*
* @param PHPExcel_Worksheet $sheet
* @param string $startColumn
* @param integer $startOffsetX Offset within start cell measured in 1/1024 of the cell width
* @param string $endColumn
* @param integer $endOffsetX Offset within end cell measured in 1/1024 of the cell width
* @return integer Horizontal measured in pixels
*/
public static function getDistanceX(PHPExcel_Worksheet $sheet, $startColumn = 'A', $startOffsetX = 0, $endColumn = 'A', $endOffsetX = 0)
{
$distanceX = 0;
$x1 = $offsetX;
$y1 = $offsetY;
// add the widths of the spanning columns
$startColumnIndex = PHPExcel_Cell::columnIndexFromString($startColumn) - 1; // 1-based
$endColumnIndex = PHPExcel_Cell::columnIndexFromString($endColumn) - 1; // 1-based
for ($i = $startColumnIndex; $i <= $endColumnIndex; ++$i) {
$distanceX += self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($i));
}
// Initialise end cell to the same as the start cell
$col_end = $col_start; // Col containing lower right corner of object
$row_end = $row_start; // Row containing bottom right corner of object
// correct for offsetX in startcell
$distanceX -= (int) floor(self::sizeCol($sheet, $startColumn) * $startOffsetX / 1024);
// Zero the specified offset if greater than the cell dimensions
if ($x1 >= self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start))) {
$x1 = 0;
}
if ($y1 >= self::sizeRow($sheet, $row_start + 1)) {
$y1 = 0;
}
// correct for offsetX in endcell
$distanceX -= (int) floor(self::sizeCol($sheet, $endColumn) * (1 - $endOffsetX / 1024));
$width = $width + $x1 -1;
$height = $height + $y1 -1;
return $distanceX;
}
// Subtract the underlying cell widths to find the end cell of the image
while ($width >= self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end))) {
$width -= self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end));
++$col_end;
}
/**
* Get the vertical distance in pixels between two anchors
* The distanceY is found as sum of all the spanning rows minus two offsets
*
* @param PHPExcel_Worksheet $sheet
* @param integer $startRow (1-based)
* @param integer $startOffsetY Offset within start cell measured in 1/256 of the cell height
* @param integer $endRow (1-based)
* @param integer $endOffsetY Offset within end cell measured in 1/256 of the cell height
* @return integer Vertical distance measured in pixels
*/
public static function getDistanceY(PHPExcel_Worksheet $sheet, $startRow = 1, $startOffsetY = 0, $endRow = 1, $endOffsetY = 0)
{
$distanceY = 0;
// Subtract the underlying cell heights to find the end cell of the image
while ($height >= self::sizeRow($sheet, $row_end + 1)) {
$height -= self::sizeRow($sheet, $row_end + 1);
++$row_end;
}
// add the widths of the spanning rows
for ($row = $startRow; $row <= $endRow; ++$row) {
$distanceY += self::sizeRow($sheet, $row);
}
// Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell
// with zero height or width.
if (self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) == 0) {
return;
}
if (self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end)) == 0) {
return;
}
if (self::sizeRow($sheet, $row_start + 1) == 0) {
return;
}
if (self::sizeRow($sheet, $row_end + 1) == 0) {
return;
}
// correct for offsetX in startcell
$distanceY -= (int) floor(self::sizeRow($sheet, $startRow) * $startOffsetY / 256);
// Convert the pixel values to the percentage value expected by Excel
$x1 = $x1 / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) * 1024;
$y1 = $y1 / self::sizeRow($sheet, $row_start + 1) * 256;
$x2 = ($width + 1) / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object
$y2 = ($height + 1) / self::sizeRow($sheet, $row_end + 1) * 256; // Distance to bottom of object
// correct for offsetX in endcell
$distanceY -= (int) floor(self::sizeRow($sheet, $endRow) * (1 - $endOffsetY / 256));
$startCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_start) . ($row_start + 1);
$endCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_end) . ($row_end + 1);
return $distanceY;
}
/**
* Convert 1-cell anchor coordinates to 2-cell anchor coordinates
* This function is ported from PEAR Spreadsheet_Writer_Excel with small modifications
*
* Calculate the vertices that define the position of the image as required by
* the OBJ record.
*
* +------------+------------+
* | A | B |
* +-----+------------+------------+
* | |(x1,y1) | |
* | 1 |(A1)._______|______ |
* | | | | |
* | | | | |
* +-----+----| BITMAP |-----+
* | | | | |
* | 2 | |______________. |
* | | | (B2)|
* | | | (x2,y2)|
* +---- +------------+------------+
*
* Example of a bitmap that covers some of the area from cell A1 to cell B2.
*
* Based on the width and height of the bitmap we need to calculate 8 vars:
* $col_start, $row_start, $col_end, $row_end, $x1, $y1, $x2, $y2.
* The width and height of the cells are also variable and have to be taken into
* account.
* The values of $col_start and $row_start are passed in from the calling
* function. The values of $col_end and $row_end are calculated by subtracting
* the width and height of the bitmap from the width and height of the
* underlying cells.
* The vertices are expressed as a percentage of the underlying cell width as
* follows (rhs values are in pixels):
*
* x1 = X / W *1024
* y1 = Y / H *256
* x2 = (X-1) / W *1024
* y2 = (Y-1) / H *256
*
* Where: X is distance from the left side of the underlying cell
* Y is distance from the top of the underlying cell
* W is the width of the cell
* H is the height of the cell
*
* @param PHPExcel_Worksheet $sheet
* @param string $coordinates E.g. 'A1'
* @param integer $offsetX Horizontal offset in pixels
* @param integer $offsetY Vertical offset in pixels
* @param integer $width Width in pixels
* @param integer $height Height in pixels
* @return array
*/
public static function oneAnchor2twoAnchor($sheet, $coordinates, $offsetX, $offsetY, $width, $height)
{
list($column, $row) = PHPExcel_Cell::coordinateFromString($coordinates);
$col_start = PHPExcel_Cell::columnIndexFromString($column) - 1;
$row_start = $row - 1;
$x1 = $offsetX;
$y1 = $offsetY;
// Initialise end cell to the same as the start cell
$col_end = $col_start; // Col containing lower right corner of object
$row_end = $row_start; // Row containing bottom right corner of object
// Zero the specified offset if greater than the cell dimensions
if ($x1 >= self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start))) {
$x1 = 0;
}
if ($y1 >= self::sizeRow($sheet, $row_start + 1)) {
$y1 = 0;
}
$width = $width + $x1 -1;
$height = $height + $y1 -1;
// Subtract the underlying cell widths to find the end cell of the image
while ($width >= self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end))) {
$width -= self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end));
++$col_end;
}
// Subtract the underlying cell heights to find the end cell of the image
while ($height >= self::sizeRow($sheet, $row_end + 1)) {
$height -= self::sizeRow($sheet, $row_end + 1);
++$row_end;
}
// Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell
// with zero height or width.
if (self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) == 0) {
return;
}
if (self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end)) == 0) {
return;
}
if (self::sizeRow($sheet, $row_start + 1) == 0) {
return;
}
if (self::sizeRow($sheet, $row_end + 1) == 0) {
return;
}
// Convert the pixel values to the percentage value expected by Excel
$x1 = $x1 / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) * 1024;
$y1 = $y1 / self::sizeRow($sheet, $row_start + 1) * 256;
$x2 = ($width + 1) / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object
$y2 = ($height + 1) / self::sizeRow($sheet, $row_end + 1) * 256; // Distance to bottom of object
$startCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_start) . ($row_start + 1);
$endCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_end) . ($row_end + 1);
$twoAnchor = array(
'startCoordinates' => $startCoordinates,
'startOffsetX' => $x1,
'startOffsetY' => $y1,
'endCoordinates' => $endCoordinates,
'endOffsetX' => $x2,
'endOffsetY' => $y2,
);
return $twoAnchor;
}
$twoAnchor = array(
'startCoordinates' => $startCoordinates,
'startOffsetX' => $x1,
'startOffsetY' => $y1,
'endCoordinates' => $endCoordinates,
'endOffsetX' => $x2,
'endOffsetY' => $y2,
);
return $twoAnchor;
}
}

View File

@@ -1,8 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_File
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,159 +21,160 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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_File
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_File
{
/*
* Use Temp or File Upload Temp for temporary files
*
* @protected
* @var boolean
*/
protected static $_useUploadTempDirectory = FALSE;
/*
* Use Temp or File Upload Temp for temporary files
*
* @protected
* @var boolean
*/
protected static $useUploadTempDirectory = false;
/**
* Set the flag indicating whether the File Upload Temp directory should be used for temporary files
*
* @param boolean $useUploadTempDir Use File Upload Temporary directory (true or false)
*/
public static function setUseUploadTempDirectory($useUploadTempDir = FALSE) {
self::$_useUploadTempDirectory = (boolean) $useUploadTempDir;
} // function setUseUploadTempDirectory()
/**
* Set the flag indicating whether the File Upload Temp directory should be used for temporary files
*
* @param boolean $useUploadTempDir Use File Upload Temporary directory (true or false)
*/
public static function setUseUploadTempDirectory($useUploadTempDir = false)
{
self::$useUploadTempDirectory = (boolean) $useUploadTempDir;
}
/**
* Get the flag indicating whether the File Upload Temp directory should be used for temporary files
*
* @return boolean Use File Upload Temporary directory (true or false)
*/
public static function getUseUploadTempDirectory() {
return self::$_useUploadTempDirectory;
} // function getUseUploadTempDirectory()
/**
* Get the flag indicating whether the File Upload Temp directory should be used for temporary files
*
* @return boolean Use File Upload Temporary directory (true or false)
*/
public static function getUseUploadTempDirectory()
{
return self::$useUploadTempDirectory;
}
/**
* Verify if a file exists
*
* @param string $pFilename Filename
* @return bool
*/
public static function file_exists($pFilename) {
// Sick construction, but it seems that
// file_exists returns strange values when
// doing the original file_exists on ZIP archives...
if ( strtolower(substr($pFilename, 0, 3)) == 'zip' ) {
// Open ZIP file and verify if the file exists
$zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
$archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);
/**
* Verify if a file exists
*
* @param string $pFilename Filename
* @return bool
*/
public static function file_exists($pFilename)
{
// Sick construction, but it seems that
// file_exists returns strange values when
// doing the original file_exists on ZIP archives...
if (strtolower(substr($pFilename, 0, 3)) == 'zip') {
// Open ZIP file and verify if the file exists
$zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
$archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);
$zip = new ZipArchive();
if ($zip->open($zipFile) === true) {
$returnValue = ($zip->getFromName($archiveFile) !== false);
$zip->close();
return $returnValue;
} else {
return false;
}
} else {
// Regular file_exists
return file_exists($pFilename);
}
}
$zip = new ZipArchive();
if ($zip->open($zipFile) === true) {
$returnValue = ($zip->getFromName($archiveFile) !== false);
$zip->close();
return $returnValue;
} else {
return false;
}
} else {
// Regular file_exists
return file_exists($pFilename);
}
}
/**
* Returns canonicalized absolute pathname, also for ZIP archives
*
* @param string $pFilename
* @return string
*/
public static function realpath($pFilename) {
// Returnvalue
$returnValue = '';
/**
* Returns canonicalized absolute pathname, also for ZIP archives
*
* @param string $pFilename
* @return string
*/
public static function realpath($pFilename)
{
// Returnvalue
$returnValue = '';
// Try using realpath()
if (file_exists($pFilename)) {
$returnValue = realpath($pFilename);
}
// Try using realpath()
if (file_exists($pFilename)) {
$returnValue = realpath($pFilename);
}
// Found something?
if ($returnValue == '' || ($returnValue === NULL)) {
$pathArray = explode('/' , $pFilename);
while(in_array('..', $pathArray) && $pathArray[0] != '..') {
for ($i = 0; $i < count($pathArray); ++$i) {
if ($pathArray[$i] == '..' && $i > 0) {
unset($pathArray[$i]);
unset($pathArray[$i - 1]);
break;
}
}
}
$returnValue = implode('/', $pathArray);
}
// Found something?
if ($returnValue == '' || ($returnValue === null)) {
$pathArray = explode('/', $pFilename);
while (in_array('..', $pathArray) && $pathArray[0] != '..') {
for ($i = 0; $i < count($pathArray); ++$i) {
if ($pathArray[$i] == '..' && $i > 0) {
unset($pathArray[$i]);
unset($pathArray[$i - 1]);
break;
}
}
}
$returnValue = implode('/', $pathArray);
}
// Return
return $returnValue;
}
// Return
return $returnValue;
}
/**
* Get the systems temporary directory.
*
* @return string
*/
public static function sys_get_temp_dir()
{
if (self::$_useUploadTempDirectory) {
// use upload-directory when defined to allow running on environments having very restricted
// open_basedir configs
if (ini_get('upload_tmp_dir') !== FALSE) {
if ($temp = ini_get('upload_tmp_dir')) {
if (file_exists($temp))
return realpath($temp);
}
}
}
/**
* Get the systems temporary directory.
*
* @return string
*/
public static function sys_get_temp_dir()
{
if (self::$useUploadTempDirectory) {
// use upload-directory when defined to allow running on environments having very restricted
// open_basedir configs
if (ini_get('upload_tmp_dir') !== false) {
if ($temp = ini_get('upload_tmp_dir')) {
if (file_exists($temp)) {
return realpath($temp);
}
}
}
}
// sys_get_temp_dir is only available since PHP 5.2.1
// http://php.net/manual/en/function.sys-get-temp-dir.php#94119
if ( !function_exists('sys_get_temp_dir')) {
if ($temp = getenv('TMP') ) {
if ((!empty($temp)) && (file_exists($temp))) { return realpath($temp); }
}
if ($temp = getenv('TEMP') ) {
if ((!empty($temp)) && (file_exists($temp))) { return realpath($temp); }
}
if ($temp = getenv('TMPDIR') ) {
if ((!empty($temp)) && (file_exists($temp))) { return realpath($temp); }
}
// sys_get_temp_dir is only available since PHP 5.2.1
// http://php.net/manual/en/function.sys-get-temp-dir.php#94119
if (!function_exists('sys_get_temp_dir')) {
if ($temp = getenv('TMP')) {
if ((!empty($temp)) && (file_exists($temp))) {
return realpath($temp);
}
}
if ($temp = getenv('TEMP')) {
if ((!empty($temp)) && (file_exists($temp))) {
return realpath($temp);
}
}
if ($temp = getenv('TMPDIR')) {
if ((!empty($temp)) && (file_exists($temp))) {
return realpath($temp);
}
}
// trick for creating a file in system's temporary dir
// without knowing the path of the system's temporary dir
$temp = tempnam(__FILE__, '');
if (file_exists($temp)) {
unlink($temp);
return realpath(dirname($temp));
}
// trick for creating a file in system's temporary dir
// without knowing the path of the system's temporary dir
$temp = tempnam(__FILE__, '');
if (file_exists($temp)) {
unlink($temp);
return realpath(dirname($temp));
}
return null;
}
// use ordinary built-in PHP function
// There should be no problem with the 5.2.4 Suhosin realpath() bug, because this line should only
// be called if we're running 5.2.1 or earlier
return realpath(sys_get_temp_dir());
}
return null;
}
// use ordinary built-in PHP function
// There should be no problem with the 5.2.4 Suhosin realpath() bug, because this line should only
// be called if we're running 5.2.1 or earlier
return realpath(sys_get_temp_dir());
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,149 +1,148 @@
<?php
/**
* @package JAMA
* @package JAMA
*
* Cholesky decomposition class
* Cholesky decomposition class
*
* For a symmetric, positive definite matrix A, the Cholesky decomposition
* is an lower triangular matrix L so that A = L*L'.
* For a symmetric, positive definite matrix A, the Cholesky decomposition
* is an lower triangular matrix L so that A = L*L'.
*
* If the matrix is not symmetric or positive definite, the constructor
* returns a partial decomposition and sets an internal flag that may
* be queried by the isSPD() method.
* If the matrix is not symmetric or positive definite, the constructor
* returns a partial decomposition and sets an internal flag that may
* be queried by the isSPD() method.
*
* @author Paul Meagher
* @author Michael Bommarito
* @version 1.2
* @author Paul Meagher
* @author Michael Bommarito
* @version 1.2
*/
class CholeskyDecomposition {
class CholeskyDecomposition
{
/**
* Decomposition storage
* @var array
* @access private
*/
private $L = array();
/**
* Decomposition storage
* @var array
* @access private
*/
private $L = array();
/**
* Matrix row and column dimension
* @var int
* @access private
*/
private $m;
/**
* Matrix row and column dimension
* @var int
* @access private
*/
private $m;
/**
* Symmetric positive definite flag
* @var boolean
* @access private
*/
private $isspd = true;
/**
* Symmetric positive definite flag
* @var boolean
* @access private
*/
private $isspd = true;
/**
* CholeskyDecomposition
*
* Class constructor - decomposes symmetric positive definite matrix
* @param mixed Matrix square symmetric positive definite matrix
*/
public function __construct($A = null)
{
if ($A instanceof Matrix) {
$this->L = $A->getArray();
$this->m = $A->getRowDimension();
for ($i = 0; $i < $this->m; ++$i) {
for ($j = $i; $j < $this->m; ++$j) {
for ($sum = $this->L[$i][$j], $k = $i - 1; $k >= 0; --$k) {
$sum -= $this->L[$i][$k] * $this->L[$j][$k];
}
if ($i == $j) {
if ($sum >= 0) {
$this->L[$i][$i] = sqrt($sum);
} else {
$this->isspd = false;
}
} else {
if ($this->L[$i][$i] != 0) {
$this->L[$j][$i] = $sum / $this->L[$i][$i];
}
}
}
/**
* CholeskyDecomposition
*
* Class constructor - decomposes symmetric positive definite matrix
* @param mixed Matrix square symmetric positive definite matrix
*/
public function __construct($A = null) {
if ($A instanceof Matrix) {
$this->L = $A->getArray();
$this->m = $A->getRowDimension();
for ($k = $i+1; $k < $this->m; ++$k) {
$this->L[$i][$k] = 0.0;
}
}
} else {
throw new PHPExcel_Calculation_Exception(JAMAError(ARGUMENT_TYPE_EXCEPTION));
}
} // function __construct()
for($i = 0; $i < $this->m; ++$i) {
for($j = $i; $j < $this->m; ++$j) {
for($sum = $this->L[$i][$j], $k = $i - 1; $k >= 0; --$k) {
$sum -= $this->L[$i][$k] * $this->L[$j][$k];
}
if ($i == $j) {
if ($sum >= 0) {
$this->L[$i][$i] = sqrt($sum);
} else {
$this->isspd = false;
}
} else {
if ($this->L[$i][$i] != 0) {
$this->L[$j][$i] = $sum / $this->L[$i][$i];
}
}
}
/**
* Is the matrix symmetric and positive definite?
*
* @return boolean
*/
public function isSPD()
{
return $this->isspd;
} // function isSPD()
for ($k = $i+1; $k < $this->m; ++$k) {
$this->L[$i][$k] = 0.0;
}
}
} else {
throw new PHPExcel_Calculation_Exception(JAMAError(ArgumentTypeException));
}
} // function __construct()
/**
* getL
*
* Return triangular factor.
* @return Matrix Lower triangular matrix
*/
public function getL()
{
return new Matrix($this->L);
} // function getL()
/**
* Solve A*X = B
*
* @param $B Row-equal matrix
* @return Matrix L * L' * X = B
*/
public function solve($B = null)
{
if ($B instanceof Matrix) {
if ($B->getRowDimension() == $this->m) {
if ($this->isspd) {
$X = $B->getArrayCopy();
$nx = $B->getColumnDimension();
/**
* Is the matrix symmetric and positive definite?
*
* @return boolean
*/
public function isSPD() {
return $this->isspd;
} // function isSPD()
for ($k = 0; $k < $this->m; ++$k) {
for ($i = $k + 1; $i < $this->m; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X[$i][$j] -= $X[$k][$j] * $this->L[$i][$k];
}
}
for ($j = 0; $j < $nx; ++$j) {
$X[$k][$j] /= $this->L[$k][$k];
}
}
for ($k = $this->m - 1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; ++$j) {
$X[$k][$j] /= $this->L[$k][$k];
}
for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X[$i][$j] -= $X[$k][$j] * $this->L[$k][$i];
}
}
}
/**
* getL
*
* Return triangular factor.
* @return Matrix Lower triangular matrix
*/
public function getL() {
return new Matrix($this->L);
} // function getL()
/**
* Solve A*X = B
*
* @param $B Row-equal matrix
* @return Matrix L * L' * X = B
*/
public function solve($B = null) {
if ($B instanceof Matrix) {
if ($B->getRowDimension() == $this->m) {
if ($this->isspd) {
$X = $B->getArrayCopy();
$nx = $B->getColumnDimension();
for ($k = 0; $k < $this->m; ++$k) {
for ($i = $k + 1; $i < $this->m; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X[$i][$j] -= $X[$k][$j] * $this->L[$i][$k];
}
}
for ($j = 0; $j < $nx; ++$j) {
$X[$k][$j] /= $this->L[$k][$k];
}
}
for ($k = $this->m - 1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; ++$j) {
$X[$k][$j] /= $this->L[$k][$k];
}
for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X[$i][$j] -= $X[$k][$j] * $this->L[$k][$i];
}
}
}
return new Matrix($X, $this->m, $nx);
} else {
throw new PHPExcel_Calculation_Exception(JAMAError(MatrixSPDException));
}
} else {
throw new PHPExcel_Calculation_Exception(JAMAError(MatrixDimensionException));
}
} else {
throw new PHPExcel_Calculation_Exception(JAMAError(ArgumentTypeException));
}
} // function solve()
} // class CholeskyDecomposition
return new Matrix($X, $this->m, $nx);
} else {
throw new PHPExcel_Calculation_Exception(JAMAError(MatrixSPDException));
}
} else {
throw new PHPExcel_Calculation_Exception(JAMAError(MATRIX_DIMENSION_EXCEPTION));
}
} else {
throw new PHPExcel_Calculation_Exception(JAMAError(ARGUMENT_TYPE_EXCEPTION));
}
} // function solve()
}

View File

@@ -1,258 +1,257 @@
<?php
/**
* @package JAMA
* @package JAMA
*
* For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n
* unit lower triangular matrix L, an n-by-n upper triangular matrix U,
* and a permutation vector piv of length m so that A(piv,:) = L*U.
* If m < n, then L is m-by-m and U is m-by-n.
* For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n
* unit lower triangular matrix L, an n-by-n upper triangular matrix U,
* and a permutation vector piv of length m so that A(piv,:) = L*U.
* If m < n, then L is m-by-m and U is m-by-n.
*
* The LU decompostion with pivoting always exists, even if the matrix is
* singular, so the constructor will never fail. The primary use of the
* LU decomposition is in the solution of square systems of simultaneous
* linear equations. This will fail if isNonsingular() returns false.
* The LU decompostion with pivoting always exists, even if the matrix is
* singular, so the constructor will never fail. The primary use of the
* LU decomposition is in the solution of square systems of simultaneous
* linear equations. This will fail if isNonsingular() returns false.
*
* @author Paul Meagher
* @author Bartosz Matosiuk
* @author Michael Bommarito
* @version 1.1
* @license PHP v3.0
* @author Paul Meagher
* @author Bartosz Matosiuk
* @author Michael Bommarito
* @version 1.1
* @license PHP v3.0
*/
class PHPExcel_Shared_JAMA_LUDecomposition {
class PHPExcel_Shared_JAMA_LUDecomposition
{
const MATRIX_SINGULAR_EXCEPTION = "Can only perform operation on singular matrix.";
const MATRIX_SQUARE_EXCEPTION = "Mismatched Row dimension";
const MatrixSingularException = "Can only perform operation on singular matrix.";
const MatrixSquareException = "Mismatched Row dimension";
/**
* Decomposition storage
* @var array
*/
private $LU = array();
/**
* Decomposition storage
* @var array
*/
private $LU = array();
/**
* Row dimension.
* @var int
*/
private $m;
/**
* Row dimension.
* @var int
*/
private $m;
/**
* Column dimension.
* @var int
*/
private $n;
/**
* Column dimension.
* @var int
*/
private $n;
/**
* Pivot sign.
* @var int
*/
private $pivsign;
/**
* Pivot sign.
* @var int
*/
private $pivsign;
/**
* Internal storage of pivot vector.
* @var array
*/
private $piv = array();
/**
* Internal storage of pivot vector.
* @var array
*/
private $piv = array();
/**
* LU Decomposition constructor.
*
* @param $A Rectangular matrix
* @return Structure to access L, U and piv.
*/
public function __construct($A)
{
if ($A instanceof PHPExcel_Shared_JAMA_Matrix) {
// Use a "left-looking", dot-product, Crout/Doolittle algorithm.
$this->LU = $A->getArray();
$this->m = $A->getRowDimension();
$this->n = $A->getColumnDimension();
for ($i = 0; $i < $this->m; ++$i) {
$this->piv[$i] = $i;
}
$this->pivsign = 1;
$LUrowi = $LUcolj = array();
// Outer loop.
for ($j = 0; $j < $this->n; ++$j) {
// Make a copy of the j-th column to localize references.
for ($i = 0; $i < $this->m; ++$i) {
$LUcolj[$i] = &$this->LU[$i][$j];
}
// Apply previous transformations.
for ($i = 0; $i < $this->m; ++$i) {
$LUrowi = $this->LU[$i];
// Most of the time is spent in the following dot product.
$kmax = min($i, $j);
$s = 0.0;
for ($k = 0; $k < $kmax; ++$k) {
$s += $LUrowi[$k] * $LUcolj[$k];
}
$LUrowi[$j] = $LUcolj[$i] -= $s;
}
// Find pivot and exchange if necessary.
$p = $j;
for ($i = $j+1; $i < $this->m; ++$i) {
if (abs($LUcolj[$i]) > abs($LUcolj[$p])) {
$p = $i;
}
}
if ($p != $j) {
for ($k = 0; $k < $this->n; ++$k) {
$t = $this->LU[$p][$k];
$this->LU[$p][$k] = $this->LU[$j][$k];
$this->LU[$j][$k] = $t;
}
$k = $this->piv[$p];
$this->piv[$p] = $this->piv[$j];
$this->piv[$j] = $k;
$this->pivsign = $this->pivsign * -1;
}
// Compute multipliers.
if (($j < $this->m) && ($this->LU[$j][$j] != 0.0)) {
for ($i = $j+1; $i < $this->m; ++$i) {
$this->LU[$i][$j] /= $this->LU[$j][$j];
}
}
}
} else {
throw new PHPExcel_Calculation_Exception(PHPExcel_Shared_JAMA_Matrix::ARGUMENT_TYPE_EXCEPTION);
}
} // function __construct()
/**
* LU Decomposition constructor.
*
* @param $A Rectangular matrix
* @return Structure to access L, U and piv.
*/
public function __construct($A) {
if ($A instanceof PHPExcel_Shared_JAMA_Matrix) {
// Use a "left-looking", dot-product, Crout/Doolittle algorithm.
$this->LU = $A->getArray();
$this->m = $A->getRowDimension();
$this->n = $A->getColumnDimension();
for ($i = 0; $i < $this->m; ++$i) {
$this->piv[$i] = $i;
}
$this->pivsign = 1;
$LUrowi = $LUcolj = array();
/**
* Get lower triangular factor.
*
* @return array Lower triangular factor
*/
public function getL()
{
for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i > $j) {
$L[$i][$j] = $this->LU[$i][$j];
} elseif ($i == $j) {
$L[$i][$j] = 1.0;
} else {
$L[$i][$j] = 0.0;
}
}
}
return new PHPExcel_Shared_JAMA_Matrix($L);
} // function getL()
// Outer loop.
for ($j = 0; $j < $this->n; ++$j) {
// Make a copy of the j-th column to localize references.
for ($i = 0; $i < $this->m; ++$i) {
$LUcolj[$i] = &$this->LU[$i][$j];
}
// Apply previous transformations.
for ($i = 0; $i < $this->m; ++$i) {
$LUrowi = $this->LU[$i];
// Most of the time is spent in the following dot product.
$kmax = min($i,$j);
$s = 0.0;
for ($k = 0; $k < $kmax; ++$k) {
$s += $LUrowi[$k] * $LUcolj[$k];
}
$LUrowi[$j] = $LUcolj[$i] -= $s;
}
// Find pivot and exchange if necessary.
$p = $j;
for ($i = $j+1; $i < $this->m; ++$i) {
if (abs($LUcolj[$i]) > abs($LUcolj[$p])) {
$p = $i;
}
}
if ($p != $j) {
for ($k = 0; $k < $this->n; ++$k) {
$t = $this->LU[$p][$k];
$this->LU[$p][$k] = $this->LU[$j][$k];
$this->LU[$j][$k] = $t;
}
$k = $this->piv[$p];
$this->piv[$p] = $this->piv[$j];
$this->piv[$j] = $k;
$this->pivsign = $this->pivsign * -1;
}
// Compute multipliers.
if (($j < $this->m) && ($this->LU[$j][$j] != 0.0)) {
for ($i = $j+1; $i < $this->m; ++$i) {
$this->LU[$i][$j] /= $this->LU[$j][$j];
}
}
}
} else {
throw new PHPExcel_Calculation_Exception(PHPExcel_Shared_JAMA_Matrix::ArgumentTypeException);
}
} // function __construct()
/**
* Get upper triangular factor.
*
* @return array Upper triangular factor
*/
public function getU()
{
for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i <= $j) {
$U[$i][$j] = $this->LU[$i][$j];
} else {
$U[$i][$j] = 0.0;
}
}
}
return new PHPExcel_Shared_JAMA_Matrix($U);
} // function getU()
/**
* Return pivot permutation vector.
*
* @return array Pivot vector
*/
public function getPivot()
{
return $this->piv;
} // function getPivot()
/**
* Get lower triangular factor.
*
* @return array Lower triangular factor
*/
public function getL() {
for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i > $j) {
$L[$i][$j] = $this->LU[$i][$j];
} elseif ($i == $j) {
$L[$i][$j] = 1.0;
} else {
$L[$i][$j] = 0.0;
}
}
}
return new PHPExcel_Shared_JAMA_Matrix($L);
} // function getL()
/**
* Alias for getPivot
*
* @see getPivot
*/
public function getDoublePivot()
{
return $this->getPivot();
} // function getDoublePivot()
/**
* Is the matrix nonsingular?
*
* @return true if U, and hence A, is nonsingular.
*/
public function isNonsingular()
{
for ($j = 0; $j < $this->n; ++$j) {
if ($this->LU[$j][$j] == 0) {
return false;
}
}
return true;
} // function isNonsingular()
/**
* Get upper triangular factor.
*
* @return array Upper triangular factor
*/
public function getU() {
for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i <= $j) {
$U[$i][$j] = $this->LU[$i][$j];
} else {
$U[$i][$j] = 0.0;
}
}
}
return new PHPExcel_Shared_JAMA_Matrix($U);
} // function getU()
/**
* Count determinants
*
* @return array d matrix deterninat
*/
public function det()
{
if ($this->m == $this->n) {
$d = $this->pivsign;
for ($j = 0; $j < $this->n; ++$j) {
$d *= $this->LU[$j][$j];
}
return $d;
} else {
throw new PHPExcel_Calculation_Exception(PHPExcel_Shared_JAMA_Matrix::MATRIX_DIMENSION_EXCEPTION);
}
} // function det()
/**
* Return pivot permutation vector.
*
* @return array Pivot vector
*/
public function getPivot() {
return $this->piv;
} // function getPivot()
/**
* Alias for getPivot
*
* @see getPivot
*/
public function getDoublePivot() {
return $this->getPivot();
} // function getDoublePivot()
/**
* Is the matrix nonsingular?
*
* @return true if U, and hence A, is nonsingular.
*/
public function isNonsingular() {
for ($j = 0; $j < $this->n; ++$j) {
if ($this->LU[$j][$j] == 0) {
return false;
}
}
return true;
} // function isNonsingular()
/**
* Count determinants
*
* @return array d matrix deterninat
*/
public function det() {
if ($this->m == $this->n) {
$d = $this->pivsign;
for ($j = 0; $j < $this->n; ++$j) {
$d *= $this->LU[$j][$j];
}
return $d;
} else {
throw new PHPExcel_Calculation_Exception(PHPExcel_Shared_JAMA_Matrix::MatrixDimensionException);
}
} // function det()
/**
* Solve A*X = B
*
* @param $B A Matrix with as many rows as A and any number of columns.
* @return X so that L*U*X = B(piv,:)
* @PHPExcel_Calculation_Exception IllegalArgumentException Matrix row dimensions must agree.
* @PHPExcel_Calculation_Exception RuntimeException Matrix is singular.
*/
public function solve($B) {
if ($B->getRowDimension() == $this->m) {
if ($this->isNonsingular()) {
// Copy right hand side with pivoting
$nx = $B->getColumnDimension();
$X = $B->getMatrix($this->piv, 0, $nx-1);
// Solve L*Y = B(piv,:)
for ($k = 0; $k < $this->n; ++$k) {
for ($i = $k+1; $i < $this->n; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
}
}
}
// Solve U*X = Y;
for ($k = $this->n-1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; ++$j) {
$X->A[$k][$j] /= $this->LU[$k][$k];
}
for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
}
}
}
return $X;
} else {
throw new PHPExcel_Calculation_Exception(self::MatrixSingularException);
}
} else {
throw new PHPExcel_Calculation_Exception(self::MatrixSquareException);
}
} // function solve()
} // class PHPExcel_Shared_JAMA_LUDecomposition
/**
* Solve A*X = B
*
* @param $B A Matrix with as many rows as A and any number of columns.
* @return X so that L*U*X = B(piv,:)
* @PHPExcel_Calculation_Exception IllegalArgumentException Matrix row dimensions must agree.
* @PHPExcel_Calculation_Exception RuntimeException Matrix is singular.
*/
public function solve($B)
{
if ($B->getRowDimension() == $this->m) {
if ($this->isNonsingular()) {
// Copy right hand side with pivoting
$nx = $B->getColumnDimension();
$X = $B->getMatrix($this->piv, 0, $nx-1);
// Solve L*Y = B(piv,:)
for ($k = 0; $k < $this->n; ++$k) {
for ($i = $k+1; $i < $this->n; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
}
}
}
// Solve U*X = Y;
for ($k = $this->n-1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; ++$j) {
$X->A[$k][$j] /= $this->LU[$k][$k];
}
for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
}
}
}
return $X;
} else {
throw new PHPExcel_Calculation_Exception(self::MATRIX_SINGULAR_EXCEPTION);
}
} else {
throw new PHPExcel_Calculation_Exception(self::MATRIX_SQUARE_EXCEPTION);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,234 +1,235 @@
<?php
/**
* @package JAMA
* @package JAMA
*
* For an m-by-n matrix A with m >= n, the QR decomposition is an m-by-n
* orthogonal matrix Q and an n-by-n upper triangular matrix R so that
* A = Q*R.
* For an m-by-n matrix A with m >= n, the QR decomposition is an m-by-n
* orthogonal matrix Q and an n-by-n upper triangular matrix R so that
* A = Q*R.
*
* The QR decompostion always exists, even if the matrix does not have
* full rank, so the constructor will never fail. The primary use of the
* QR decomposition is in the least squares solution of nonsquare systems
* of simultaneous linear equations. This will fail if isFullRank()
* returns false.
* The QR decompostion always exists, even if the matrix does not have
* full rank, so the constructor will never fail. The primary use of the
* QR decomposition is in the least squares solution of nonsquare systems
* of simultaneous linear equations. This will fail if isFullRank()
* returns false.
*
* @author Paul Meagher
* @license PHP v3.0
* @version 1.1
* @author Paul Meagher
* @license PHP v3.0
* @version 1.1
*/
class PHPExcel_Shared_JAMA_QRDecomposition {
class PHPExcel_Shared_JAMA_QRDecomposition
{
const MATRIX_RANK_EXCEPTION = "Can only perform operation on full-rank matrix.";
const MatrixRankException = "Can only perform operation on full-rank matrix.";
/**
* Array for internal storage of decomposition.
* @var array
*/
private $QR = array();
/**
* Array for internal storage of decomposition.
* @var array
*/
private $QR = array();
/**
* Row dimension.
* @var integer
*/
private $m;
/**
* Row dimension.
* @var integer
*/
private $m;
/**
* Column dimension.
* @var integer
*/
private $n;
/**
* Column dimension.
* @var integer
*/
private $n;
/**
* Array for internal storage of diagonal of R.
* @var array
*/
private $Rdiag = array();
/**
* Array for internal storage of diagonal of R.
* @var array
*/
private $Rdiag = array();
/**
* QR Decomposition computed by Householder reflections.
*
* @param matrix $A Rectangular matrix
* @return Structure to access R and the Householder vectors and compute Q.
*/
public function __construct($A) {
if($A instanceof PHPExcel_Shared_JAMA_Matrix) {
// Initialize.
$this->QR = $A->getArrayCopy();
$this->m = $A->getRowDimension();
$this->n = $A->getColumnDimension();
// Main loop.
for ($k = 0; $k < $this->n; ++$k) {
// Compute 2-norm of k-th column without under/overflow.
$nrm = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$nrm = hypo($nrm, $this->QR[$i][$k]);
}
if ($nrm != 0.0) {
// Form k-th Householder vector.
if ($this->QR[$k][$k] < 0) {
$nrm = -$nrm;
}
for ($i = $k; $i < $this->m; ++$i) {
$this->QR[$i][$k] /= $nrm;
}
$this->QR[$k][$k] += 1.0;
// Apply transformation to remaining columns.
for ($j = $k+1; $j < $this->n; ++$j) {
$s = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $this->QR[$i][$j];
}
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; ++$i) {
$this->QR[$i][$j] += $s * $this->QR[$i][$k];
}
}
}
$this->Rdiag[$k] = -$nrm;
}
} else {
throw new PHPExcel_Calculation_Exception(PHPExcel_Shared_JAMA_Matrix::ArgumentTypeException);
}
} // function __construct()
/**
* QR Decomposition computed by Householder reflections.
*
* @param matrix $A Rectangular matrix
* @return Structure to access R and the Householder vectors and compute Q.
*/
public function __construct($A)
{
if ($A instanceof PHPExcel_Shared_JAMA_Matrix) {
// Initialize.
$this->QR = $A->getArrayCopy();
$this->m = $A->getRowDimension();
$this->n = $A->getColumnDimension();
// Main loop.
for ($k = 0; $k < $this->n; ++$k) {
// Compute 2-norm of k-th column without under/overflow.
$nrm = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$nrm = hypo($nrm, $this->QR[$i][$k]);
}
if ($nrm != 0.0) {
// Form k-th Householder vector.
if ($this->QR[$k][$k] < 0) {
$nrm = -$nrm;
}
for ($i = $k; $i < $this->m; ++$i) {
$this->QR[$i][$k] /= $nrm;
}
$this->QR[$k][$k] += 1.0;
// Apply transformation to remaining columns.
for ($j = $k+1; $j < $this->n; ++$j) {
$s = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $this->QR[$i][$j];
}
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; ++$i) {
$this->QR[$i][$j] += $s * $this->QR[$i][$k];
}
}
}
$this->Rdiag[$k] = -$nrm;
}
} else {
throw new PHPExcel_Calculation_Exception(PHPExcel_Shared_JAMA_Matrix::ARGUMENT_TYPE_EXCEPTION);
}
} // function __construct()
/**
* Is the matrix full rank?
*
* @return boolean true if R, and hence A, has full rank, else false.
*/
public function isFullRank() {
for ($j = 0; $j < $this->n; ++$j) {
if ($this->Rdiag[$j] == 0) {
return false;
}
}
return true;
} // function isFullRank()
/**
* Is the matrix full rank?
*
* @return boolean true if R, and hence A, has full rank, else false.
*/
public function isFullRank()
{
for ($j = 0; $j < $this->n; ++$j) {
if ($this->Rdiag[$j] == 0) {
return false;
}
}
return true;
} // function isFullRank()
/**
* Return the Householder vectors
*
* @return Matrix Lower trapezoidal matrix whose columns define the reflections
*/
public function getH()
{
for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i >= $j) {
$H[$i][$j] = $this->QR[$i][$j];
} else {
$H[$i][$j] = 0.0;
}
}
}
return new PHPExcel_Shared_JAMA_Matrix($H);
} // function getH()
/**
* Return the Householder vectors
*
* @return Matrix Lower trapezoidal matrix whose columns define the reflections
*/
public function getH() {
for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i >= $j) {
$H[$i][$j] = $this->QR[$i][$j];
} else {
$H[$i][$j] = 0.0;
}
}
}
return new PHPExcel_Shared_JAMA_Matrix($H);
} // function getH()
/**
* Return the upper triangular factor
*
* @return Matrix upper triangular factor
*/
public function getR()
{
for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i < $j) {
$R[$i][$j] = $this->QR[$i][$j];
} elseif ($i == $j) {
$R[$i][$j] = $this->Rdiag[$i];
} else {
$R[$i][$j] = 0.0;
}
}
}
return new PHPExcel_Shared_JAMA_Matrix($R);
} // function getR()
/**
* Generate and return the (economy-sized) orthogonal factor
*
* @return Matrix orthogonal factor
*/
public function getQ()
{
for ($k = $this->n-1; $k >= 0; --$k) {
for ($i = 0; $i < $this->m; ++$i) {
$Q[$i][$k] = 0.0;
}
$Q[$k][$k] = 1.0;
for ($j = $k; $j < $this->n; ++$j) {
if ($this->QR[$k][$k] != 0) {
$s = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $Q[$i][$j];
}
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; ++$i) {
$Q[$i][$j] += $s * $this->QR[$i][$k];
}
}
}
}
/*
for($i = 0; $i < count($Q); ++$i) {
for($j = 0; $j < count($Q); ++$j) {
if (! isset($Q[$i][$j]) ) {
$Q[$i][$j] = 0;
}
}
}
*/
return new PHPExcel_Shared_JAMA_Matrix($Q);
} // function getQ()
/**
* Return the upper triangular factor
*
* @return Matrix upper triangular factor
*/
public function getR() {
for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i < $j) {
$R[$i][$j] = $this->QR[$i][$j];
} elseif ($i == $j) {
$R[$i][$j] = $this->Rdiag[$i];
} else {
$R[$i][$j] = 0.0;
}
}
}
return new PHPExcel_Shared_JAMA_Matrix($R);
} // function getR()
/**
* Generate and return the (economy-sized) orthogonal factor
*
* @return Matrix orthogonal factor
*/
public function getQ() {
for ($k = $this->n-1; $k >= 0; --$k) {
for ($i = 0; $i < $this->m; ++$i) {
$Q[$i][$k] = 0.0;
}
$Q[$k][$k] = 1.0;
for ($j = $k; $j < $this->n; ++$j) {
if ($this->QR[$k][$k] != 0) {
$s = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $Q[$i][$j];
}
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; ++$i) {
$Q[$i][$j] += $s * $this->QR[$i][$k];
}
}
}
}
/*
for($i = 0; $i < count($Q); ++$i) {
for($j = 0; $j < count($Q); ++$j) {
if(! isset($Q[$i][$j]) ) {
$Q[$i][$j] = 0;
}
}
}
*/
return new PHPExcel_Shared_JAMA_Matrix($Q);
} // function getQ()
/**
* Least squares solution of A*X = B
*
* @param Matrix $B A Matrix with as many rows as A and any number of columns.
* @return Matrix Matrix that minimizes the two norm of Q*R*X-B.
*/
public function solve($B) {
if ($B->getRowDimension() == $this->m) {
if ($this->isFullRank()) {
// Copy right hand side
$nx = $B->getColumnDimension();
$X = $B->getArrayCopy();
// Compute Y = transpose(Q)*B
for ($k = 0; $k < $this->n; ++$k) {
for ($j = 0; $j < $nx; ++$j) {
$s = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $X[$i][$j];
}
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; ++$i) {
$X[$i][$j] += $s * $this->QR[$i][$k];
}
}
}
// Solve R*X = Y;
for ($k = $this->n-1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; ++$j) {
$X[$k][$j] /= $this->Rdiag[$k];
}
for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X[$i][$j] -= $X[$k][$j]* $this->QR[$i][$k];
}
}
}
$X = new PHPExcel_Shared_JAMA_Matrix($X);
return ($X->getMatrix(0, $this->n-1, 0, $nx));
} else {
throw new PHPExcel_Calculation_Exception(self::MatrixRankException);
}
} else {
throw new PHPExcel_Calculation_Exception(PHPExcel_Shared_JAMA_Matrix::MatrixDimensionException);
}
} // function solve()
} // PHPExcel_Shared_JAMA_class QRDecomposition
/**
* Least squares solution of A*X = B
*
* @param Matrix $B A Matrix with as many rows as A and any number of columns.
* @return Matrix Matrix that minimizes the two norm of Q*R*X-B.
*/
public function solve($B)
{
if ($B->getRowDimension() == $this->m) {
if ($this->isFullRank()) {
// Copy right hand side
$nx = $B->getColumnDimension();
$X = $B->getArrayCopy();
// Compute Y = transpose(Q)*B
for ($k = 0; $k < $this->n; ++$k) {
for ($j = 0; $j < $nx; ++$j) {
$s = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $X[$i][$j];
}
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; ++$i) {
$X[$i][$j] += $s * $this->QR[$i][$k];
}
}
}
// Solve R*X = Y;
for ($k = $this->n-1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; ++$j) {
$X[$k][$j] /= $this->Rdiag[$k];
}
for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X[$i][$j] -= $X[$k][$j]* $this->QR[$i][$k];
}
}
}
$X = new PHPExcel_Shared_JAMA_Matrix($X);
return ($X->getMatrix(0, $this->n-1, 0, $nx));
} else {
throw new PHPExcel_Calculation_Exception(self::MATRIX_RANK_EXCEPTION);
}
} else {
throw new PHPExcel_Calculation_Exception(PHPExcel_Shared_JAMA_Matrix::MATRIX_DIMENSION_EXCEPTION);
}
}
}

View File

@@ -1,10 +1,10 @@
<?php
/**
* @package JAMA
* @package JAMA
*
* Error handling
* @author Michael Bommarito
* @version 01292005
* Error handling
* @author Michael Bommarito
* @version 01292005
*/
//Language constant
@@ -21,62 +21,63 @@ I've used Babelfish and a little poor knowledge of Romance/Germanic languages fo
Feel free to correct anything that looks amiss to you.
*/
define('PolymorphicArgumentException', -1);
$error['EN'][PolymorphicArgumentException] = "Invalid argument pattern for polymorphic function.";
$error['FR'][PolymorphicArgumentException] = "Modèle inadmissible d'argument pour la fonction polymorphe.".
$error['DE'][PolymorphicArgumentException] = "Unzulässiges Argumentmuster für polymorphe Funktion.";
define('POLYMORPHIC_ARGUMENT_EXCEPTION', -1);
$error['EN'][POLYMORPHIC_ARGUMENT_EXCEPTION] = "Invalid argument pattern for polymorphic function.";
$error['FR'][POLYMORPHIC_ARGUMENT_EXCEPTION] = "Modèle inadmissible d'argument pour la fonction polymorphe.".
$error['DE'][POLYMORPHIC_ARGUMENT_EXCEPTION] = "Unzulässiges Argumentmuster für polymorphe Funktion.";
define('ArgumentTypeException', -2);
$error['EN'][ArgumentTypeException] = "Invalid argument type.";
$error['FR'][ArgumentTypeException] = "Type inadmissible d'argument.";
$error['DE'][ArgumentTypeException] = "Unzulässige Argumentart.";
define('ARGUMENT_TYPE_EXCEPTION', -2);
$error['EN'][ARGUMENT_TYPE_EXCEPTION] = "Invalid argument type.";
$error['FR'][ARGUMENT_TYPE_EXCEPTION] = "Type inadmissible d'argument.";
$error['DE'][ARGUMENT_TYPE_EXCEPTION] = "Unzulässige Argumentart.";
define('ArgumentBoundsException', -3);
$error['EN'][ArgumentBoundsException] = "Invalid argument range.";
$error['FR'][ArgumentBoundsException] = "Gamme inadmissible d'argument.";
$error['DE'][ArgumentBoundsException] = "Unzulässige Argumentstrecke.";
define('ARGUMENT_BOUNDS_EXCEPTION', -3);
$error['EN'][ARGUMENT_BOUNDS_EXCEPTION] = "Invalid argument range.";
$error['FR'][ARGUMENT_BOUNDS_EXCEPTION] = "Gamme inadmissible d'argument.";
$error['DE'][ARGUMENT_BOUNDS_EXCEPTION] = "Unzulässige Argumentstrecke.";
define('MatrixDimensionException', -4);
$error['EN'][MatrixDimensionException] = "Matrix dimensions are not equal.";
$error['FR'][MatrixDimensionException] = "Les dimensions de Matrix ne sont pas égales.";
$error['DE'][MatrixDimensionException] = "Matrixmaße sind nicht gleich.";
define('MATRIX_DIMENSION_EXCEPTION', -4);
$error['EN'][MATRIX_DIMENSION_EXCEPTION] = "Matrix dimensions are not equal.";
$error['FR'][MATRIX_DIMENSION_EXCEPTION] = "Les dimensions de Matrix ne sont pas égales.";
$error['DE'][MATRIX_DIMENSION_EXCEPTION] = "Matrixmaße sind nicht gleich.";
define('PrecisionLossException', -5);
$error['EN'][PrecisionLossException] = "Significant precision loss detected.";
$error['FR'][PrecisionLossException] = "Perte significative de précision détectée.";
$error['DE'][PrecisionLossException] = "Bedeutender Präzision Verlust ermittelte.";
define('PRECISION_LOSS_EXCEPTION', -5);
$error['EN'][PRECISION_LOSS_EXCEPTION] = "Significant precision loss detected.";
$error['FR'][PRECISION_LOSS_EXCEPTION] = "Perte significative de précision détectée.";
$error['DE'][PRECISION_LOSS_EXCEPTION] = "Bedeutender Präzision Verlust ermittelte.";
define('MatrixSPDException', -6);
$error['EN'][MatrixSPDException] = "Can only perform operation on symmetric positive definite matrix.";
$error['FR'][MatrixSPDException] = "Perte significative de précision détectée.";
$error['DE'][MatrixSPDException] = "Bedeutender Präzision Verlust ermittelte.";
define('MATRIX_SPD_EXCEPTION', -6);
$error['EN'][MATRIX_SPD_EXCEPTION] = "Can only perform operation on symmetric positive definite matrix.";
$error['FR'][MATRIX_SPD_EXCEPTION] = "Perte significative de précision détectée.";
$error['DE'][MATRIX_SPD_EXCEPTION] = "Bedeutender Präzision Verlust ermittelte.";
define('MatrixSingularException', -7);
$error['EN'][MatrixSingularException] = "Can only perform operation on singular matrix.";
define('MATRIX_SINGULAR_EXCEPTION', -7);
$error['EN'][MATRIX_SINGULAR_EXCEPTION] = "Can only perform operation on singular matrix.";
define('MatrixRankException', -8);
$error['EN'][MatrixRankException] = "Can only perform operation on full-rank matrix.";
define('MATRIX_RANK_EXCEPTION', -8);
$error['EN'][MATRIX_RANK_EXCEPTION] = "Can only perform operation on full-rank matrix.";
define('ArrayLengthException', -9);
$error['EN'][ArrayLengthException] = "Array length must be a multiple of m.";
define('ARRAY_LENGTH_EXCEPTION', -9);
$error['EN'][ARRAY_LENGTH_EXCEPTION] = "Array length must be a multiple of m.";
define('RowLengthException', -10);
$error['EN'][RowLengthException] = "All rows must have the same length.";
define('ROW_LENGTH_EXCEPTION', -10);
$error['EN'][ROW_LENGTH_EXCEPTION] = "All rows must have the same length.";
/**
* Custom error handler
* @param int $num Error number
* Custom error handler
* @param int $num Error number
*/
function JAMAError($errorNumber = null) {
global $error;
function JAMAError($errorNumber = null)
{
global $error;
if (isset($errorNumber)) {
if (isset($error[JAMALANG][$errorNumber])) {
return $error[JAMALANG][$errorNumber];
} else {
return $error['EN'][$errorNumber];
}
} else {
return ("Invalid argument to JAMAError()");
}
if (isset($errorNumber)) {
if (isset($error[JAMALANG][$errorNumber])) {
return $error[JAMALANG][$errorNumber];
} else {
return $error['EN'][$errorNumber];
}
} else {
return ("Invalid argument to JAMAError()");
}
}

View File

@@ -1,43 +1,44 @@
<?php
/**
* @package JAMA
* @package JAMA
*
* Pythagorean Theorem:
* Pythagorean Theorem:
*
* a = 3
* b = 4
* r = sqrt(square(a) + square(b))
* r = 5
* a = 3
* b = 4
* r = sqrt(square(a) + square(b))
* r = 5
*
* r = sqrt(a^2 + b^2) without under/overflow.
* r = sqrt(a^2 + b^2) without under/overflow.
*/
function hypo($a, $b) {
if (abs($a) > abs($b)) {
$r = $b / $a;
$r = abs($a) * sqrt(1 + $r * $r);
} elseif ($b != 0) {
$r = $a / $b;
$r = abs($b) * sqrt(1 + $r * $r);
} else {
$r = 0.0;
}
return $r;
} // function hypo()
function hypo($a, $b)
{
if (abs($a) > abs($b)) {
$r = $b / $a;
$r = abs($a) * sqrt(1 + $r * $r);
} elseif ($b != 0) {
$r = $a / $b;
$r = abs($b) * sqrt(1 + $r * $r);
} else {
$r = 0.0;
}
return $r;
} // function hypo()
/**
* Mike Bommarito's version.
* Compute n-dimensional hyotheneuse.
* Mike Bommarito's version.
* Compute n-dimensional hyotheneuse.
*
function hypot() {
$s = 0;
foreach (func_get_args() as $d) {
if (is_numeric($d)) {
$s += pow($d, 2);
} else {
throw new PHPExcel_Calculation_Exception(JAMAError(ArgumentTypeException));
}
}
return sqrt($s);
$s = 0;
foreach (func_get_args() as $d) {
if (is_numeric($d)) {
$s += pow($d, 2);
} else {
throw new PHPExcel_Calculation_Exception(JAMAError(ARGUMENT_TYPE_EXCEPTION));
}
}
return sqrt($s);
}
*/

View File

@@ -37,495 +37,490 @@ $GLOBALS['_OLE_INSTANCES'] = array();
*/
class PHPExcel_Shared_OLE
{
const OLE_PPS_TYPE_ROOT = 5;
const OLE_PPS_TYPE_DIR = 1;
const OLE_PPS_TYPE_FILE = 2;
const OLE_DATA_SIZE_SMALL = 0x1000;
const OLE_LONG_INT_SIZE = 4;
const OLE_PPS_SIZE = 0x80;
const OLE_PPS_TYPE_ROOT = 5;
const OLE_PPS_TYPE_DIR = 1;
const OLE_PPS_TYPE_FILE = 2;
const OLE_DATA_SIZE_SMALL = 0x1000;
const OLE_LONG_INT_SIZE = 4;
const OLE_PPS_SIZE = 0x80;
/**
* The file handle for reading an OLE container
* @var resource
*/
public $_file_handle;
/**
* The file handle for reading an OLE container
* @var resource
*/
public $_file_handle;
/**
* Array of PPS's found on the OLE container
* @var array
*/
public $_list = array();
/**
* Array of PPS's found on the OLE container
* @var array
*/
public $_list = array();
/**
* Root directory of OLE container
* @var OLE_PPS_Root
*/
public $root;
/**
* Root directory of OLE container
* @var OLE_PPS_Root
*/
public $root;
/**
* Big Block Allocation Table
* @var array (blockId => nextBlockId)
*/
public $bbat;
/**
* Big Block Allocation Table
* @var array (blockId => nextBlockId)
*/
public $bbat;
/**
* Short Block Allocation Table
* @var array (blockId => nextBlockId)
*/
public $sbat;
/**
* Short Block Allocation Table
* @var array (blockId => nextBlockId)
*/
public $sbat;
/**
* Size of big blocks. This is usually 512.
* @var int number of octets per block.
*/
public $bigBlockSize;
/**
* Size of big blocks. This is usually 512.
* @var int number of octets per block.
*/
public $bigBlockSize;
/**
* Size of small blocks. This is usually 64.
* @var int number of octets per block
*/
public $smallBlockSize;
/**
* Size of small blocks. This is usually 64.
* @var int number of octets per block
*/
public $smallBlockSize;
/**
* Reads an OLE container from the contents of the file given.
*
* @acces public
* @param string $file
* @return mixed true on success, PEAR_Error on failure
*/
public function read($file)
{
$fh = fopen($file, "r");
if (!$fh) {
throw new PHPExcel_Reader_Exception("Can't open file $file");
}
$this->_file_handle = $fh;
/**
* Reads an OLE container from the contents of the file given.
*
* @acces public
* @param string $file
* @return mixed true on success, PEAR_Error on failure
*/
public function read($file)
{
$fh = fopen($file, "r");
if (!$fh) {
throw new PHPExcel_Reader_Exception("Can't open file $file");
}
$this->_file_handle = $fh;
$signature = fread($fh, 8);
if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) {
throw new PHPExcel_Reader_Exception("File doesn't seem to be an OLE container.");
}
fseek($fh, 28);
if (fread($fh, 2) != "\xFE\xFF") {
// This shouldn't be a problem in practice
throw new PHPExcel_Reader_Exception("Only Little-Endian encoding is supported.");
}
// Size of blocks and short blocks in bytes
$this->bigBlockSize = pow(2, self::_readInt2($fh));
$this->smallBlockSize = pow(2, self::_readInt2($fh));
$signature = fread($fh, 8);
if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) {
throw new PHPExcel_Reader_Exception("File doesn't seem to be an OLE container.");
}
fseek($fh, 28);
if (fread($fh, 2) != "\xFE\xFF") {
// This shouldn't be a problem in practice
throw new PHPExcel_Reader_Exception("Only Little-Endian encoding is supported.");
}
// Size of blocks and short blocks in bytes
$this->bigBlockSize = pow(2, self::_readInt2($fh));
$this->smallBlockSize = pow(2, self::_readInt2($fh));
// Skip UID, revision number and version number
fseek($fh, 44);
// Number of blocks in Big Block Allocation Table
$bbatBlockCount = self::_readInt4($fh);
// Skip UID, revision number and version number
fseek($fh, 44);
// Number of blocks in Big Block Allocation Table
$bbatBlockCount = self::_readInt4($fh);
// Root chain 1st block
$directoryFirstBlockId = self::_readInt4($fh);
// Root chain 1st block
$directoryFirstBlockId = self::_readInt4($fh);
// Skip unused bytes
fseek($fh, 56);
// Streams shorter than this are stored using small blocks
$this->bigBlockThreshold = self::_readInt4($fh);
// Block id of first sector in Short Block Allocation Table
$sbatFirstBlockId = self::_readInt4($fh);
// Number of blocks in Short Block Allocation Table
$sbbatBlockCount = self::_readInt4($fh);
// Block id of first sector in Master Block Allocation Table
$mbatFirstBlockId = self::_readInt4($fh);
// Number of blocks in Master Block Allocation Table
$mbbatBlockCount = self::_readInt4($fh);
$this->bbat = array();
// Skip unused bytes
fseek($fh, 56);
// Streams shorter than this are stored using small blocks
$this->bigBlockThreshold = self::_readInt4($fh);
// Block id of first sector in Short Block Allocation Table
$sbatFirstBlockId = self::_readInt4($fh);
// Number of blocks in Short Block Allocation Table
$sbbatBlockCount = self::_readInt4($fh);
// Block id of first sector in Master Block Allocation Table
$mbatFirstBlockId = self::_readInt4($fh);
// Number of blocks in Master Block Allocation Table
$mbbatBlockCount = self::_readInt4($fh);
$this->bbat = array();
// Remaining 4 * 109 bytes of current block is beginning of Master
// Block Allocation Table
$mbatBlocks = array();
for ($i = 0; $i < 109; ++$i) {
$mbatBlocks[] = self::_readInt4($fh);
}
// Remaining 4 * 109 bytes of current block is beginning of Master
// Block Allocation Table
$mbatBlocks = array();
for ($i = 0; $i < 109; ++$i) {
$mbatBlocks[] = self::_readInt4($fh);
}
// Read rest of Master Block Allocation Table (if any is left)
$pos = $this->_getBlockOffset($mbatFirstBlockId);
for ($i = 0; $i < $mbbatBlockCount; ++$i) {
fseek($fh, $pos);
for ($j = 0; $j < $this->bigBlockSize / 4 - 1; ++$j) {
$mbatBlocks[] = self::_readInt4($fh);
}
// Last block id in each block points to next block
$pos = $this->_getBlockOffset(self::_readInt4($fh));
}
// Read rest of Master Block Allocation Table (if any is left)
$pos = $this->_getBlockOffset($mbatFirstBlockId);
for ($i = 0; $i < $mbbatBlockCount; ++$i) {
fseek($fh, $pos);
for ($j = 0; $j < $this->bigBlockSize / 4 - 1; ++$j) {
$mbatBlocks[] = self::_readInt4($fh);
}
// Last block id in each block points to next block
$pos = $this->_getBlockOffset(self::_readInt4($fh));
}
// Read Big Block Allocation Table according to chain specified by
// $mbatBlocks
for ($i = 0; $i < $bbatBlockCount; ++$i) {
$pos = $this->_getBlockOffset($mbatBlocks[$i]);
fseek($fh, $pos);
for ($j = 0 ; $j < $this->bigBlockSize / 4; ++$j) {
$this->bbat[] = self::_readInt4($fh);
}
}
// Read Big Block Allocation Table according to chain specified by
// $mbatBlocks
for ($i = 0; $i < $bbatBlockCount; ++$i) {
$pos = $this->_getBlockOffset($mbatBlocks[$i]);
fseek($fh, $pos);
for ($j = 0; $j < $this->bigBlockSize / 4; ++$j) {
$this->bbat[] = self::_readInt4($fh);
}
}
// Read short block allocation table (SBAT)
$this->sbat = array();
$shortBlockCount = $sbbatBlockCount * $this->bigBlockSize / 4;
$sbatFh = $this->getStream($sbatFirstBlockId);
for ($blockId = 0; $blockId < $shortBlockCount; ++$blockId) {
$this->sbat[$blockId] = self::_readInt4($sbatFh);
}
fclose($sbatFh);
// Read short block allocation table (SBAT)
$this->sbat = array();
$shortBlockCount = $sbbatBlockCount * $this->bigBlockSize / 4;
$sbatFh = $this->getStream($sbatFirstBlockId);
for ($blockId = 0; $blockId < $shortBlockCount; ++$blockId) {
$this->sbat[$blockId] = self::_readInt4($sbatFh);
}
fclose($sbatFh);
$this->_readPpsWks($directoryFirstBlockId);
$this->_readPpsWks($directoryFirstBlockId);
return true;
}
return true;
}
/**
* @param int block id
* @param int byte offset from beginning of file
* @access public
*/
public function _getBlockOffset($blockId)
{
return 512 + $blockId * $this->bigBlockSize;
}
/**
* @param int block id
* @param int byte offset from beginning of file
* @access public
*/
public function _getBlockOffset($blockId)
{
return 512 + $blockId * $this->bigBlockSize;
}
/**
* Returns a stream for use with fread() etc. External callers should
* use PHPExcel_Shared_OLE_PPS_File::getStream().
* @param int|PPS block id or PPS
* @return resource read-only stream
*/
public function getStream($blockIdOrPps)
{
static $isRegistered = false;
if (!$isRegistered) {
stream_wrapper_register('ole-chainedblockstream',
'PHPExcel_Shared_OLE_ChainedBlockStream');
$isRegistered = true;
}
/**
* Returns a stream for use with fread() etc. External callers should
* use PHPExcel_Shared_OLE_PPS_File::getStream().
* @param int|PPS block id or PPS
* @return resource read-only stream
*/
public function getStream($blockIdOrPps)
{
static $isRegistered = false;
if (!$isRegistered) {
stream_wrapper_register('ole-chainedblockstream', 'PHPExcel_Shared_OLE_ChainedBlockStream');
$isRegistered = true;
}
// Store current instance in global array, so that it can be accessed
// in OLE_ChainedBlockStream::stream_open().
// Object is removed from self::$instances in OLE_Stream::close().
$GLOBALS['_OLE_INSTANCES'][] = $this;
$instanceId = end(array_keys($GLOBALS['_OLE_INSTANCES']));
// Store current instance in global array, so that it can be accessed
// in OLE_ChainedBlockStream::stream_open().
// Object is removed from self::$instances in OLE_Stream::close().
$GLOBALS['_OLE_INSTANCES'][] = $this;
$instanceId = end(array_keys($GLOBALS['_OLE_INSTANCES']));
$path = 'ole-chainedblockstream://oleInstanceId=' . $instanceId;
if ($blockIdOrPps instanceof PHPExcel_Shared_OLE_PPS) {
$path .= '&blockId=' . $blockIdOrPps->_StartBlock;
$path .= '&size=' . $blockIdOrPps->Size;
} else {
$path .= '&blockId=' . $blockIdOrPps;
}
return fopen($path, 'r');
}
$path = 'ole-chainedblockstream://oleInstanceId=' . $instanceId;
if ($blockIdOrPps instanceof PHPExcel_Shared_OLE_PPS) {
$path .= '&blockId=' . $blockIdOrPps->_StartBlock;
$path .= '&size=' . $blockIdOrPps->Size;
} else {
$path .= '&blockId=' . $blockIdOrPps;
}
return fopen($path, 'r');
}
/**
* Reads a signed char.
* @param resource file handle
* @return int
* @access public
*/
private static function _readInt1($fh)
{
list(, $tmp) = unpack("c", fread($fh, 1));
return $tmp;
}
/**
* Reads a signed char.
* @param resource file handle
* @return int
* @access public
*/
private static function _readInt1($fh)
{
list(, $tmp) = unpack("c", fread($fh, 1));
return $tmp;
}
/**
* Reads an unsigned short (2 octets).
* @param resource file handle
* @return int
* @access public
*/
private static function _readInt2($fh)
{
list(, $tmp) = unpack("v", fread($fh, 2));
return $tmp;
}
/**
* Reads an unsigned short (2 octets).
* @param resource file handle
* @return int
* @access public
*/
private static function _readInt2($fh)
{
list(, $tmp) = unpack("v", fread($fh, 2));
return $tmp;
}
/**
* Reads an unsigned long (4 octets).
* @param resource file handle
* @return int
* @access public
*/
private static function _readInt4($fh)
{
list(, $tmp) = unpack("V", fread($fh, 4));
return $tmp;
}
/**
* Reads an unsigned long (4 octets).
* @param resource file handle
* @return int
* @access public
*/
private static function _readInt4($fh)
{
list(, $tmp) = unpack("V", fread($fh, 4));
return $tmp;
}
/**
* Gets information about all PPS's on the OLE container from the PPS WK's
* creates an OLE_PPS object for each one.
*
* @access public
* @param integer the block id of the first block
* @return mixed true on success, PEAR_Error on failure
*/
public function _readPpsWks($blockId)
{
$fh = $this->getStream($blockId);
for ($pos = 0; ; $pos += 128) {
fseek($fh, $pos, SEEK_SET);
$nameUtf16 = fread($fh, 64);
$nameLength = self::_readInt2($fh);
$nameUtf16 = substr($nameUtf16, 0, $nameLength - 2);
// Simple conversion from UTF-16LE to ISO-8859-1
$name = str_replace("\x00", "", $nameUtf16);
$type = self::_readInt1($fh);
switch ($type) {
case self::OLE_PPS_TYPE_ROOT:
$pps = new PHPExcel_Shared_OLE_PPS_Root(null, null, array());
$this->root = $pps;
break;
case self::OLE_PPS_TYPE_DIR:
$pps = new PHPExcel_Shared_OLE_PPS(null, null, null, null, null,
null, null, null, null, array());
break;
case self::OLE_PPS_TYPE_FILE:
$pps = new PHPExcel_Shared_OLE_PPS_File($name);
break;
default:
continue;
}
fseek($fh, 1, SEEK_CUR);
$pps->Type = $type;
$pps->Name = $name;
$pps->PrevPps = self::_readInt4($fh);
$pps->NextPps = self::_readInt4($fh);
$pps->DirPps = self::_readInt4($fh);
fseek($fh, 20, SEEK_CUR);
$pps->Time1st = self::OLE2LocalDate(fread($fh, 8));
$pps->Time2nd = self::OLE2LocalDate(fread($fh, 8));
$pps->_StartBlock = self::_readInt4($fh);
$pps->Size = self::_readInt4($fh);
$pps->No = count($this->_list);
$this->_list[] = $pps;
/**
* Gets information about all PPS's on the OLE container from the PPS WK's
* creates an OLE_PPS object for each one.
*
* @access public
* @param integer the block id of the first block
* @return mixed true on success, PEAR_Error on failure
*/
public function _readPpsWks($blockId)
{
$fh = $this->getStream($blockId);
for ($pos = 0;; $pos += 128) {
fseek($fh, $pos, SEEK_SET);
$nameUtf16 = fread($fh, 64);
$nameLength = self::_readInt2($fh);
$nameUtf16 = substr($nameUtf16, 0, $nameLength - 2);
// Simple conversion from UTF-16LE to ISO-8859-1
$name = str_replace("\x00", "", $nameUtf16);
$type = self::_readInt1($fh);
switch ($type) {
case self::OLE_PPS_TYPE_ROOT:
$pps = new PHPExcel_Shared_OLE_PPS_Root(null, null, array());
$this->root = $pps;
break;
case self::OLE_PPS_TYPE_DIR:
$pps = new PHPExcel_Shared_OLE_PPS(null, null, null, null, null, null, null, null, null, array());
break;
case self::OLE_PPS_TYPE_FILE:
$pps = new PHPExcel_Shared_OLE_PPS_File($name);
break;
default:
continue;
}
fseek($fh, 1, SEEK_CUR);
$pps->Type = $type;
$pps->Name = $name;
$pps->PrevPps = self::_readInt4($fh);
$pps->NextPps = self::_readInt4($fh);
$pps->DirPps = self::_readInt4($fh);
fseek($fh, 20, SEEK_CUR);
$pps->Time1st = self::OLE2LocalDate(fread($fh, 8));
$pps->Time2nd = self::OLE2LocalDate(fread($fh, 8));
$pps->_StartBlock = self::_readInt4($fh);
$pps->Size = self::_readInt4($fh);
$pps->No = count($this->_list);
$this->_list[] = $pps;
// check if the PPS tree (starting from root) is complete
if (isset($this->root) &&
$this->_ppsTreeComplete($this->root->No)) {
// check if the PPS tree (starting from root) is complete
if (isset($this->root) && $this->_ppsTreeComplete($this->root->No)) {
break;
}
}
fclose($fh);
break;
}
}
fclose($fh);
// Initialize $pps->children on directories
foreach ($this->_list as $pps) {
if ($pps->Type == self::OLE_PPS_TYPE_DIR || $pps->Type == self::OLE_PPS_TYPE_ROOT) {
$nos = array($pps->DirPps);
$pps->children = array();
while ($nos) {
$no = array_pop($nos);
if ($no != -1) {
$childPps = $this->_list[$no];
$nos[] = $childPps->PrevPps;
$nos[] = $childPps->NextPps;
$pps->children[] = $childPps;
}
}
}
}
// Initialize $pps->children on directories
foreach ($this->_list as $pps) {
if ($pps->Type == self::OLE_PPS_TYPE_DIR || $pps->Type == self::OLE_PPS_TYPE_ROOT) {
$nos = array($pps->DirPps);
$pps->children = array();
while ($nos) {
$no = array_pop($nos);
if ($no != -1) {
$childPps = $this->_list[$no];
$nos[] = $childPps->PrevPps;
$nos[] = $childPps->NextPps;
$pps->children[] = $childPps;
}
}
}
}
return true;
}
return true;
}
/**
* It checks whether the PPS tree is complete (all PPS's read)
* starting with the given PPS (not necessarily root)
*
* @access public
* @param integer $index The index of the PPS from which we are checking
* @return boolean Whether the PPS tree for the given PPS is complete
*/
public function _ppsTreeComplete($index)
{
return isset($this->_list[$index]) &&
($pps = $this->_list[$index]) &&
($pps->PrevPps == -1 ||
$this->_ppsTreeComplete($pps->PrevPps)) &&
($pps->NextPps == -1 ||
$this->_ppsTreeComplete($pps->NextPps)) &&
($pps->DirPps == -1 ||
$this->_ppsTreeComplete($pps->DirPps));
}
/**
* It checks whether the PPS tree is complete (all PPS's read)
* starting with the given PPS (not necessarily root)
*
* @access public
* @param integer $index The index of the PPS from which we are checking
* @return boolean Whether the PPS tree for the given PPS is complete
*/
public function _ppsTreeComplete($index)
{
return isset($this->_list[$index]) &&
($pps = $this->_list[$index]) &&
($pps->PrevPps == -1 ||
$this->_ppsTreeComplete($pps->PrevPps)) &&
($pps->NextPps == -1 ||
$this->_ppsTreeComplete($pps->NextPps)) &&
($pps->DirPps == -1 ||
$this->_ppsTreeComplete($pps->DirPps));
}
/**
* Checks whether a PPS is a File PPS or not.
* If there is no PPS for the index given, it will return false.
*
* @access public
* @param integer $index The index for the PPS
* @return bool true if it's a File PPS, false otherwise
*/
public function isFile($index)
{
if (isset($this->_list[$index])) {
return ($this->_list[$index]->Type == self::OLE_PPS_TYPE_FILE);
}
return false;
}
/**
* Checks whether a PPS is a File PPS or not.
* If there is no PPS for the index given, it will return false.
*
* @access public
* @param integer $index The index for the PPS
* @return bool true if it's a File PPS, false otherwise
*/
public function isFile($index)
{
if (isset($this->_list[$index])) {
return ($this->_list[$index]->Type == self::OLE_PPS_TYPE_FILE);
}
return false;
}
/**
* Checks whether a PPS is a Root PPS or not.
* If there is no PPS for the index given, it will return false.
*
* @access public
* @param integer $index The index for the PPS.
* @return bool true if it's a Root PPS, false otherwise
*/
public function isRoot($index)
{
if (isset($this->_list[$index])) {
return ($this->_list[$index]->Type == self::OLE_PPS_TYPE_ROOT);
}
return false;
}
/**
* Checks whether a PPS is a Root PPS or not.
* If there is no PPS for the index given, it will return false.
*
* @access public
* @param integer $index The index for the PPS.
* @return bool true if it's a Root PPS, false otherwise
*/
public function isRoot($index)
{
if (isset($this->_list[$index])) {
return ($this->_list[$index]->Type == self::OLE_PPS_TYPE_ROOT);
}
return false;
}
/**
* Gives the total number of PPS's found in the OLE container.
*
* @access public
* @return integer The total number of PPS's found in the OLE container
*/
public function ppsTotal()
{
return count($this->_list);
}
/**
* Gives the total number of PPS's found in the OLE container.
*
* @access public
* @return integer The total number of PPS's found in the OLE container
*/
public function ppsTotal()
{
return count($this->_list);
}
/**
* Gets data from a PPS
* If there is no PPS for the index given, it will return an empty string.
*
* @access public
* @param integer $index The index for the PPS
* @param integer $position The position from which to start reading
* (relative to the PPS)
* @param integer $length The amount of bytes to read (at most)
* @return string The binary string containing the data requested
* @see OLE_PPS_File::getStream()
*/
public function getData($index, $position, $length)
{
// if position is not valid return empty string
if (!isset($this->_list[$index]) || ($position >= $this->_list[$index]->Size) || ($position < 0)) {
return '';
}
$fh = $this->getStream($this->_list[$index]);
$data = stream_get_contents($fh, $length, $position);
fclose($fh);
return $data;
}
/**
* Gets data from a PPS
* If there is no PPS for the index given, it will return an empty string.
*
* @access public
* @param integer $index The index for the PPS
* @param integer $position The position from which to start reading
* (relative to the PPS)
* @param integer $length The amount of bytes to read (at most)
* @return string The binary string containing the data requested
* @see OLE_PPS_File::getStream()
*/
public function getData($index, $position, $length)
{
// if position is not valid return empty string
if (!isset($this->_list[$index]) || ($position >= $this->_list[$index]->Size) || ($position < 0)) {
return '';
}
$fh = $this->getStream($this->_list[$index]);
$data = stream_get_contents($fh, $length, $position);
fclose($fh);
return $data;
}
/**
* Gets the data length from a PPS
* If there is no PPS for the index given, it will return 0.
*
* @access public
* @param integer $index The index for the PPS
* @return integer The amount of bytes in data the PPS has
*/
public function getDataLength($index)
{
if (isset($this->_list[$index])) {
return $this->_list[$index]->Size;
}
return 0;
}
/**
* Gets the data length from a PPS
* If there is no PPS for the index given, it will return 0.
*
* @access public
* @param integer $index The index for the PPS
* @return integer The amount of bytes in data the PPS has
*/
public function getDataLength($index)
{
if (isset($this->_list[$index])) {
return $this->_list[$index]->Size;
}
return 0;
}
/**
* Utility function to transform ASCII text to Unicode
*
* @access public
* @static
* @param string $ascii The ASCII string to transform
* @return string The string in Unicode
*/
public static function Asc2Ucs($ascii)
{
$rawname = '';
for ($i = 0; $i < strlen($ascii); ++$i) {
$rawname .= $ascii{$i} . "\x00";
}
return $rawname;
}
/**
* Utility function to transform ASCII text to Unicode
*
* @access public
* @static
* @param string $ascii The ASCII string to transform
* @return string The string in Unicode
*/
public static function Asc2Ucs($ascii)
{
$rawname = '';
for ($i = 0; $i < strlen($ascii); ++$i) {
$rawname .= $ascii{$i} . "\x00";
}
return $rawname;
}
/**
* Utility function
* Returns a string for the OLE container with the date given
*
* @access public
* @static
* @param integer $date A timestamp
* @return string The string for the OLE container
*/
public static function LocalDate2OLE($date = null)
{
if (!isset($date)) {
return "\x00\x00\x00\x00\x00\x00\x00\x00";
}
/**
* Utility function
* Returns a string for the OLE container with the date given
*
* @access public
* @static
* @param integer $date A timestamp
* @return string The string for the OLE container
*/
public static function LocalDate2OLE($date = null)
{
if (!isset($date)) {
return "\x00\x00\x00\x00\x00\x00\x00\x00";
}
// factor used for separating numbers into 4 bytes parts
$factor = pow(2, 32);
// factor used for separating numbers into 4 bytes parts
$factor = pow(2, 32);
// days from 1-1-1601 until the beggining of UNIX era
$days = 134774;
// calculate seconds
$big_date = $days*24*3600 + gmmktime(date("H", $date), date("i", $date), date("s", $date), date("m", $date), date("d", $date), date("Y", $date));
// multiply just to make MS happy
$big_date *= 10000000;
// days from 1-1-1601 until the beggining of UNIX era
$days = 134774;
// calculate seconds
$big_date = $days*24*3600 + gmmktime(date("H",$date),date("i",$date),date("s",$date),
date("m",$date),date("d",$date),date("Y",$date));
// multiply just to make MS happy
$big_date *= 10000000;
$high_part = floor($big_date / $factor);
// lower 4 bytes
$low_part = floor((($big_date / $factor) - $high_part) * $factor);
$high_part = floor($big_date / $factor);
// lower 4 bytes
$low_part = floor((($big_date / $factor) - $high_part) * $factor);
// Make HEX string
$res = '';
// Make HEX string
$res = '';
for ($i = 0; $i < 4; ++$i) {
$hex = $low_part % 0x100;
$res .= pack('c', $hex);
$low_part /= 0x100;
}
for ($i = 0; $i < 4; ++$i) {
$hex = $high_part % 0x100;
$res .= pack('c', $hex);
$high_part /= 0x100;
}
return $res;
}
for ($i = 0; $i < 4; ++$i) {
$hex = $low_part % 0x100;
$res .= pack('c', $hex);
$low_part /= 0x100;
}
for ($i = 0; $i < 4; ++$i) {
$hex = $high_part % 0x100;
$res .= pack('c', $hex);
$high_part /= 0x100;
}
return $res;
}
/**
* Returns a timestamp from an OLE container's date
*
* @access public
* @static
* @param integer $string A binary string with the encoded date
* @return string The timestamp corresponding to the string
*/
public static function OLE2LocalDate($string)
{
if (strlen($string) != 8) {
return new PEAR_Error("Expecting 8 byte string");
}
/**
* Returns a timestamp from an OLE container's date
*
* @access public
* @static
* @param integer $string A binary string with the encoded date
* @return string The timestamp corresponding to the string
*/
public static function OLE2LocalDate($string)
{
if (strlen($string) != 8) {
return new PEAR_Error("Expecting 8 byte string");
}
// factor used for separating numbers into 4 bytes parts
$factor = pow(2, 32);
list(, $high_part) = unpack('V', substr($string, 4, 4));
list(, $low_part) = unpack('V', substr($string, 0, 4));
// factor used for separating numbers into 4 bytes parts
$factor = pow(2,32);
list(, $high_part) = unpack('V', substr($string, 4, 4));
list(, $low_part) = unpack('V', substr($string, 0, 4));
$big_date = ($high_part * $factor) + $low_part;
// translate to seconds
$big_date /= 10000000;
$big_date = ($high_part * $factor) + $low_part;
// translate to seconds
$big_date /= 10000000;
// days from 1-1-1601 until the beggining of UNIX era
$days = 134774;
// days from 1-1-1601 until the beggining of UNIX era
$days = 134774;
// translate to seconds from beggining of UNIX era
$big_date -= $days * 24 * 3600;
return floor($big_date);
}
// translate to seconds from beggining of UNIX era
$big_date -= $days * 24 * 3600;
return floor($big_date);
}
}

View File

@@ -1,8 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_OLE_ChainedBlockStream
*
* Copyright (C) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -21,202 +22,185 @@
* @category PHPExcel
* @package PHPExcel_Shared_OLE
* @copyright Copyright (c) 2006 - 2007 Christian Schmidt
* @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_OLE_ChainedBlockStream
*
* Stream wrapper for reading data stored in an OLE file. Implements methods
* for PHP's stream_wrapper_register(). For creating streams using this
* wrapper, use PHPExcel_Shared_OLE_PPS_File::getStream().
*
* @category PHPExcel
* @package PHPExcel_Shared_OLE
*/
class PHPExcel_Shared_OLE_ChainedBlockStream
{
/**
* The OLE container of the file that is being read.
* @var OLE
*/
public $ole;
/**
* The OLE container of the file that is being read.
* @var OLE
*/
public $ole;
/**
* Parameters specified by fopen().
* @var array
*/
public $params;
/**
* Parameters specified by fopen().
* @var array
*/
public $params;
/**
* The binary data of the file.
* @var string
*/
public $data;
/**
* The binary data of the file.
* @var string
*/
public $data;
/**
* The file pointer.
* @var int byte offset
*/
public $pos;
/**
* The file pointer.
* @var int byte offset
*/
public $pos;
/**
* Implements support for fopen().
* For creating streams using this wrapper, use OLE_PPS_File::getStream().
*
* @param string $path resource name including scheme, e.g.
* ole-chainedblockstream://oleInstanceId=1
* @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, &$openedPath)
{
if ($mode != 'r') {
if ($options & STREAM_REPORT_ERRORS) {
trigger_error('Only reading is supported', E_USER_WARNING);
}
return false;
}
/**
* Implements support for fopen().
* For creating streams using this wrapper, use OLE_PPS_File::getStream().
*
* @param string $path resource name including scheme, e.g.
* ole-chainedblockstream://oleInstanceId=1
* @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, &$openedPath)
{
if ($mode != 'r') {
if ($options & STREAM_REPORT_ERRORS) {
trigger_error('Only reading is supported', E_USER_WARNING);
}
return false;
}
// 25 is length of "ole-chainedblockstream://"
parse_str(substr($path, 25), $this->params);
if (!isset($this->params['oleInstanceId'],
$this->params['blockId'],
$GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']])) {
// 25 is length of "ole-chainedblockstream://"
parse_str(substr($path, 25), $this->params);
if (!isset($this->params['oleInstanceId'], $this->params['blockId'], $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']])) {
if ($options & STREAM_REPORT_ERRORS) {
trigger_error('OLE stream not found', E_USER_WARNING);
}
return false;
}
$this->ole = $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']];
if ($options & STREAM_REPORT_ERRORS) {
trigger_error('OLE stream not found', E_USER_WARNING);
}
return false;
}
$this->ole = $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']];
$blockId = $this->params['blockId'];
$this->data = '';
if (isset($this->params['size']) && $this->params['size'] < $this->ole->bigBlockThreshold && $blockId != $this->ole->root->_StartBlock) {
// Block id refers to small blocks
$rootPos = $this->ole->_getBlockOffset($this->ole->root->_StartBlock);
while ($blockId != -2) {
$pos = $rootPos + $blockId * $this->ole->bigBlockSize;
$blockId = $this->ole->sbat[$blockId];
fseek($this->ole->_file_handle, $pos);
$this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize);
}
} else {
// Block id refers to big blocks
while ($blockId != -2) {
$pos = $this->ole->_getBlockOffset($blockId);
fseek($this->ole->_file_handle, $pos);
$this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize);
$blockId = $this->ole->bbat[$blockId];
}
}
if (isset($this->params['size'])) {
$this->data = substr($this->data, 0, $this->params['size']);
}
$blockId = $this->params['blockId'];
$this->data = '';
if (isset($this->params['size']) &&
$this->params['size'] < $this->ole->bigBlockThreshold &&
$blockId != $this->ole->root->_StartBlock) {
if ($options & STREAM_USE_PATH) {
$openedPath = $path;
}
// Block id refers to small blocks
$rootPos = $this->ole->_getBlockOffset($this->ole->root->_StartBlock);
while ($blockId != -2) {
$pos = $rootPos + $blockId * $this->ole->bigBlockSize;
$blockId = $this->ole->sbat[$blockId];
fseek($this->ole->_file_handle, $pos);
$this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize);
}
} else {
// Block id refers to big blocks
while ($blockId != -2) {
$pos = $this->ole->_getBlockOffset($blockId);
fseek($this->ole->_file_handle, $pos);
$this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize);
$blockId = $this->ole->bbat[$blockId];
}
}
if (isset($this->params['size'])) {
$this->data = substr($this->data, 0, $this->params['size']);
}
return true;
}
if ($options & STREAM_USE_PATH) {
$openedPath = $path;
}
/**
* Implements support for fclose().
*
*/
public function stream_close()
{
$this->ole = null;
unset($GLOBALS['_OLE_INSTANCES']);
}
return true;
}
/**
* Implements support for fread(), fgets() etc.
*
* @param int $count maximum number of bytes to read
* @return string
*/
public function stream_read($count)
{
if ($this->stream_eof()) {
return false;
}
$s = substr($this->data, $this->pos, $count);
$this->pos += $count;
return $s;
}
/**
* Implements support for fclose().
*
*/
public function stream_close()
{
$this->ole = null;
unset($GLOBALS['_OLE_INSTANCES']);
}
/**
* Implements support for feof().
*
* @return bool TRUE if the file pointer is at EOF; otherwise FALSE
*/
public function stream_eof()
{
return $this->pos >= strlen($this->data);
}
/**
* Implements support for fread(), fgets() etc.
*
* @param int $count maximum number of bytes to read
* @return string
*/
public function stream_read($count)
{
if ($this->stream_eof()) {
return false;
}
$s = substr($this->data, $this->pos, $count);
$this->pos += $count;
return $s;
}
/**
* 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->pos;
}
/**
* Implements support for feof().
*
* @return bool TRUE if the file pointer is at EOF; otherwise FALSE
*/
public function stream_eof()
{
return $this->pos >= strlen($this->data);
}
/**
* Implements support for fseek().
*
* @param int $offset byte offset
* @param int $whence SEEK_SET, SEEK_CUR or SEEK_END
* @return bool
*/
public function stream_seek($offset, $whence)
{
if ($whence == SEEK_SET && $offset >= 0) {
$this->pos = $offset;
} elseif ($whence == SEEK_CUR && -$offset <= $this->pos) {
$this->pos += $offset;
} elseif ($whence == SEEK_END && -$offset <= sizeof($this->data)) {
$this->pos = strlen($this->data) + $offset;
} else {
return false;
}
return true;
}
/**
* 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->pos;
}
/**
* Implements support for fstat(). Currently the only supported field is
* "size".
* @return array
*/
public function stream_stat()
{
return array(
'size' => strlen($this->data),
);
}
/**
* Implements support for fseek().
*
* @param int $offset byte offset
* @param int $whence SEEK_SET, SEEK_CUR or SEEK_END
* @return bool
*/
public function stream_seek($offset, $whence)
{
if ($whence == SEEK_SET && $offset >= 0) {
$this->pos = $offset;
} elseif ($whence == SEEK_CUR && -$offset <= $this->pos) {
$this->pos += $offset;
} elseif ($whence == SEEK_END && -$offset <= sizeof($this->data)) {
$this->pos = strlen($this->data) + $offset;
} else {
return false;
}
return true;
}
/**
* Implements support for fstat(). Currently the only supported field is
* "size".
* @return array
*/
public function stream_stat()
{
return array(
'size' => strlen($this->data),
);
}
// Methods used by stream_wrapper_register() that are not implemented:
// bool stream_flush ( void )
// int stream_write ( string data )
// bool rename ( string path_from, string path_to )
// bool mkdir ( string path, int mode, int options )
// bool rmdir ( string path, int options )
// bool dir_opendir ( string path, int options )
// array url_stat ( string path, int flags )
// string dir_readdir ( void )
// bool dir_rewinddir ( void )
// bool dir_closedir ( void )
// Methods used by stream_wrapper_register() that are not implemented:
// bool stream_flush ( void )
// int stream_write ( string data )
// bool rename ( string path_from, string path_to )
// bool mkdir ( string path, int mode, int options )
// bool rmdir ( string path, int options )
// bool dir_opendir ( string path, int options )
// array url_stat ( string path, int flags )
// string dir_readdir ( void )
// bool dir_rewinddir ( void )
// bool dir_closedir ( void )
}

View File

@@ -29,202 +29,202 @@
*/
class PHPExcel_Shared_OLE_PPS
{
/**
* The PPS index
* @var integer
*/
public $No;
/**
* The PPS index
* @var integer
*/
public $No;
/**
* The PPS name (in Unicode)
* @var string
*/
public $Name;
/**
* The PPS name (in Unicode)
* @var string
*/
public $Name;
/**
* The PPS type. Dir, Root or File
* @var integer
*/
public $Type;
/**
* The PPS type. Dir, Root or File
* @var integer
*/
public $Type;
/**
* The index of the previous PPS
* @var integer
*/
public $PrevPps;
/**
* The index of the previous PPS
* @var integer
*/
public $PrevPps;
/**
* The index of the next PPS
* @var integer
*/
public $NextPps;
/**
* The index of the next PPS
* @var integer
*/
public $NextPps;
/**
* The index of it's first child if this is a Dir or Root PPS
* @var integer
*/
public $DirPps;
/**
* The index of it's first child if this is a Dir or Root PPS
* @var integer
*/
public $DirPps;
/**
* A timestamp
* @var integer
*/
public $Time1st;
/**
* A timestamp
* @var integer
*/
public $Time1st;
/**
* A timestamp
* @var integer
*/
public $Time2nd;
/**
* A timestamp
* @var integer
*/
public $Time2nd;
/**
* Starting block (small or big) for this PPS's data inside the container
* @var integer
*/
public $_StartBlock;
/**
* Starting block (small or big) for this PPS's data inside the container
* @var integer
*/
public $_StartBlock;
/**
* The size of the PPS's data (in bytes)
* @var integer
*/
public $Size;
/**
* The size of the PPS's data (in bytes)
* @var integer
*/
public $Size;
/**
* The PPS's data (only used if it's not using a temporary file)
* @var string
*/
public $_data;
/**
* The PPS's data (only used if it's not using a temporary file)
* @var string
*/
public $_data;
/**
* Array of child PPS's (only used by Root and Dir PPS's)
* @var array
*/
public $children = array();
/**
* Array of child PPS's (only used by Root and Dir PPS's)
* @var array
*/
public $children = array();
/**
* Pointer to OLE container
* @var OLE
*/
public $ole;
/**
* Pointer to OLE container
* @var OLE
*/
public $ole;
/**
* The constructor
*
* @access public
* @param integer $No The PPS index
* @param string $name The PPS name
* @param integer $type The PPS type. Dir, Root or File
* @param integer $prev The index of the previous PPS
* @param integer $next The index of the next PPS
* @param integer $dir The index of it's first child if this is a Dir or Root PPS
* @param integer $time_1st A timestamp
* @param integer $time_2nd A timestamp
* @param string $data The (usually binary) source data of the PPS
* @param array $children Array containing children PPS for this PPS
*/
public function __construct($No, $name, $type, $prev, $next, $dir, $time_1st, $time_2nd, $data, $children)
{
$this->No = $No;
$this->Name = $name;
$this->Type = $type;
$this->PrevPps = $prev;
$this->NextPps = $next;
$this->DirPps = $dir;
$this->Time1st = $time_1st;
$this->Time2nd = $time_2nd;
$this->_data = $data;
$this->children = $children;
if ($data != '') {
$this->Size = strlen($data);
} else {
$this->Size = 0;
}
}
/**
* The constructor
*
* @access public
* @param integer $No The PPS index
* @param string $name The PPS name
* @param integer $type The PPS type. Dir, Root or File
* @param integer $prev The index of the previous PPS
* @param integer $next The index of the next PPS
* @param integer $dir The index of it's first child if this is a Dir or Root PPS
* @param integer $time_1st A timestamp
* @param integer $time_2nd A timestamp
* @param string $data The (usually binary) source data of the PPS
* @param array $children Array containing children PPS for this PPS
*/
public function __construct($No, $name, $type, $prev, $next, $dir, $time_1st, $time_2nd, $data, $children)
{
$this->No = $No;
$this->Name = $name;
$this->Type = $type;
$this->PrevPps = $prev;
$this->NextPps = $next;
$this->DirPps = $dir;
$this->Time1st = $time_1st;
$this->Time2nd = $time_2nd;
$this->_data = $data;
$this->children = $children;
if ($data != '') {
$this->Size = strlen($data);
} else {
$this->Size = 0;
}
}
/**
* Returns the amount of data saved for this PPS
*
* @access public
* @return integer The amount of data (in bytes)
*/
public function _DataLen()
{
if (!isset($this->_data)) {
return 0;
}
//if (isset($this->_PPS_FILE)) {
// fseek($this->_PPS_FILE, 0);
// $stats = fstat($this->_PPS_FILE);
// return $stats[7];
//} else {
return strlen($this->_data);
//}
}
/**
* Returns the amount of data saved for this PPS
*
* @access public
* @return integer The amount of data (in bytes)
*/
public function _DataLen()
{
if (!isset($this->_data)) {
return 0;
}
//if (isset($this->_PPS_FILE)) {
// fseek($this->_PPS_FILE, 0);
// $stats = fstat($this->_PPS_FILE);
// return $stats[7];
//} else {
return strlen($this->_data);
//}
}
/**
* Returns a string with the PPS's WK (What is a WK?)
*
* @access public
* @return string The binary string
*/
public function _getPpsWk()
{
$ret = str_pad($this->Name,64,"\x00");
/**
* Returns a string with the PPS's WK (What is a WK?)
*
* @access public
* @return string The binary string
*/
public function _getPpsWk()
{
$ret = str_pad($this->Name, 64, "\x00");
$ret .= pack("v", strlen($this->Name) + 2) // 66
. pack("c", $this->Type) // 67
. pack("c", 0x00) //UK // 68
. pack("V", $this->PrevPps) //Prev // 72
. pack("V", $this->NextPps) //Next // 76
. pack("V", $this->DirPps) //Dir // 80
. "\x00\x09\x02\x00" // 84
. "\x00\x00\x00\x00" // 88
. "\xc0\x00\x00\x00" // 92
. "\x00\x00\x00\x46" // 96 // Seems to be ok only for Root
. "\x00\x00\x00\x00" // 100
. PHPExcel_Shared_OLE::LocalDate2OLE($this->Time1st) // 108
. PHPExcel_Shared_OLE::LocalDate2OLE($this->Time2nd) // 116
. pack("V", isset($this->_StartBlock)?
$this->_StartBlock:0) // 120
. pack("V", $this->Size) // 124
. pack("V", 0); // 128
return $ret;
}
$ret .= pack("v", strlen($this->Name) + 2) // 66
. pack("c", $this->Type) // 67
. pack("c", 0x00) //UK // 68
. pack("V", $this->PrevPps) //Prev // 72
. pack("V", $this->NextPps) //Next // 76
. pack("V", $this->DirPps) //Dir // 80
. "\x00\x09\x02\x00" // 84
. "\x00\x00\x00\x00" // 88
. "\xc0\x00\x00\x00" // 92
. "\x00\x00\x00\x46" // 96 // Seems to be ok only for Root
. "\x00\x00\x00\x00" // 100
. PHPExcel_Shared_OLE::LocalDate2OLE($this->Time1st) // 108
. PHPExcel_Shared_OLE::LocalDate2OLE($this->Time2nd) // 116
. pack("V", isset($this->_StartBlock)?
$this->_StartBlock:0) // 120
. pack("V", $this->Size) // 124
. pack("V", 0); // 128
return $ret;
}
/**
* Updates index and pointers to previous, next and children PPS's for this
* PPS. I don't think it'll work with Dir PPS's.
*
* @access public
* @param array &$raList Reference to the array of PPS's for the whole OLE
* container
* @return integer The index for this PPS
*/
public static function _savePpsSetPnt(&$raList, $to_save, $depth = 0)
{
if ( !is_array($to_save) || (empty($to_save)) ) {
return 0xFFFFFFFF;
} elseif( count($to_save) == 1 ) {
$cnt = count($raList);
// If the first entry, it's the root... Don't clone it!
$raList[$cnt] = ( $depth == 0 ) ? $to_save[0] : clone $to_save[0];
$raList[$cnt]->No = $cnt;
$raList[$cnt]->PrevPps = 0xFFFFFFFF;
$raList[$cnt]->NextPps = 0xFFFFFFFF;
$raList[$cnt]->DirPps = self::_savePpsSetPnt($raList, @$raList[$cnt]->children, $depth++);
} else {
$iPos = floor(count($to_save) / 2);
$aPrev = array_slice($to_save, 0, $iPos);
$aNext = array_slice($to_save, $iPos + 1);
$cnt = count($raList);
// If the first entry, it's the root... Don't clone it!
$raList[$cnt] = ( $depth == 0 ) ? $to_save[$iPos] : clone $to_save[$iPos];
$raList[$cnt]->No = $cnt;
$raList[$cnt]->PrevPps = self::_savePpsSetPnt($raList, $aPrev, $depth++);
$raList[$cnt]->NextPps = self::_savePpsSetPnt($raList, $aNext, $depth++);
$raList[$cnt]->DirPps = self::_savePpsSetPnt($raList, @$raList[$cnt]->children, $depth++);
/**
* Updates index and pointers to previous, next and children PPS's for this
* PPS. I don't think it'll work with Dir PPS's.
*
* @access public
* @param array &$raList Reference to the array of PPS's for the whole OLE
* container
* @return integer The index for this PPS
*/
public static function _savePpsSetPnt(&$raList, $to_save, $depth = 0)
{
if (!is_array($to_save) || (empty($to_save))) {
return 0xFFFFFFFF;
} elseif (count($to_save) == 1) {
$cnt = count($raList);
// If the first entry, it's the root... Don't clone it!
$raList[$cnt] = ( $depth == 0 ) ? $to_save[0] : clone $to_save[0];
$raList[$cnt]->No = $cnt;
$raList[$cnt]->PrevPps = 0xFFFFFFFF;
$raList[$cnt]->NextPps = 0xFFFFFFFF;
$raList[$cnt]->DirPps = self::_savePpsSetPnt($raList, @$raList[$cnt]->children, $depth++);
} else {
$iPos = floor(count($to_save) / 2);
$aPrev = array_slice($to_save, 0, $iPos);
$aNext = array_slice($to_save, $iPos + 1);
$cnt = count($raList);
// If the first entry, it's the root... Don't clone it!
$raList[$cnt] = ( $depth == 0 ) ? $to_save[$iPos] : clone $to_save[$iPos];
$raList[$cnt]->No = $cnt;
$raList[$cnt]->PrevPps = self::_savePpsSetPnt($raList, $aPrev, $depth++);
$raList[$cnt]->NextPps = self::_savePpsSetPnt($raList, $aNext, $depth++);
$raList[$cnt]->DirPps = self::_savePpsSetPnt($raList, @$raList[$cnt]->children, $depth++);
}
return $cnt;
}
}
return $cnt;
}
}

View File

@@ -28,57 +28,47 @@
* @package PHPExcel_Shared_OLE
*/
class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
{
/**
* The constructor
*
* @access public
* @param string $name The name of the file (in Unicode)
* @see OLE::Asc2Ucs()
*/
public function __construct($name)
{
parent::__construct(
null,
$name,
PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE,
null,
null,
null,
null,
null,
'',
array());
}
{
/**
* The constructor
*
* @access public
* @param string $name The name of the file (in Unicode)
* @see OLE::Asc2Ucs()
*/
public function __construct($name)
{
parent::__construct(null, $name, PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE, null, null, null, null, null, '', array());
}
/**
* Initialization method. Has to be called right after OLE_PPS_File().
*
* @access public
* @return mixed true on success
*/
public function init()
{
return true;
}
/**
* Initialization method. Has to be called right after OLE_PPS_File().
*
* @access public
* @return mixed true on success
*/
public function init()
{
return true;
}
/**
* Append data to PPS
*
* @access public
* @param string $data The data to append
*/
public function append($data)
{
$this->_data .= $data;
}
/**
* Append data to PPS
*
* @access public
* @param string $data The data to append
*/
public function append($data)
{
$this->_data .= $data;
}
/**
* Returns a stream for reading this file using fread() etc.
* @return resource a read-only stream
*/
public function getStream()
{
$this->ole->getStream($this);
}
/**
* Returns a stream for reading this file using fread() etc.
* @return resource a read-only stream
*/
public function getStream()
{
$this->ole->getStream($this);
}
}

View File

@@ -28,440 +28,435 @@
* @package PHPExcel_Shared_OLE
*/
class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
{
{
/**
* Directory for temporary files
* @var string
*/
protected $_tmp_dir = NULL;
/**
* Directory for temporary files
* @var string
*/
protected $tempDirectory = null;
/**
* @param integer $time_1st A timestamp
* @param integer $time_2nd A timestamp
*/
public function __construct($time_1st, $time_2nd, $raChild)
{
$this->_tempDir = PHPExcel_Shared_File::sys_get_temp_dir();
/**
* @param integer $time_1st A timestamp
* @param integer $time_2nd A timestamp
*/
public function __construct($time_1st, $time_2nd, $raChild)
{
$this->_tempDir = PHPExcel_Shared_File::sys_get_temp_dir();
parent::__construct(
null,
PHPExcel_Shared_OLE::Asc2Ucs('Root Entry'),
PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT,
null,
null,
null,
$time_1st,
$time_2nd,
null,
$raChild);
}
parent::__construct(null, PHPExcel_Shared_OLE::Asc2Ucs('Root Entry'), PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT, null, null, null, $time_1st, $time_2nd, null, $raChild);
}
/**
* Method for saving the whole OLE container (including files).
* In fact, if called with an empty argument (or '-'), it saves to a
* temporary file and then outputs it's contents to stdout.
* If a resource pointer to a stream created by fopen() is passed
* it will be used, but you have to close such stream by yourself.
*
* @param string|resource $filename The name of the file or stream where to save the OLE container.
* @access public
* @return mixed true on success
*/
public function save($filename)
{
// Initial Setting for saving
$this->_BIG_BLOCK_SIZE = pow(2,
((isset($this->_BIG_BLOCK_SIZE))? self::_adjust2($this->_BIG_BLOCK_SIZE) : 9));
$this->_SMALL_BLOCK_SIZE= pow(2,
((isset($this->_SMALL_BLOCK_SIZE))? self::_adjust2($this->_SMALL_BLOCK_SIZE): 6));
/**
* Method for saving the whole OLE container (including files).
* In fact, if called with an empty argument (or '-'), it saves to a
* temporary file and then outputs it's contents to stdout.
* If a resource pointer to a stream created by fopen() is passed
* it will be used, but you have to close such stream by yourself.
*
* @param string|resource $filename The name of the file or stream where to save the OLE container.
* @access public
* @return mixed true on success
*/
public function save($filename)
{
// Initial Setting for saving
$this->_BIG_BLOCK_SIZE = pow(
2,
(isset($this->_BIG_BLOCK_SIZE))? self::adjust2($this->_BIG_BLOCK_SIZE) : 9
);
$this->_SMALL_BLOCK_SIZE= pow(
2,
(isset($this->_SMALL_BLOCK_SIZE))? self::adjust2($this->_SMALL_BLOCK_SIZE) : 6
);
if (is_resource($filename)) {
$this->_FILEH_ = $filename;
} else if ($filename == '-' || $filename == '') {
if ($this->_tmp_dir === NULL)
$this->_tmp_dir = PHPExcel_Shared_File::sys_get_temp_dir();
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
$this->_FILEH_ = fopen($this->_tmp_filename,"w+b");
if ($this->_FILEH_ == false) {
throw new PHPExcel_Writer_Exception("Can't create temporary file.");
}
} else {
$this->_FILEH_ = fopen($filename, "wb");
}
if ($this->_FILEH_ == false) {
throw new PHPExcel_Writer_Exception("Can't open $filename. It may be in use or protected.");
}
// Make an array of PPS's (for Save)
$aList = array();
PHPExcel_Shared_OLE_PPS::_savePpsSetPnt($aList, array($this));
// calculate values for header
list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->_calcSize($aList); //, $rhInfo);
// Save Header
$this->_saveHeader($iSBDcnt, $iBBcnt, $iPPScnt);
if (is_resource($filename)) {
$this->_FILEH_ = $filename;
} elseif ($filename == '-' || $filename == '') {
if ($this->tempDirectory === null) {
$this->tempDirectory = PHPExcel_Shared_File::sys_get_temp_dir();
}
$this->_tmp_filename = tempnam($this->tempDirectory, "OLE_PPS_Root");
$this->_FILEH_ = fopen($this->_tmp_filename, "w+b");
if ($this->_FILEH_ == false) {
throw new PHPExcel_Writer_Exception("Can't create temporary file.");
}
} else {
$this->_FILEH_ = fopen($filename, "wb");
}
if ($this->_FILEH_ == false) {
throw new PHPExcel_Writer_Exception("Can't open $filename. It may be in use or protected.");
}
// Make an array of PPS's (for Save)
$aList = array();
PHPExcel_Shared_OLE_PPS::_savePpsSetPnt($aList, array($this));
// calculate values for header
list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->_calcSize($aList); //, $rhInfo);
// Save Header
$this->_saveHeader($iSBDcnt, $iBBcnt, $iPPScnt);
// Make Small Data string (write SBD)
$this->_data = $this->_makeSmallData($aList);
// Make Small Data string (write SBD)
$this->_data = $this->_makeSmallData($aList);
// Write BB
$this->_saveBigData($iSBDcnt, $aList);
// Write PPS
$this->_savePps($aList);
// Write Big Block Depot and BDList and Adding Header informations
$this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
// Write BB
$this->_saveBigData($iSBDcnt, $aList);
// Write PPS
$this->_savePps($aList);
// Write Big Block Depot and BDList and Adding Header informations
$this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
if (!is_resource($filename)) {
fclose($this->_FILEH_);
}
if (!is_resource($filename)) {
fclose($this->_FILEH_);
}
return true;
}
return true;
}
/**
* Calculate some numbers
*
* @access public
* @param array $raList Reference to an array of PPS's
* @return array The array of numbers
*/
public function _calcSize(&$raList)
{
// Calculate Basic Setting
list($iSBDcnt, $iBBcnt, $iPPScnt) = array(0,0,0);
$iSmallLen = 0;
$iSBcnt = 0;
$iCount = count($raList);
for ($i = 0; $i < $iCount; ++$i) {
if ($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE) {
$raList[$i]->Size = $raList[$i]->_DataLen();
if ($raList[$i]->Size < PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) {
$iSBcnt += floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
+ (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
} else {
$iBBcnt += (floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
(($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
}
}
}
$iSmallLen = $iSBcnt * $this->_SMALL_BLOCK_SIZE;
$iSlCnt = floor($this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE);
$iSBDcnt = floor($iSBcnt / $iSlCnt) + (($iSBcnt % $iSlCnt)? 1:0);
$iBBcnt += (floor($iSmallLen / $this->_BIG_BLOCK_SIZE) +
(( $iSmallLen % $this->_BIG_BLOCK_SIZE)? 1: 0));
$iCnt = count($raList);
$iBdCnt = $this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_PPS_SIZE;
$iPPScnt = (floor($iCnt/$iBdCnt) + (($iCnt % $iBdCnt)? 1: 0));
/**
* Calculate some numbers
*
* @access public
* @param array $raList Reference to an array of PPS's
* @return array The array of numbers
*/
public function _calcSize(&$raList)
{
// Calculate Basic Setting
list($iSBDcnt, $iBBcnt, $iPPScnt) = array(0,0,0);
$iSmallLen = 0;
$iSBcnt = 0;
$iCount = count($raList);
for ($i = 0; $i < $iCount; ++$i) {
if ($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE) {
$raList[$i]->Size = $raList[$i]->_DataLen();
if ($raList[$i]->Size < PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) {
$iSBcnt += floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
+ (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
} else {
$iBBcnt += (floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
(($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
}
}
}
$iSmallLen = $iSBcnt * $this->_SMALL_BLOCK_SIZE;
$iSlCnt = floor($this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE);
$iSBDcnt = floor($iSBcnt / $iSlCnt) + (($iSBcnt % $iSlCnt)? 1:0);
$iBBcnt += (floor($iSmallLen / $this->_BIG_BLOCK_SIZE) +
(( $iSmallLen % $this->_BIG_BLOCK_SIZE)? 1: 0));
$iCnt = count($raList);
$iBdCnt = $this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_PPS_SIZE;
$iPPScnt = (floor($iCnt/$iBdCnt) + (($iCnt % $iBdCnt)? 1: 0));
return array($iSBDcnt, $iBBcnt, $iPPScnt);
}
return array($iSBDcnt, $iBBcnt, $iPPScnt);
}
/**
* Helper function for caculating a magic value for block sizes
*
* @access public
* @param integer $i2 The argument
* @see save()
* @return integer
*/
private static function _adjust2($i2)
{
$iWk = log($i2)/log(2);
return ($iWk > floor($iWk))? floor($iWk)+1:$iWk;
}
/**
* Helper function for caculating a magic value for block sizes
*
* @access public
* @param integer $i2 The argument
* @see save()
* @return integer
*/
private static function adjust2($i2)
{
$iWk = log($i2)/log(2);
return ($iWk > floor($iWk))? floor($iWk)+1:$iWk;
}
/**
* Save OLE header
*
* @access public
* @param integer $iSBDcnt
* @param integer $iBBcnt
* @param integer $iPPScnt
*/
public function _saveHeader($iSBDcnt, $iBBcnt, $iPPScnt)
{
$FILE = $this->_FILEH_;
/**
* Save OLE header
*
* @access public
* @param integer $iSBDcnt
* @param integer $iBBcnt
* @param integer $iPPScnt
*/
public function _saveHeader($iSBDcnt, $iBBcnt, $iPPScnt)
{
$FILE = $this->_FILEH_;
// Calculate Basic Setting
$iBlCnt = $this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE;
$i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE;
// Calculate Basic Setting
$iBlCnt = $this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE;
$i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE;
$iBdExL = 0;
$iAll = $iBBcnt + $iPPScnt + $iSBDcnt;
$iAllW = $iAll;
$iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
$iBdCnt = floor(($iAll + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
$iBdExL = 0;
$iAll = $iBBcnt + $iPPScnt + $iSBDcnt;
$iAllW = $iAll;
$iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
$iBdCnt = floor(($iAll + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
// Calculate BD count
if ($iBdCnt > $i1stBdL) {
while (1) {
++$iBdExL;
++$iAllW;
$iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
$iBdCnt = floor(($iAllW + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
if ($iBdCnt <= ($iBdExL*$iBlCnt+ $i1stBdL)) {
break;
}
}
}
// Calculate BD count
if ($iBdCnt > $i1stBdL) {
while (1) {
++$iBdExL;
++$iAllW;
$iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
$iBdCnt = floor(($iAllW + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
if ($iBdCnt <= ($iBdExL*$iBlCnt+ $i1stBdL)) {
break;
}
}
}
// Save Header
fwrite($FILE,
"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
. "\x00\x00\x00\x00"
. "\x00\x00\x00\x00"
. "\x00\x00\x00\x00"
. "\x00\x00\x00\x00"
. pack("v", 0x3b)
. pack("v", 0x03)
. pack("v", -2)
. pack("v", 9)
. pack("v", 6)
. pack("v", 0)
. "\x00\x00\x00\x00"
. "\x00\x00\x00\x00"
. pack("V", $iBdCnt)
. pack("V", $iBBcnt+$iSBDcnt) //ROOT START
. pack("V", 0)
. pack("V", 0x1000)
. pack("V", $iSBDcnt ? 0 : -2) //Small Block Depot
. pack("V", $iSBDcnt)
);
// Extra BDList Start, Count
if ($iBdCnt < $i1stBdL) {
fwrite($FILE,
pack("V", -2) // Extra BDList Start
. pack("V", 0) // Extra BDList Count
);
} else {
fwrite($FILE, pack("V", $iAll+$iBdCnt) . pack("V", $iBdExL));
}
// Save Header
fwrite(
$FILE,
"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
. "\x00\x00\x00\x00"
. "\x00\x00\x00\x00"
. "\x00\x00\x00\x00"
. "\x00\x00\x00\x00"
. pack("v", 0x3b)
. pack("v", 0x03)
. pack("v", -2)
. pack("v", 9)
. pack("v", 6)
. pack("v", 0)
. "\x00\x00\x00\x00"
. "\x00\x00\x00\x00"
. pack("V", $iBdCnt)
. pack("V", $iBBcnt+$iSBDcnt) //ROOT START
. pack("V", 0)
. pack("V", 0x1000)
. pack("V", $iSBDcnt ? 0 : -2) //Small Block Depot
. pack("V", $iSBDcnt)
);
// Extra BDList Start, Count
if ($iBdCnt < $i1stBdL) {
fwrite(
$FILE,
pack("V", -2) // Extra BDList Start
. pack("V", 0)// Extra BDList Count
);
} else {
fwrite($FILE, pack("V", $iAll+$iBdCnt) . pack("V", $iBdExL));
}
// BDList
for ($i = 0; $i < $i1stBdL && $i < $iBdCnt; ++$i) {
fwrite($FILE, pack("V", $iAll+$i));
}
if ($i < $i1stBdL) {
$jB = $i1stBdL - $i;
for ($j = 0; $j < $jB; ++$j) {
fwrite($FILE, (pack("V", -1)));
}
}
}
// BDList
for ($i = 0; $i < $i1stBdL && $i < $iBdCnt; ++$i) {
fwrite($FILE, pack("V", $iAll+$i));
}
if ($i < $i1stBdL) {
$jB = $i1stBdL - $i;
for ($j = 0; $j < $jB; ++$j) {
fwrite($FILE, (pack("V", -1)));
}
}
}
/**
* Saving big data (PPS's with data bigger than PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL)
*
* @access public
* @param integer $iStBlk
* @param array &$raList Reference to array of PPS's
*/
public function _saveBigData($iStBlk, &$raList)
{
$FILE = $this->_FILEH_;
/**
* Saving big data (PPS's with data bigger than PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL)
*
* @access public
* @param integer $iStBlk
* @param array &$raList Reference to array of PPS's
*/
public function _saveBigData($iStBlk, &$raList)
{
$FILE = $this->_FILEH_;
// cycle through PPS's
$iCount = count($raList);
for ($i = 0; $i < $iCount; ++$i) {
if ($raList[$i]->Type != PHPExcel_Shared_OLE::OLE_PPS_TYPE_DIR) {
$raList[$i]->Size = $raList[$i]->_DataLen();
if (($raList[$i]->Size >= PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) ||
(($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT) && isset($raList[$i]->_data)))
{
// Write Data
//if (isset($raList[$i]->_PPS_FILE)) {
// $iLen = 0;
// fseek($raList[$i]->_PPS_FILE, 0); // To The Top
// while($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
// $iLen += strlen($sBuff);
// fwrite($FILE, $sBuff);
// }
//} else {
fwrite($FILE, $raList[$i]->_data);
//}
// cycle through PPS's
$iCount = count($raList);
for ($i = 0; $i < $iCount; ++$i) {
if ($raList[$i]->Type != PHPExcel_Shared_OLE::OLE_PPS_TYPE_DIR) {
$raList[$i]->Size = $raList[$i]->_DataLen();
if (($raList[$i]->Size >= PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) || (($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT) && isset($raList[$i]->_data))) {
// Write Data
//if (isset($raList[$i]->_PPS_FILE)) {
// $iLen = 0;
// fseek($raList[$i]->_PPS_FILE, 0); // To The Top
// while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
// $iLen += strlen($sBuff);
// fwrite($FILE, $sBuff);
// }
//} else {
fwrite($FILE, $raList[$i]->_data);
//}
if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) {
fwrite($FILE, str_repeat("\x00", $this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)));
}
// Set For PPS
$raList[$i]->_StartBlock = $iStBlk;
$iStBlk +=
(floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
(($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
}
// Close file for each PPS, and unlink it
//if (isset($raList[$i]->_PPS_FILE)) {
// fclose($raList[$i]->_PPS_FILE);
// $raList[$i]->_PPS_FILE = null;
// unlink($raList[$i]->_tmp_filename);
//}
}
}
}
if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) {
fwrite($FILE, str_repeat("\x00", $this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)));
}
// Set For PPS
$raList[$i]->_StartBlock = $iStBlk;
$iStBlk +=
(floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
(($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
}
// Close file for each PPS, and unlink it
//if (isset($raList[$i]->_PPS_FILE)) {
// fclose($raList[$i]->_PPS_FILE);
// $raList[$i]->_PPS_FILE = null;
// unlink($raList[$i]->_tmp_filename);
//}
}
}
}
/**
* get small data (PPS's with data smaller than PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL)
*
* @access public
* @param array &$raList Reference to array of PPS's
*/
public function _makeSmallData(&$raList)
{
$sRes = '';
$FILE = $this->_FILEH_;
$iSmBlk = 0;
/**
* get small data (PPS's with data smaller than PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL)
*
* @access public
* @param array &$raList Reference to array of PPS's
*/
public function _makeSmallData(&$raList)
{
$sRes = '';
$FILE = $this->_FILEH_;
$iSmBlk = 0;
$iCount = count($raList);
for ($i = 0; $i < $iCount; ++$i) {
// Make SBD, small data string
if ($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE) {
if ($raList[$i]->Size <= 0) {
continue;
}
if ($raList[$i]->Size < PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) {
$iSmbCnt = floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
+ (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
// Add to SBD
$jB = $iSmbCnt - 1;
for ($j = 0; $j < $jB; ++$j) {
fwrite($FILE, pack("V", $j+$iSmBlk+1));
}
fwrite($FILE, pack("V", -2));
$iCount = count($raList);
for ($i = 0; $i < $iCount; ++$i) {
// Make SBD, small data string
if ($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE) {
if ($raList[$i]->Size <= 0) {
continue;
}
if ($raList[$i]->Size < PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) {
$iSmbCnt = floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
+ (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
// Add to SBD
$jB = $iSmbCnt - 1;
for ($j = 0; $j < $jB; ++$j) {
fwrite($FILE, pack("V", $j+$iSmBlk+1));
}
fwrite($FILE, pack("V", -2));
//// Add to Data String(this will be written for RootEntry)
//if ($raList[$i]->_PPS_FILE) {
// fseek($raList[$i]->_PPS_FILE, 0); // To The Top
// while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
// $sRes .= $sBuff;
// }
//} else {
$sRes .= $raList[$i]->_data;
//}
if ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) {
$sRes .= str_repeat("\x00",$this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE));
}
// Set for PPS
$raList[$i]->_StartBlock = $iSmBlk;
$iSmBlk += $iSmbCnt;
}
}
}
$iSbCnt = floor($this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE);
if ($iSmBlk % $iSbCnt) {
$iB = $iSbCnt - ($iSmBlk % $iSbCnt);
for ($i = 0; $i < $iB; ++$i) {
fwrite($FILE, pack("V", -1));
}
}
return $sRes;
}
//// Add to Data String(this will be written for RootEntry)
//if ($raList[$i]->_PPS_FILE) {
// fseek($raList[$i]->_PPS_FILE, 0); // To The Top
// while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
// $sRes .= $sBuff;
// }
//} else {
$sRes .= $raList[$i]->_data;
//}
if ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) {
$sRes .= str_repeat("\x00", $this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE));
}
// Set for PPS
$raList[$i]->_StartBlock = $iSmBlk;
$iSmBlk += $iSmbCnt;
}
}
}
$iSbCnt = floor($this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE);
if ($iSmBlk % $iSbCnt) {
$iB = $iSbCnt - ($iSmBlk % $iSbCnt);
for ($i = 0; $i < $iB; ++$i) {
fwrite($FILE, pack("V", -1));
}
}
return $sRes;
}
/**
* Saves all the PPS's WKs
*
* @access public
* @param array $raList Reference to an array with all PPS's
*/
public function _savePps(&$raList)
{
// Save each PPS WK
$iC = count($raList);
for ($i = 0; $i < $iC; ++$i) {
fwrite($this->_FILEH_, $raList[$i]->_getPpsWk());
}
// Adjust for Block
$iCnt = count($raList);
$iBCnt = $this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_PPS_SIZE;
if ($iCnt % $iBCnt) {
fwrite($this->_FILEH_, str_repeat("\x00",($iBCnt - ($iCnt % $iBCnt)) * PHPExcel_Shared_OLE::OLE_PPS_SIZE));
}
}
/**
* Saves all the PPS's WKs
*
* @access public
* @param array $raList Reference to an array with all PPS's
*/
public function _savePps(&$raList)
{
// Save each PPS WK
$iC = count($raList);
for ($i = 0; $i < $iC; ++$i) {
fwrite($this->_FILEH_, $raList[$i]->_getPpsWk());
}
// Adjust for Block
$iCnt = count($raList);
$iBCnt = $this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_PPS_SIZE;
if ($iCnt % $iBCnt) {
fwrite($this->_FILEH_, str_repeat("\x00", ($iBCnt - ($iCnt % $iBCnt)) * PHPExcel_Shared_OLE::OLE_PPS_SIZE));
}
}
/**
* Saving Big Block Depot
*
* @access public
* @param integer $iSbdSize
* @param integer $iBsize
* @param integer $iPpsCnt
*/
public function _saveBbd($iSbdSize, $iBsize, $iPpsCnt)
{
$FILE = $this->_FILEH_;
// Calculate Basic Setting
$iBbCnt = $this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE;
$i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE;
/**
* Saving Big Block Depot
*
* @access public
* @param integer $iSbdSize
* @param integer $iBsize
* @param integer $iPpsCnt
*/
public function _saveBbd($iSbdSize, $iBsize, $iPpsCnt)
{
$FILE = $this->_FILEH_;
// Calculate Basic Setting
$iBbCnt = $this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE;
$i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE;
$iBdExL = 0;
$iAll = $iBsize + $iPpsCnt + $iSbdSize;
$iAllW = $iAll;
$iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
$iBdCnt = floor(($iAll + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
// Calculate BD count
if ($iBdCnt >$i1stBdL) {
while (1) {
++$iBdExL;
++$iAllW;
$iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
$iBdCnt = floor(($iAllW + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
if ($iBdCnt <= ($iBdExL*$iBbCnt+ $i1stBdL)) {
break;
}
}
}
$iBdExL = 0;
$iAll = $iBsize + $iPpsCnt + $iSbdSize;
$iAllW = $iAll;
$iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
$iBdCnt = floor(($iAll + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
// Calculate BD count
if ($iBdCnt >$i1stBdL) {
while (1) {
++$iBdExL;
++$iAllW;
$iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
$iBdCnt = floor(($iAllW + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
if ($iBdCnt <= ($iBdExL*$iBbCnt+ $i1stBdL)) {
break;
}
}
}
// Making BD
// Set for SBD
if ($iSbdSize > 0) {
for ($i = 0; $i < ($iSbdSize - 1); ++$i) {
fwrite($FILE, pack("V", $i+1));
}
fwrite($FILE, pack("V", -2));
}
// Set for B
for ($i = 0; $i < ($iBsize - 1); ++$i) {
fwrite($FILE, pack("V", $i+$iSbdSize+1));
}
fwrite($FILE, pack("V", -2));
// Making BD
// Set for SBD
if ($iSbdSize > 0) {
for ($i = 0; $i < ($iSbdSize - 1); ++$i) {
fwrite($FILE, pack("V", $i+1));
}
fwrite($FILE, pack("V", -2));
}
// Set for B
for ($i = 0; $i < ($iBsize - 1); ++$i) {
fwrite($FILE, pack("V", $i+$iSbdSize+1));
}
fwrite($FILE, pack("V", -2));
// Set for PPS
for ($i = 0; $i < ($iPpsCnt - 1); ++$i) {
fwrite($FILE, pack("V", $i+$iSbdSize+$iBsize+1));
}
fwrite($FILE, pack("V", -2));
// Set for BBD itself ( 0xFFFFFFFD : BBD)
for ($i = 0; $i < $iBdCnt; ++$i) {
fwrite($FILE, pack("V", 0xFFFFFFFD));
}
// Set for ExtraBDList
for ($i = 0; $i < $iBdExL; ++$i) {
fwrite($FILE, pack("V", 0xFFFFFFFC));
}
// Adjust for Block
if (($iAllW + $iBdCnt) % $iBbCnt) {
$iBlock = ($iBbCnt - (($iAllW + $iBdCnt) % $iBbCnt));
for ($i = 0; $i < $iBlock; ++$i) {
fwrite($FILE, pack("V", -1));
}
}
// Extra BDList
if ($iBdCnt > $i1stBdL) {
$iN=0;
$iNb=0;
for ($i = $i1stBdL;$i < $iBdCnt; $i++, ++$iN) {
if ($iN >= ($iBbCnt - 1)) {
$iN = 0;
++$iNb;
fwrite($FILE, pack("V", $iAll+$iBdCnt+$iNb));
}
fwrite($FILE, pack("V", $iBsize+$iSbdSize+$iPpsCnt+$i));
}
if (($iBdCnt-$i1stBdL) % ($iBbCnt-1)) {
$iB = ($iBbCnt - 1) - (($iBdCnt - $i1stBdL) % ($iBbCnt - 1));
for ($i = 0; $i < $iB; ++$i) {
fwrite($FILE, pack("V", -1));
}
}
fwrite($FILE, pack("V", -2));
}
}
// Set for PPS
for ($i = 0; $i < ($iPpsCnt - 1); ++$i) {
fwrite($FILE, pack("V", $i+$iSbdSize+$iBsize+1));
}
fwrite($FILE, pack("V", -2));
// Set for BBD itself ( 0xFFFFFFFD : BBD)
for ($i = 0; $i < $iBdCnt; ++$i) {
fwrite($FILE, pack("V", 0xFFFFFFFD));
}
// Set for ExtraBDList
for ($i = 0; $i < $iBdExL; ++$i) {
fwrite($FILE, pack("V", 0xFFFFFFFC));
}
// Adjust for Block
if (($iAllW + $iBdCnt) % $iBbCnt) {
$iBlock = ($iBbCnt - (($iAllW + $iBdCnt) % $iBbCnt));
for ($i = 0; $i < $iBlock; ++$i) {
fwrite($FILE, pack("V", -1));
}
}
// Extra BDList
if ($iBdCnt > $i1stBdL) {
$iN=0;
$iNb=0;
for ($i = $i1stBdL; $i < $iBdCnt; $i++, ++$iN) {
if ($iN >= ($iBbCnt - 1)) {
$iN = 0;
++$iNb;
fwrite($FILE, pack("V", $iAll+$iBdCnt+$iNb));
}
fwrite($FILE, pack("V", $iBsize+$iSbdSize+$iPpsCnt+$i));
}
if (($iBdCnt-$i1stBdL) % ($iBbCnt-1)) {
$iB = ($iBbCnt - 1) - (($iBdCnt - $i1stBdL) % ($iBbCnt - 1));
for ($i = 0; $i < $iB; ++$i) {
fwrite($FILE, pack("V", -1));
}
}
fwrite($FILE, pack("V", -2));
}
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,298 +20,299 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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##
*/
defined('IDENTIFIER_OLE') ||
define('IDENTIFIER_OLE', pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1));
class PHPExcel_Shared_OLERead {
private $data = '';
class PHPExcel_Shared_OLERead
{
private $data = '';
// OLE identifier
const IDENTIFIER_OLE = IDENTIFIER_OLE;
// OLE identifier
const IDENTIFIER_OLE = IDENTIFIER_OLE;
// Size of a sector = 512 bytes
const BIG_BLOCK_SIZE = 0x200;
// Size of a sector = 512 bytes
const BIG_BLOCK_SIZE = 0x200;
// Size of a short sector = 64 bytes
const SMALL_BLOCK_SIZE = 0x40;
// Size of a short sector = 64 bytes
const SMALL_BLOCK_SIZE = 0x40;
// Size of a directory entry always = 128 bytes
const PROPERTY_STORAGE_BLOCK_SIZE = 0x80;
// Size of a directory entry always = 128 bytes
const PROPERTY_STORAGE_BLOCK_SIZE = 0x80;
// Minimum size of a standard stream = 4096 bytes, streams smaller than this are stored as short streams
const SMALL_BLOCK_THRESHOLD = 0x1000;
// Minimum size of a standard stream = 4096 bytes, streams smaller than this are stored as short streams
const SMALL_BLOCK_THRESHOLD = 0x1000;
// header offsets
const NUM_BIG_BLOCK_DEPOT_BLOCKS_POS = 0x2c;
const ROOT_START_BLOCK_POS = 0x30;
const SMALL_BLOCK_DEPOT_BLOCK_POS = 0x3c;
const EXTENSION_BLOCK_POS = 0x44;
const NUM_EXTENSION_BLOCK_POS = 0x48;
const BIG_BLOCK_DEPOT_BLOCKS_POS = 0x4c;
// header offsets
const NUM_BIG_BLOCK_DEPOT_BLOCKS_POS = 0x2c;
const ROOT_START_BLOCK_POS = 0x30;
const SMALL_BLOCK_DEPOT_BLOCK_POS = 0x3c;
const EXTENSION_BLOCK_POS = 0x44;
const NUM_EXTENSION_BLOCK_POS = 0x48;
const BIG_BLOCK_DEPOT_BLOCKS_POS = 0x4c;
// property storage offsets (directory offsets)
const SIZE_OF_NAME_POS = 0x40;
const TYPE_POS = 0x42;
const START_BLOCK_POS = 0x74;
const SIZE_POS = 0x78;
// property storage offsets (directory offsets)
const SIZE_OF_NAME_POS = 0x40;
const TYPE_POS = 0x42;
const START_BLOCK_POS = 0x74;
const SIZE_POS = 0x78;
public $wrkbook = null;
public $summaryInformation = null;
public $documentSummaryInformation = null;
public $wrkbook = null;
public $summaryInformation = null;
public $documentSummaryInformation = null;
/**
* Read the file
*
* @param $sFileName string Filename
* @throws PHPExcel_Reader_Exception
*/
public function read($sFileName)
{
// Check if file exists and is readable
if(!is_readable($sFileName)) {
throw new PHPExcel_Reader_Exception("Could not open " . $sFileName . " for reading! File does not exist, or it is not readable.");
}
/**
* Read the file
*
* @param $sFileName string Filename
* @throws PHPExcel_Reader_Exception
*/
public function read($sFileName)
{
// Check if file exists and is readable
if (!is_readable($sFileName)) {
throw new PHPExcel_Reader_Exception("Could not open " . $sFileName . " for reading! File does not exist, or it is not readable.");
}
// Get the file identifier
// Don't bother reading the whole file until we know it's a valid OLE file
$this->data = file_get_contents($sFileName, FALSE, NULL, 0, 8);
// Get the file identifier
// Don't bother reading the whole file until we know it's a valid OLE file
$this->data = file_get_contents($sFileName, false, null, 0, 8);
// Check OLE identifier
if ($this->data != self::IDENTIFIER_OLE) {
throw new PHPExcel_Reader_Exception('The filename ' . $sFileName . ' is not recognised as an OLE file');
}
// Check OLE identifier
if ($this->data != self::IDENTIFIER_OLE) {
throw new PHPExcel_Reader_Exception('The filename ' . $sFileName . ' is not recognised as an OLE file');
}
// Get the file data
$this->data = file_get_contents($sFileName);
// Get the file data
$this->data = file_get_contents($sFileName);
// Total number of sectors used for the SAT
$this->numBigBlockDepotBlocks = self::_GetInt4d($this->data, self::NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);
// Total number of sectors used for the SAT
$this->numBigBlockDepotBlocks = self::getInt4d($this->data, self::NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);
// SecID of the first sector of the directory stream
$this->rootStartBlock = self::_GetInt4d($this->data, self::ROOT_START_BLOCK_POS);
// SecID of the first sector of the directory stream
$this->rootStartBlock = self::getInt4d($this->data, self::ROOT_START_BLOCK_POS);
// SecID of the first sector of the SSAT (or -2 if not extant)
$this->sbdStartBlock = self::_GetInt4d($this->data, self::SMALL_BLOCK_DEPOT_BLOCK_POS);
// SecID of the first sector of the SSAT (or -2 if not extant)
$this->sbdStartBlock = self::getInt4d($this->data, self::SMALL_BLOCK_DEPOT_BLOCK_POS);
// SecID of the first sector of the MSAT (or -2 if no additional sectors are used)
$this->extensionBlock = self::_GetInt4d($this->data, self::EXTENSION_BLOCK_POS);
// SecID of the first sector of the MSAT (or -2 if no additional sectors are used)
$this->extensionBlock = self::getInt4d($this->data, self::EXTENSION_BLOCK_POS);
// Total number of sectors used by MSAT
$this->numExtensionBlocks = self::_GetInt4d($this->data, self::NUM_EXTENSION_BLOCK_POS);
// Total number of sectors used by MSAT
$this->numExtensionBlocks = self::getInt4d($this->data, self::NUM_EXTENSION_BLOCK_POS);
$bigBlockDepotBlocks = array();
$pos = self::BIG_BLOCK_DEPOT_BLOCKS_POS;
$bigBlockDepotBlocks = array();
$pos = self::BIG_BLOCK_DEPOT_BLOCKS_POS;
$bbdBlocks = $this->numBigBlockDepotBlocks;
$bbdBlocks = $this->numBigBlockDepotBlocks;
if ($this->numExtensionBlocks != 0) {
$bbdBlocks = (self::BIG_BLOCK_SIZE - self::BIG_BLOCK_DEPOT_BLOCKS_POS)/4;
}
if ($this->numExtensionBlocks != 0) {
$bbdBlocks = (self::BIG_BLOCK_SIZE - self::BIG_BLOCK_DEPOT_BLOCKS_POS)/4;
}
for ($i = 0; $i < $bbdBlocks; ++$i) {
$bigBlockDepotBlocks[$i] = self::_GetInt4d($this->data, $pos);
$pos += 4;
}
for ($i = 0; $i < $bbdBlocks; ++$i) {
$bigBlockDepotBlocks[$i] = self::getInt4d($this->data, $pos);
$pos += 4;
}
for ($j = 0; $j < $this->numExtensionBlocks; ++$j) {
$pos = ($this->extensionBlock + 1) * self::BIG_BLOCK_SIZE;
$blocksToRead = min($this->numBigBlockDepotBlocks - $bbdBlocks, self::BIG_BLOCK_SIZE / 4 - 1);
for ($j = 0; $j < $this->numExtensionBlocks; ++$j) {
$pos = ($this->extensionBlock + 1) * self::BIG_BLOCK_SIZE;
$blocksToRead = min($this->numBigBlockDepotBlocks - $bbdBlocks, self::BIG_BLOCK_SIZE / 4 - 1);
for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; ++$i) {
$bigBlockDepotBlocks[$i] = self::_GetInt4d($this->data, $pos);
$pos += 4;
}
for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; ++$i) {
$bigBlockDepotBlocks[$i] = self::getInt4d($this->data, $pos);
$pos += 4;
}
$bbdBlocks += $blocksToRead;
if ($bbdBlocks < $this->numBigBlockDepotBlocks) {
$this->extensionBlock = self::_GetInt4d($this->data, $pos);
}
}
$bbdBlocks += $blocksToRead;
if ($bbdBlocks < $this->numBigBlockDepotBlocks) {
$this->extensionBlock = self::getInt4d($this->data, $pos);
}
}
$pos = 0;
$this->bigBlockChain = '';
$bbs = self::BIG_BLOCK_SIZE / 4;
for ($i = 0; $i < $this->numBigBlockDepotBlocks; ++$i) {
$pos = ($bigBlockDepotBlocks[$i] + 1) * self::BIG_BLOCK_SIZE;
$pos = 0;
$this->bigBlockChain = '';
$bbs = self::BIG_BLOCK_SIZE / 4;
for ($i = 0; $i < $this->numBigBlockDepotBlocks; ++$i) {
$pos = ($bigBlockDepotBlocks[$i] + 1) * self::BIG_BLOCK_SIZE;
$this->bigBlockChain .= substr($this->data, $pos, 4*$bbs);
$pos += 4*$bbs;
}
$this->bigBlockChain .= substr($this->data, $pos, 4*$bbs);
$pos += 4*$bbs;
}
$pos = 0;
$sbdBlock = $this->sbdStartBlock;
$this->smallBlockChain = '';
while ($sbdBlock != -2) {
$pos = ($sbdBlock + 1) * self::BIG_BLOCK_SIZE;
$pos = 0;
$sbdBlock = $this->sbdStartBlock;
$this->smallBlockChain = '';
while ($sbdBlock != -2) {
$pos = ($sbdBlock + 1) * self::BIG_BLOCK_SIZE;
$this->smallBlockChain .= substr($this->data, $pos, 4*$bbs);
$pos += 4*$bbs;
$this->smallBlockChain .= substr($this->data, $pos, 4*$bbs);
$pos += 4*$bbs;
$sbdBlock = self::_GetInt4d($this->bigBlockChain, $sbdBlock*4);
}
$sbdBlock = self::getInt4d($this->bigBlockChain, $sbdBlock*4);
}
// read the directory stream
$block = $this->rootStartBlock;
$this->entry = $this->_readData($block);
// read the directory stream
$block = $this->rootStartBlock;
$this->entry = $this->_readData($block);
$this->_readPropertySets();
}
$this->readPropertySets();
}
/**
* Extract binary stream data
*
* @return string
*/
public function getStream($stream)
{
if ($stream === NULL) {
return null;
}
/**
* Extract binary stream data
*
* @return string
*/
public function getStream($stream)
{
if ($stream === null) {
return null;
}
$streamData = '';
$streamData = '';
if ($this->props[$stream]['size'] < self::SMALL_BLOCK_THRESHOLD) {
$rootdata = $this->_readData($this->props[$this->rootentry]['startBlock']);
if ($this->props[$stream]['size'] < self::SMALL_BLOCK_THRESHOLD) {
$rootdata = $this->_readData($this->props[$this->rootentry]['startBlock']);
$block = $this->props[$stream]['startBlock'];
$block = $this->props[$stream]['startBlock'];
while ($block != -2) {
$pos = $block * self::SMALL_BLOCK_SIZE;
$streamData .= substr($rootdata, $pos, self::SMALL_BLOCK_SIZE);
while ($block != -2) {
$pos = $block * self::SMALL_BLOCK_SIZE;
$streamData .= substr($rootdata, $pos, self::SMALL_BLOCK_SIZE);
$block = self::_GetInt4d($this->smallBlockChain, $block*4);
}
$block = self::getInt4d($this->smallBlockChain, $block*4);
}
return $streamData;
} else {
$numBlocks = $this->props[$stream]['size'] / self::BIG_BLOCK_SIZE;
if ($this->props[$stream]['size'] % self::BIG_BLOCK_SIZE != 0) {
++$numBlocks;
}
return $streamData;
} else {
$numBlocks = $this->props[$stream]['size'] / self::BIG_BLOCK_SIZE;
if ($this->props[$stream]['size'] % self::BIG_BLOCK_SIZE != 0) {
++$numBlocks;
}
if ($numBlocks == 0) return '';
if ($numBlocks == 0) {
return '';
}
$block = $this->props[$stream]['startBlock'];
$block = $this->props[$stream]['startBlock'];
while ($block != -2) {
$pos = ($block + 1) * self::BIG_BLOCK_SIZE;
$streamData .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
$block = self::_GetInt4d($this->bigBlockChain, $block*4);
}
while ($block != -2) {
$pos = ($block + 1) * self::BIG_BLOCK_SIZE;
$streamData .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
$block = self::getInt4d($this->bigBlockChain, $block*4);
}
return $streamData;
}
}
return $streamData;
}
}
/**
* Read a standard stream (by joining sectors using information from SAT)
*
* @param int $bl Sector ID where the stream starts
* @return string Data for standard stream
*/
private function _readData($bl)
{
$block = $bl;
$data = '';
/**
* Read a standard stream (by joining sectors using information from SAT)
*
* @param int $bl Sector ID where the stream starts
* @return string Data for standard stream
*/
private function _readData($bl)
{
$block = $bl;
$data = '';
while ($block != -2) {
$pos = ($block + 1) * self::BIG_BLOCK_SIZE;
$data .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
$block = self::_GetInt4d($this->bigBlockChain, $block*4);
}
return $data;
}
while ($block != -2) {
$pos = ($block + 1) * self::BIG_BLOCK_SIZE;
$data .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
$block = self::getInt4d($this->bigBlockChain, $block*4);
}
return $data;
}
/**
* Read entries in the directory stream.
*/
private function _readPropertySets() {
$offset = 0;
/**
* Read entries in the directory stream.
*/
private function readPropertySets()
{
$offset = 0;
// loop through entires, each entry is 128 bytes
$entryLen = strlen($this->entry);
while ($offset < $entryLen) {
// entry data (128 bytes)
$d = substr($this->entry, $offset, self::PROPERTY_STORAGE_BLOCK_SIZE);
// loop through entires, each entry is 128 bytes
$entryLen = strlen($this->entry);
while ($offset < $entryLen) {
// entry data (128 bytes)
$d = substr($this->entry, $offset, self::PROPERTY_STORAGE_BLOCK_SIZE);
// size in bytes of name
$nameSize = ord($d[self::SIZE_OF_NAME_POS]) | (ord($d[self::SIZE_OF_NAME_POS+1]) << 8);
// size in bytes of name
$nameSize = ord($d[self::SIZE_OF_NAME_POS]) | (ord($d[self::SIZE_OF_NAME_POS+1]) << 8);
// type of entry
$type = ord($d[self::TYPE_POS]);
// type of entry
$type = ord($d[self::TYPE_POS]);
// sectorID of first sector or short sector, if this entry refers to a stream (the case with workbook)
// sectorID of first sector of the short-stream container stream, if this entry is root entry
$startBlock = self::_GetInt4d($d, self::START_BLOCK_POS);
// sectorID of first sector or short sector, if this entry refers to a stream (the case with workbook)
// sectorID of first sector of the short-stream container stream, if this entry is root entry
$startBlock = self::getInt4d($d, self::START_BLOCK_POS);
$size = self::_GetInt4d($d, self::SIZE_POS);
$size = self::getInt4d($d, self::SIZE_POS);
$name = str_replace("\x00", "", substr($d,0,$nameSize));
$name = str_replace("\x00", "", substr($d, 0, $nameSize));
$this->props[] = array(
'name' => $name,
'type' => $type,
'startBlock' => $startBlock,
'size' => $size
);
$this->props[] = array (
'name' => $name,
'type' => $type,
'startBlock' => $startBlock,
'size' => $size);
// tmp helper to simplify checks
$upName = strtoupper($name);
// tmp helper to simplify checks
$upName = strtoupper($name);
// Workbook directory entry (BIFF5 uses Book, BIFF8 uses Workbook)
if (($upName === 'WORKBOOK') || ($upName === 'BOOK')) {
$this->wrkbook = count($this->props) - 1;
} elseif ($upName === 'ROOT ENTRY' || $upName === 'R') {
// Root entry
$this->rootentry = count($this->props) - 1;
}
// Workbook directory entry (BIFF5 uses Book, BIFF8 uses Workbook)
if (($upName === 'WORKBOOK') || ($upName === 'BOOK')) {
$this->wrkbook = count($this->props) - 1;
}
else if ( $upName === 'ROOT ENTRY' || $upName === 'R') {
// Root entry
$this->rootentry = count($this->props) - 1;
}
// Summary information
if ($name == chr(5) . 'SummaryInformation') {
// echo 'Summary Information<br />';
$this->summaryInformation = count($this->props) - 1;
}
// Summary information
if ($name == chr(5) . 'SummaryInformation') {
// echo 'Summary Information<br />';
$this->summaryInformation = count($this->props) - 1;
}
// Additional Document Summary information
if ($name == chr(5) . 'DocumentSummaryInformation') {
// echo 'Document Summary Information<br />';
$this->documentSummaryInformation = count($this->props) - 1;
}
// Additional Document Summary information
if ($name == chr(5) . 'DocumentSummaryInformation') {
// echo 'Document Summary Information<br />';
$this->documentSummaryInformation = count($this->props) - 1;
}
$offset += self::PROPERTY_STORAGE_BLOCK_SIZE;
}
}
/**
* Read 4 bytes of data at specified position
*
* @param string $data
* @param int $pos
* @return int
*/
private static function _GetInt4d($data, $pos)
{
// FIX: represent numbers correctly on 64-bit system
// http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334
// Hacked by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems
$_or_24 = ord($data[$pos + 3]);
if ($_or_24 >= 128) {
// negative number
$_ord_24 = -abs((256 - $_or_24) << 24);
} else {
$_ord_24 = ($_or_24 & 127) << 24;
}
return ord($data[$pos]) | (ord($data[$pos + 1]) << 8) | (ord($data[$pos + 2]) << 16) | $_ord_24;
}
$offset += self::PROPERTY_STORAGE_BLOCK_SIZE;
}
}
/**
* Read 4 bytes of data at specified position
*
* @param string $data
* @param int $pos
* @return int
*/
private static function getInt4d($data, $pos)
{
// FIX: represent numbers correctly on 64-bit system
// http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334
// Hacked by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems
$_or_24 = ord($data[$pos + 3]);
if ($_or_24 >= 128) {
// negative number
$_ord_24 = -abs((256 - $_or_24) << 24);
} else {
$_ord_24 = ($_or_24 & 127) << 24;
}
return ord($data[$pos]) | (ord($data[$pos + 1]) << 8) | (ord($data[$pos + 2]) << 16) | $_ord_24;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,8 +20,8 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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##
*/
@@ -31,36 +31,37 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_PasswordHasher
{
/**
* Create a password hash from a given string.
*
* This method is based on the algorithm provided by
* Daniel Rentz of OpenOffice and the PEAR package
* Spreadsheet_Excel_Writer by Xavier Noguer <xnoguer@rezebra.com>.
*
* @param string $pPassword Password to hash
* @return string Hashed password
*/
public static function hashPassword($pPassword = '') {
$password = 0x0000;
$charPos = 1; // char position
/**
* Create a password hash from a given string.
*
* This method is based on the algorithm provided by
* Daniel Rentz of OpenOffice and the PEAR package
* Spreadsheet_Excel_Writer by Xavier Noguer <xnoguer@rezebra.com>.
*
* @param string $pPassword Password to hash
* @return string Hashed password
*/
public static function hashPassword($pPassword = '')
{
$password = 0x0000;
$charPos = 1; // char position
// split the plain text password in its component characters
$chars = preg_split('//', $pPassword, -1, PREG_SPLIT_NO_EMPTY);
foreach ($chars as $char) {
$value = ord($char) << $charPos++; // shifted ASCII value
$rotated_bits = $value >> 15; // rotated bits beyond bit 15
$value &= 0x7fff; // first 15 bits
$password ^= ($value | $rotated_bits);
$value = ord($char) << $charPos++; // shifted ASCII value
$rotated_bits = $value >> 15; // rotated bits beyond bit 15
$value &= 0x7fff; // first 15 bits
$password ^= ($value | $rotated_bits);
}
$password ^= strlen($pPassword);
$password ^= 0xCE4B;
return(strtoupper(dechex($password)));
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,10 +20,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
* @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##
*/
@@ -31,110 +31,114 @@
* PHPExcel_Shared_TimeZone
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_TimeZone
{
/*
* Default Timezone used for date/time conversions
*
* @private
* @var string
*/
protected static $_timezone = 'UTC';
/*
* Default Timezone used for date/time conversions
*
* @private
* @var string
*/
protected static $timezone = 'UTC';
/**
* Validate a Timezone name
*
* @param string $timezone Time zone (e.g. 'Europe/London')
* @return boolean Success or failure
*/
public static function _validateTimeZone($timezone) {
if (in_array($timezone, DateTimeZone::listIdentifiers())) {
return TRUE;
}
return FALSE;
}
/**
* Validate a Timezone name
*
* @param string $timezone Time zone (e.g. 'Europe/London')
* @return boolean Success or failure
*/
public static function _validateTimeZone($timezone)
{
if (in_array($timezone, DateTimeZone::listIdentifiers())) {
return true;
}
return false;
}
/**
* Set the Default Timezone used for date/time conversions
*
* @param string $timezone Time zone (e.g. 'Europe/London')
* @return boolean Success or failure
*/
public static function setTimeZone($timezone) {
if (self::_validateTimezone($timezone)) {
self::$_timezone = $timezone;
return TRUE;
}
return FALSE;
} // function setTimezone()
/**
* Set the Default Timezone used for date/time conversions
*
* @param string $timezone Time zone (e.g. 'Europe/London')
* @return boolean Success or failure
*/
public static function setTimeZone($timezone)
{
if (self::_validateTimezone($timezone)) {
self::$timezone = $timezone;
return true;
}
return false;
}
/**
* Return the Default Timezone used for date/time conversions
*
* @return string Timezone (e.g. 'Europe/London')
*/
public static function getTimeZone() {
return self::$_timezone;
} // function getTimezone()
/**
* Return the Default Timezone used for date/time conversions
*
* @return string Timezone (e.g. 'Europe/London')
*/
public static function getTimeZone()
{
return self::$timezone;
}
/**
* Return the Timezone transition for the specified timezone and timestamp
*
* @param DateTimeZone $objTimezone The timezone for finding the transitions
* @param integer $timestamp PHP date/time value for finding the current transition
* @return array The current transition details
*/
private static function _getTimezoneTransitions($objTimezone, $timestamp) {
$allTransitions = $objTimezone->getTransitions();
$transitions = array();
foreach($allTransitions as $key => $transition) {
if ($transition['ts'] > $timestamp) {
$transitions[] = ($key > 0) ? $allTransitions[$key - 1] : $transition;
break;
}
if (empty($transitions)) {
$transitions[] = end($allTransitions);
}
}
/**
* Return the Timezone transition for the specified timezone and timestamp
*
* @param DateTimeZone $objTimezone The timezone for finding the transitions
* @param integer $timestamp PHP date/time value for finding the current transition
* @return array The current transition details
*/
private static function getTimezoneTransitions($objTimezone, $timestamp)
{
$allTransitions = $objTimezone->getTransitions();
$transitions = array();
foreach ($allTransitions as $key => $transition) {
if ($transition['ts'] > $timestamp) {
$transitions[] = ($key > 0) ? $allTransitions[$key - 1] : $transition;
break;
}
if (empty($transitions)) {
$transitions[] = end($allTransitions);
}
}
return $transitions;
}
return $transitions;
}
/**
* Return the Timezone offset used for date/time conversions to/from UST
* This requires both the timezone and the calculated date/time to allow for local DST
*
* @param string $timezone The timezone for finding the adjustment to UST
* @param integer $timestamp PHP date/time value
* @return integer Number of seconds for timezone adjustment
* @throws PHPExcel_Exception
*/
public static function getTimeZoneAdjustment($timezone, $timestamp) {
if ($timezone !== NULL) {
if (!self::_validateTimezone($timezone)) {
throw new PHPExcel_Exception("Invalid timezone " . $timezone);
}
} else {
$timezone = self::$_timezone;
}
/**
* Return the Timezone offset used for date/time conversions to/from UST
* This requires both the timezone and the calculated date/time to allow for local DST
*
* @param string $timezone The timezone for finding the adjustment to UST
* @param integer $timestamp PHP date/time value
* @return integer Number of seconds for timezone adjustment
* @throws PHPExcel_Exception
*/
public static function getTimeZoneAdjustment($timezone, $timestamp)
{
if ($timezone !== null) {
if (!self::_validateTimezone($timezone)) {
throw new PHPExcel_Exception("Invalid timezone " . $timezone);
}
} else {
$timezone = self::$timezone;
}
if ($timezone == 'UST') {
return 0;
}
if ($timezone == 'UST') {
return 0;
}
$objTimezone = new DateTimeZone($timezone);
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
$transitions = $objTimezone->getTransitions($timestamp,$timestamp);
} else {
$transitions = self::_getTimezoneTransitions($objTimezone, $timestamp);
}
return (count($transitions) > 0) ? $transitions[0]['offset'] : 0;
}
$objTimezone = new DateTimeZone($timezone);
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
$transitions = $objTimezone->getTransitions($timestamp, $timestamp);
} else {
$transitions = self::getTimezoneTransitions($objTimezone, $timestamp);
}
return (count($transitions) > 0) ? $transitions[0]['offset'] : 0;
}
}

View File

@@ -1,8 +1,17 @@
<?php
if (!defined('DATE_W3C')) {
define('DATE_W3C', 'Y-m-d\TH:i:sP');
}
if (!defined('DEBUGMODE_ENABLED')) {
define('DEBUGMODE_ENABLED', false);
}
/**
* PHPExcel
* PHPExcel_Shared_XMLWriter
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -19,109 +28,97 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
* @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_XMLWriter extends XMLWriter
{
/** Temporary storage method */
const STORAGE_MEMORY = 1;
const STORAGE_DISK = 2;
if (!defined('DATE_W3C')) {
define('DATE_W3C', 'Y-m-d\TH:i:sP');
}
if (!defined('DEBUGMODE_ENABLED')) {
define('DEBUGMODE_ENABLED', false);
}
/**
* PHPExcel_Shared_XMLWriter
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_XMLWriter extends XMLWriter {
/** Temporary storage method */
const STORAGE_MEMORY = 1;
const STORAGE_DISK = 2;
/**
* Temporary filename
*
* @var string
*/
private $_tempFileName = '';
/**
* Create a new PHPExcel_Shared_XMLWriter instance
*
* @param int $pTemporaryStorage Temporary storage location
* @param string $pTemporaryStorageFolder Temporary storage folder
*/
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = NULL) {
// Open temporary storage
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
$this->openMemory();
} else {
// Create temporary filename
if ($pTemporaryStorageFolder === NULL)
$pTemporaryStorageFolder = PHPExcel_Shared_File::sys_get_temp_dir();
$this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
// Open storage
if ($this->openUri($this->_tempFileName) === false) {
// Fallback to memory...
$this->openMemory();
}
}
// Set default values
if (DEBUGMODE_ENABLED) {
$this->setIndent(true);
}
}
/**
* Destructor
*/
public function __destruct() {
// Unlink temporary files
if ($this->_tempFileName != '') {
@unlink($this->_tempFileName);
}
}
/**
* Get written data
*
* @return $data
*/
public function getData() {
if ($this->_tempFileName == '') {
return $this->outputMemory(true);
} else {
$this->flush();
return file_get_contents($this->_tempFileName);
}
}
/**
* Fallback method for writeRaw, introduced in PHP 5.2
*
* @param string $text
* @return string
*/
public function writeRawData($text)
{
if (is_array($text)) {
$text = implode("\n",$text);
}
if (method_exists($this, 'writeRaw')) {
return $this->writeRaw(htmlspecialchars($text));
}
return $this->text($text);
}
/**
* Temporary filename
*
* @var string
*/
private $tempFileName = '';
/**
* Create a new PHPExcel_Shared_XMLWriter instance
*
* @param int $pTemporaryStorage Temporary storage location
* @param string $pTemporaryStorageFolder Temporary storage folder
*/
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = null)
{
// Open temporary storage
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
$this->openMemory();
} else {
// Create temporary filename
if ($pTemporaryStorageFolder === null) {
$pTemporaryStorageFolder = PHPExcel_Shared_File::sys_get_temp_dir();
}
$this->tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
// Open storage
if ($this->openUri($this->tempFileName) === false) {
// Fallback to memory...
$this->openMemory();
}
}
// Set default values
if (DEBUGMODE_ENABLED) {
$this->setIndent(true);
}
}
/**
* Destructor
*/
public function __destruct()
{
// Unlink temporary files
if ($this->tempFileName != '') {
@unlink($this->tempFileName);
}
}
/**
* Get written data
*
* @return $data
*/
public function getData()
{
if ($this->tempFileName == '') {
return $this->outputMemory(true);
} else {
$this->flush();
return file_get_contents($this->tempFileName);
}
}
/**
* Fallback method for writeRaw, introduced in PHP 5.2
*
* @param string $text
* @return string
*/
public function writeRawData($text)
{
if (is_array($text)) {
$text = implode("\n", $text);
}
if (method_exists($this, 'writeRaw')) {
return $this->writeRaw(htmlspecialchars($text));
}
return $this->text($text);
}
}

View File

@@ -1,8 +1,14 @@
<?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 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,96 +26,78 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_ZipArchive
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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##
*/
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 - 2014 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())
@@ -119,17 +107,19 @@ class PHPExcel_Shared_ZipArchive
*/
public function locateName($fileName)
{
$list = $this->_zip->listContent();
$fileName = strtolower($fileName);
$list = $this->zip->listContent();
$listCount = count($list);
$list_index = -1;
$index = -1;
for ($i = 0; $i < $listCount; ++$i) {
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
$list_index = $i;
if (strtolower($list[$i]["filename"]) == $fileName ||
strtolower($list[$i]["stored_filename"]) == $fileName) {
$index = $i;
break;
}
}
return ($list_index > -1);
return ($index > -1) ? $index : false;
}
/**
@@ -138,34 +128,32 @@ class PHPExcel_Shared_ZipArchive
* @param string $fileName Filename for the file in zip archive
* @return string $contents File string contents
*/
public function getFromName($fileName)
public function getFromName($fileName)
{
$list = $this->_zip->listContent();
$listCount = count($list);
$list_index = -1;
for ($i = 0; $i < $listCount; ++$i) {
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
$list_index = $i;
break;
$index = $this->locateName($fileName);
if ($index !== false) {
$extracted = $this->getFromIndex($index);
} else {
$fileName = substr($fileName, 1);
$index = $this->locateName($fileName);
if ($index === false) {
return false;
}
$extracted = $this->zip->getFromIndex($index);
}
$extracted = "";
if ($list_index != -1) {
$extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING);
} else {
$filename = substr($fileName, 1);
$list_index = -1;
for ($i = 0; $i < $listCount; ++$i) {
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
$list_index = $i;
break;
}
}
$extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING);
$contents = $extracted;
if ((is_array($extracted)) && ($extracted != 0)) {
$contents = $extracted[0]["content"];
}
return $contents;
}
public function getFromIndex($index) {
$extracted = $this->zip->extractByIndex($index, PCLZIP_OPT_EXTRACT_AS_STRING);
$contents = '';
if ((is_array($extracted)) && ($extracted != 0)) {
$contents = $extracted[0]["content"];
}

View File

@@ -1,8 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_ZipStreamWrapper
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,180 +21,178 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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_ZipStreamWrapper
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_ZipStreamWrapper {
/**
* Internal ZipAcrhive
*
* @var ZipAcrhive
*/
private $_archive;
class PHPExcel_Shared_ZipStreamWrapper
{
/**
* Internal ZipAcrhive
*
* @var ZipArchive
*/
private $archive;
/**
* Filename in ZipAcrhive
*
* @var string
*/
private $_fileNameInArchive = '';
private $fileNameInArchive = '';
/**
* Position in file
*
* @var int
*/
private $_position = 0;
private $position = 0;
/**
* Data
*
* @var mixed
*/
private $_data = '';
private $data = '';
/**
* Register wrapper
*/
public static function register() {
@stream_wrapper_unregister("zip");
@stream_wrapper_register("zip", __CLASS__);
public static function register()
{
@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) {
public function stream_open($path, $mode, $options, &$opened_path)
{
// Check for mode
if ($mode{0} != 'r') {
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();
$this->_archive->open($url['host']);
$this->archive = new ZipArchive();
$this->archive->open($url['host']);
$this->_fileNameInArchive = $url['fragment'];
$this->_position = 0;
$this->_data = $this->_archive->getFromName( $this->_fileNameInArchive );
$this->fileNameInArchive = $url['fragment'];
$this->position = 0;
$this->data = $this->archive->getFromName($this->fileNameInArchive);
return true;
}
/**
* Implements support for fstat().
*
* @return boolean
* Implements support for fstat().
*
* @return boolean
*/
public function statName() {
return $this->_fileNameInArchive;
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 );
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 );
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);
$this->_position += strlen($ret);
public function stream_read($count)
{
$ret = substr($this->data, $this->position, $count);
$this->position += strlen($ret);
return $ret;
}
/**
* 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;
public function stream_tell()
{
return $this->position;
}
/**
* EOF stream
*
* @return bool
*
* @return bool
*/
public function stream_eof() {
return $this->_position >= strlen($this->_data);
public function stream_eof()
{
return $this->position >= strlen($this->data);
}
/**
* 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) {
public function stream_seek($offset, $whence)
{
switch ($whence) {
case SEEK_SET:
if ($offset < strlen($this->_data) && $offset >= 0) {
$this->_position = $offset;
if ($offset < strlen($this->data) && $offset >= 0) {
$this->position = $offset;
return true;
} else {
return false;
}
break;
case SEEK_CUR:
if ($offset >= 0) {
$this->_position += $offset;
$this->position += $offset;
return true;
} else {
return false;
}
break;
case SEEK_END:
if (strlen($this->_data) + $offset >= 0) {
$this->_position = strlen($this->_data) + $offset;
if (strlen($this->data) + $offset >= 0) {
$this->position = strlen($this->data) + $offset;
return true;
} else {
return false;
}
break;
default:
return false;
}

View File

@@ -1,8 +1,9 @@
<?php
/**
* PHPExcel
* PHPExcel_Best_Fit
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,413 +21,405 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Trend
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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_Best_Fit
*
* @category PHPExcel
* @package PHPExcel_Shared_Trend
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Best_Fit
{
/**
* Indicator flag for a calculation error
*
* @var boolean
**/
protected $_error = False;
/**
* Indicator flag for a calculation error
*
* @var boolean
**/
protected $error = false;
/**
* Algorithm type to use for best-fit
*
* @var string
**/
protected $_bestFitType = 'undetermined';
/**
* Number of entries in the sets of x- and y-value arrays
*
* @var int
**/
protected $_valueCount = 0;
/**
* X-value dataseries of values
*
* @var float[]
**/
protected $_xValues = array();
/**
* Y-value dataseries of values
*
* @var float[]
**/
protected $_yValues = array();
/**
* Flag indicating whether values should be adjusted to Y=0
*
* @var boolean
**/
protected $_adjustToZero = False;
/**
* Y-value series of best-fit values
*
* @var float[]
**/
protected $_yBestFitValues = array();
protected $_goodnessOfFit = 1;
protected $_stdevOfResiduals = 0;
protected $_covariance = 0;
protected $_correlation = 0;
protected $_SSRegression = 0;
protected $_SSResiduals = 0;
protected $_DFResiduals = 0;
protected $_F = 0;
protected $_slope = 0;
protected $_slopeSE = 0;
protected $_intersect = 0;
protected $_intersectSE = 0;
protected $_Xoffset = 0;
protected $_Yoffset = 0;
public function getError() {
return $this->_error;
} // function getBestFitType()
public function getBestFitType() {
return $this->_bestFitType;
} // function getBestFitType()
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
*/
public function getValueOfYForX($xValue) {
return False;
} // function getValueOfYForX()
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
*/
public function getValueOfXForY($yValue) {
return False;
} // function getValueOfXForY()
/**
* Return the original set of X-Values
*
* @return float[] X-Values
*/
public function getXValues() {
return $this->_xValues;
} // function getValueOfXForY()
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
public function getEquation($dp=0) {
return False;
} // function getEquation()
/**
* Return the Slope of the line
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
public function getSlope($dp=0) {
if ($dp != 0) {
return round($this->_slope,$dp);
}
return $this->_slope;
} // function getSlope()
/**
* Return the standard error of the Slope
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
public function getSlopeSE($dp=0) {
if ($dp != 0) {
return round($this->_slopeSE,$dp);
}
return $this->_slopeSE;
} // function getSlopeSE()
/**
* Return the Value of X where it intersects Y = 0
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
public function getIntersect($dp=0) {
if ($dp != 0) {
return round($this->_intersect,$dp);
}
return $this->_intersect;
} // function getIntersect()
/**
* Return the standard error of the Intersect
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
public function getIntersectSE($dp=0) {
if ($dp != 0) {
return round($this->_intersectSE,$dp);
}
return $this->_intersectSE;
} // function getIntersectSE()
/**
* Return the goodness of fit for this regression
*
* @param int $dp Number of places of decimal precision to return
* @return float
*/
public function getGoodnessOfFit($dp=0) {
if ($dp != 0) {
return round($this->_goodnessOfFit,$dp);
}
return $this->_goodnessOfFit;
} // function getGoodnessOfFit()
public function getGoodnessOfFitPercent($dp=0) {
if ($dp != 0) {
return round($this->_goodnessOfFit * 100,$dp);
}
return $this->_goodnessOfFit * 100;
} // function getGoodnessOfFitPercent()
/**
* Return the standard deviation of the residuals for this regression
*
* @param int $dp Number of places of decimal precision to return
* @return float
*/
public function getStdevOfResiduals($dp=0) {
if ($dp != 0) {
return round($this->_stdevOfResiduals,$dp);
}
return $this->_stdevOfResiduals;
} // function getStdevOfResiduals()
public function getSSRegression($dp=0) {
if ($dp != 0) {
return round($this->_SSRegression,$dp);
}
return $this->_SSRegression;
} // function getSSRegression()
public function getSSResiduals($dp=0) {
if ($dp != 0) {
return round($this->_SSResiduals,$dp);
}
return $this->_SSResiduals;
} // function getSSResiduals()
public function getDFResiduals($dp=0) {
if ($dp != 0) {
return round($this->_DFResiduals,$dp);
}
return $this->_DFResiduals;
} // function getDFResiduals()
public function getF($dp=0) {
if ($dp != 0) {
return round($this->_F,$dp);
}
return $this->_F;
} // function getF()
public function getCovariance($dp=0) {
if ($dp != 0) {
return round($this->_covariance,$dp);
}
return $this->_covariance;
} // function getCovariance()
public function getCorrelation($dp=0) {
if ($dp != 0) {
return round($this->_correlation,$dp);
}
return $this->_correlation;
} // function getCorrelation()
public function getYBestFitValues() {
return $this->_yBestFitValues;
} // function getYBestFitValues()
protected function _calculateGoodnessOfFit($sumX,$sumY,$sumX2,$sumY2,$sumXY,$meanX,$meanY, $const) {
$SSres = $SScov = $SScor = $SStot = $SSsex = 0.0;
foreach($this->_xValues as $xKey => $xValue) {
$bestFitY = $this->_yBestFitValues[$xKey] = $this->getValueOfYForX($xValue);
$SSres += ($this->_yValues[$xKey] - $bestFitY) * ($this->_yValues[$xKey] - $bestFitY);
if ($const) {
$SStot += ($this->_yValues[$xKey] - $meanY) * ($this->_yValues[$xKey] - $meanY);
} else {
$SStot += $this->_yValues[$xKey] * $this->_yValues[$xKey];
}
$SScov += ($this->_xValues[$xKey] - $meanX) * ($this->_yValues[$xKey] - $meanY);
if ($const) {
$SSsex += ($this->_xValues[$xKey] - $meanX) * ($this->_xValues[$xKey] - $meanX);
} else {
$SSsex += $this->_xValues[$xKey] * $this->_xValues[$xKey];
}
}
$this->_SSResiduals = $SSres;
$this->_DFResiduals = $this->_valueCount - 1 - $const;
if ($this->_DFResiduals == 0.0) {
$this->_stdevOfResiduals = 0.0;
} else {
$this->_stdevOfResiduals = sqrt($SSres / $this->_DFResiduals);
}
if (($SStot == 0.0) || ($SSres == $SStot)) {
$this->_goodnessOfFit = 1;
} else {
$this->_goodnessOfFit = 1 - ($SSres / $SStot);
}
$this->_SSRegression = $this->_goodnessOfFit * $SStot;
$this->_covariance = $SScov / $this->_valueCount;
$this->_correlation = ($this->_valueCount * $sumXY - $sumX * $sumY) / sqrt(($this->_valueCount * $sumX2 - pow($sumX,2)) * ($this->_valueCount * $sumY2 - pow($sumY,2)));
$this->_slopeSE = $this->_stdevOfResiduals / sqrt($SSsex);
$this->_intersectSE = $this->_stdevOfResiduals * sqrt(1 / ($this->_valueCount - ($sumX * $sumX) / $sumX2));
if ($this->_SSResiduals != 0.0) {
if ($this->_DFResiduals == 0.0) {
$this->_F = 0.0;
} else {
$this->_F = $this->_SSRegression / ($this->_SSResiduals / $this->_DFResiduals);
}
} else {
if ($this->_DFResiduals == 0.0) {
$this->_F = 0.0;
} else {
$this->_F = $this->_SSRegression / $this->_DFResiduals;
}
}
} // function _calculateGoodnessOfFit()
protected function _leastSquareFit($yValues, $xValues, $const) {
// calculate sums
$x_sum = array_sum($xValues);
$y_sum = array_sum($yValues);
$meanX = $x_sum / $this->_valueCount;
$meanY = $y_sum / $this->_valueCount;
$mBase = $mDivisor = $xx_sum = $xy_sum = $yy_sum = 0.0;
for($i = 0; $i < $this->_valueCount; ++$i) {
$xy_sum += $xValues[$i] * $yValues[$i];
$xx_sum += $xValues[$i] * $xValues[$i];
$yy_sum += $yValues[$i] * $yValues[$i];
if ($const) {
$mBase += ($xValues[$i] - $meanX) * ($yValues[$i] - $meanY);
$mDivisor += ($xValues[$i] - $meanX) * ($xValues[$i] - $meanX);
} else {
$mBase += $xValues[$i] * $yValues[$i];
$mDivisor += $xValues[$i] * $xValues[$i];
}
}
// calculate slope
// $this->_slope = (($this->_valueCount * $xy_sum) - ($x_sum * $y_sum)) / (($this->_valueCount * $xx_sum) - ($x_sum * $x_sum));
$this->_slope = $mBase / $mDivisor;
// calculate intersect
// $this->_intersect = ($y_sum - ($this->_slope * $x_sum)) / $this->_valueCount;
if ($const) {
$this->_intersect = $meanY - ($this->_slope * $meanX);
} else {
$this->_intersect = 0;
}
$this->_calculateGoodnessOfFit($x_sum,$y_sum,$xx_sum,$yy_sum,$xy_sum,$meanX,$meanY,$const);
} // function _leastSquareFit()
/**
* Define the regression
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
function __construct($yValues, $xValues=array(), $const=True) {
// Calculate number of points
$nY = count($yValues);
$nX = count($xValues);
// Define X Values if necessary
if ($nX == 0) {
$xValues = range(1,$nY);
$nX = $nY;
} elseif ($nY != $nX) {
// Ensure both arrays of points are the same size
$this->_error = True;
return False;
}
$this->_valueCount = $nY;
$this->_xValues = $xValues;
$this->_yValues = $yValues;
} // function __construct()
} // class bestFit
/**
* Algorithm type to use for best-fit
*
* @var string
**/
protected $bestFitType = 'undetermined';
/**
* Number of entries in the sets of x- and y-value arrays
*
* @var int
**/
protected $valueCount = 0;
/**
* X-value dataseries of values
*
* @var float[]
**/
protected $xValues = array();
/**
* Y-value dataseries of values
*
* @var float[]
**/
protected $yValues = array();
/**
* Flag indicating whether values should be adjusted to Y=0
*
* @var boolean
**/
protected $adjustToZero = false;
/**
* Y-value series of best-fit values
*
* @var float[]
**/
protected $yBestFitValues = array();
protected $goodnessOfFit = 1;
protected $stdevOfResiduals = 0;
protected $covariance = 0;
protected $correlation = 0;
protected $SSRegression = 0;
protected $SSResiduals = 0;
protected $DFResiduals = 0;
protected $f = 0;
protected $slope = 0;
protected $slopeSE = 0;
protected $intersect = 0;
protected $intersectSE = 0;
protected $xOffset = 0;
protected $yOffset = 0;
public function getError()
{
return $this->error;
}
public function getBestFitType()
{
return $this->bestFitType;
}
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
*/
public function getValueOfYForX($xValue)
{
return false;
}
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
*/
public function getValueOfXForY($yValue)
{
return false;
}
/**
* Return the original set of X-Values
*
* @return float[] X-Values
*/
public function getXValues()
{
return $this->xValues;
}
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
public function getEquation($dp = 0)
{
return false;
}
/**
* Return the Slope of the line
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
public function getSlope($dp = 0)
{
if ($dp != 0) {
return round($this->slope, $dp);
}
return $this->slope;
}
/**
* Return the standard error of the Slope
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
public function getSlopeSE($dp = 0)
{
if ($dp != 0) {
return round($this->slopeSE, $dp);
}
return $this->slopeSE;
}
/**
* Return the Value of X where it intersects Y = 0
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
public function getIntersect($dp = 0)
{
if ($dp != 0) {
return round($this->intersect, $dp);
}
return $this->intersect;
}
/**
* Return the standard error of the Intersect
*
* @param int $dp Number of places of decimal precision to display
* @return string
*/
public function getIntersectSE($dp = 0)
{
if ($dp != 0) {
return round($this->intersectSE, $dp);
}
return $this->intersectSE;
}
/**
* Return the goodness of fit for this regression
*
* @param int $dp Number of places of decimal precision to return
* @return float
*/
public function getGoodnessOfFit($dp = 0)
{
if ($dp != 0) {
return round($this->goodnessOfFit, $dp);
}
return $this->goodnessOfFit;
}
public function getGoodnessOfFitPercent($dp = 0)
{
if ($dp != 0) {
return round($this->goodnessOfFit * 100, $dp);
}
return $this->goodnessOfFit * 100;
}
/**
* Return the standard deviation of the residuals for this regression
*
* @param int $dp Number of places of decimal precision to return
* @return float
*/
public function getStdevOfResiduals($dp = 0)
{
if ($dp != 0) {
return round($this->stdevOfResiduals, $dp);
}
return $this->stdevOfResiduals;
}
public function getSSRegression($dp = 0)
{
if ($dp != 0) {
return round($this->SSRegression, $dp);
}
return $this->SSRegression;
}
public function getSSResiduals($dp = 0)
{
if ($dp != 0) {
return round($this->SSResiduals, $dp);
}
return $this->SSResiduals;
}
public function getDFResiduals($dp = 0)
{
if ($dp != 0) {
return round($this->DFResiduals, $dp);
}
return $this->DFResiduals;
}
public function getF($dp = 0)
{
if ($dp != 0) {
return round($this->f, $dp);
}
return $this->f;
}
public function getCovariance($dp = 0)
{
if ($dp != 0) {
return round($this->covariance, $dp);
}
return $this->covariance;
}
public function getCorrelation($dp = 0)
{
if ($dp != 0) {
return round($this->correlation, $dp);
}
return $this->correlation;
}
public function getYBestFitValues()
{
return $this->yBestFitValues;
}
protected function calculateGoodnessOfFit($sumX, $sumY, $sumX2, $sumY2, $sumXY, $meanX, $meanY, $const)
{
$SSres = $SScov = $SScor = $SStot = $SSsex = 0.0;
foreach ($this->xValues as $xKey => $xValue) {
$bestFitY = $this->yBestFitValues[$xKey] = $this->getValueOfYForX($xValue);
$SSres += ($this->yValues[$xKey] - $bestFitY) * ($this->yValues[$xKey] - $bestFitY);
if ($const) {
$SStot += ($this->yValues[$xKey] - $meanY) * ($this->yValues[$xKey] - $meanY);
} else {
$SStot += $this->yValues[$xKey] * $this->yValues[$xKey];
}
$SScov += ($this->xValues[$xKey] - $meanX) * ($this->yValues[$xKey] - $meanY);
if ($const) {
$SSsex += ($this->xValues[$xKey] - $meanX) * ($this->xValues[$xKey] - $meanX);
} else {
$SSsex += $this->xValues[$xKey] * $this->xValues[$xKey];
}
}
$this->SSResiduals = $SSres;
$this->DFResiduals = $this->valueCount - 1 - $const;
if ($this->DFResiduals == 0.0) {
$this->stdevOfResiduals = 0.0;
} else {
$this->stdevOfResiduals = sqrt($SSres / $this->DFResiduals);
}
if (($SStot == 0.0) || ($SSres == $SStot)) {
$this->goodnessOfFit = 1;
} else {
$this->goodnessOfFit = 1 - ($SSres / $SStot);
}
$this->SSRegression = $this->goodnessOfFit * $SStot;
$this->covariance = $SScov / $this->valueCount;
$this->correlation = ($this->valueCount * $sumXY - $sumX * $sumY) / sqrt(($this->valueCount * $sumX2 - pow($sumX, 2)) * ($this->valueCount * $sumY2 - pow($sumY, 2)));
$this->slopeSE = $this->stdevOfResiduals / sqrt($SSsex);
$this->intersectSE = $this->stdevOfResiduals * sqrt(1 / ($this->valueCount - ($sumX * $sumX) / $sumX2));
if ($this->SSResiduals != 0.0) {
if ($this->DFResiduals == 0.0) {
$this->f = 0.0;
} else {
$this->f = $this->SSRegression / ($this->SSResiduals / $this->DFResiduals);
}
} else {
if ($this->DFResiduals == 0.0) {
$this->f = 0.0;
} else {
$this->f = $this->SSRegression / $this->DFResiduals;
}
}
}
protected function leastSquareFit($yValues, $xValues, $const)
{
// calculate sums
$x_sum = array_sum($xValues);
$y_sum = array_sum($yValues);
$meanX = $x_sum / $this->valueCount;
$meanY = $y_sum / $this->valueCount;
$mBase = $mDivisor = $xx_sum = $xy_sum = $yy_sum = 0.0;
for ($i = 0; $i < $this->valueCount; ++$i) {
$xy_sum += $xValues[$i] * $yValues[$i];
$xx_sum += $xValues[$i] * $xValues[$i];
$yy_sum += $yValues[$i] * $yValues[$i];
if ($const) {
$mBase += ($xValues[$i] - $meanX) * ($yValues[$i] - $meanY);
$mDivisor += ($xValues[$i] - $meanX) * ($xValues[$i] - $meanX);
} else {
$mBase += $xValues[$i] * $yValues[$i];
$mDivisor += $xValues[$i] * $xValues[$i];
}
}
// calculate slope
// $this->slope = (($this->valueCount * $xy_sum) - ($x_sum * $y_sum)) / (($this->valueCount * $xx_sum) - ($x_sum * $x_sum));
$this->slope = $mBase / $mDivisor;
// calculate intersect
// $this->intersect = ($y_sum - ($this->slope * $x_sum)) / $this->valueCount;
if ($const) {
$this->intersect = $meanY - ($this->slope * $meanX);
} else {
$this->intersect = 0;
}
$this->calculateGoodnessOfFit($x_sum, $y_sum, $xx_sum, $yy_sum, $xy_sum, $meanX, $meanY, $const);
}
/**
* Define the regression
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
public function __construct($yValues, $xValues = array(), $const = true)
{
// Calculate number of points
$nY = count($yValues);
$nX = count($xValues);
// Define X Values if necessary
if ($nX == 0) {
$xValues = range(1, $nY);
$nX = $nY;
} elseif ($nY != $nX) {
// Ensure both arrays of points are the same size
$this->error = true;
return false;
}
$this->valueCount = $nY;
$this->xValues = $xValues;
$this->yValues = $yValues;
}
}

View File

@@ -1,8 +1,11 @@
<?php
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
/**
* PHPExcel
* PHPExcel_Exponential_Best_Fit
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,129 +23,116 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Trend
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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##
*/
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
/**
* PHPExcel_Exponential_Best_Fit
*
* @category PHPExcel
* @package PHPExcel_Shared_Trend
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
{
/**
* Algorithm type to use for best-fit
* (Name of this trend class)
*
* @var string
**/
protected $_bestFitType = 'exponential';
/**
* Algorithm type to use for best-fit
* (Name of this trend class)
*
* @var string
**/
protected $bestFitType = 'exponential';
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
**/
public function getValueOfYForX($xValue)
{
return $this->getIntersect() * pow($this->getSlope(), ($xValue - $this->xOffset));
}
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
**/
public function getValueOfYForX($xValue) {
return $this->getIntersect() * pow($this->getSlope(),($xValue - $this->_Xoffset));
} // function getValueOfYForX()
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
**/
public function getValueOfXForY($yValue)
{
return log(($yValue + $this->yOffset) / $this->getIntersect()) / log($this->getSlope());
}
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getEquation($dp = 0)
{
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
**/
public function getValueOfXForY($yValue) {
return log(($yValue + $this->_Yoffset) / $this->getIntersect()) / log($this->getSlope());
} // function getValueOfXForY()
return 'Y = ' . $intersect . ' * ' . $slope . '^X';
}
/**
* Return the Slope of the line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getSlope($dp = 0)
{
if ($dp != 0) {
return round(exp($this->_slope), $dp);
}
return exp($this->_slope);
}
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getEquation($dp=0) {
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
/**
* Return the Value of X where it intersects Y = 0
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getIntersect($dp = 0)
{
if ($dp != 0) {
return round(exp($this->intersect), $dp);
}
return exp($this->intersect);
}
return 'Y = '.$intersect.' * '.$slope.'^X';
} // function getEquation()
/**
* Execute the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
private function exponentialRegression($yValues, $xValues, $const)
{
foreach ($yValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
$this->leastSquareFit($yValues, $xValues, $const);
}
/**
* Return the Slope of the line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getSlope($dp=0) {
if ($dp != 0) {
return round(exp($this->_slope),$dp);
}
return exp($this->_slope);
} // function getSlope()
/**
* Return the Value of X where it intersects Y = 0
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getIntersect($dp=0) {
if ($dp != 0) {
return round(exp($this->_intersect),$dp);
}
return exp($this->_intersect);
} // function getIntersect()
/**
* Execute the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
private function _exponential_regression($yValues, $xValues, $const) {
foreach($yValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
$this->_leastSquareFit($yValues, $xValues, $const);
} // function _exponential_regression()
/**
* Define the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
function __construct($yValues, $xValues=array(), $const=True) {
if (parent::__construct($yValues, $xValues) !== False) {
$this->_exponential_regression($yValues, $xValues, $const);
}
} // function __construct()
} // class exponentialBestFit
/**
* Define the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
public function __construct($yValues, $xValues = array(), $const = true)
{
if (parent::__construct($yValues, $xValues) !== false) {
$this->exponentialRegression($yValues, $xValues, $const);
}
}
}

View File

@@ -1,8 +1,11 @@
<?php
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
/**
* PHPExcel
* PHPExcel_Linear_Best_Fit
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,92 +23,80 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Trend
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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##
*/
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
/**
* PHPExcel_Linear_Best_Fit
*
* @category PHPExcel
* @package PHPExcel_Shared_Trend
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit
{
/**
* Algorithm type to use for best-fit
* (Name of this trend class)
*
* @var string
**/
protected $_bestFitType = 'linear';
/**
* Algorithm type to use for best-fit
* (Name of this trend class)
*
* @var string
**/
protected $bestFitType = 'linear';
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
**/
public function getValueOfYForX($xValue)
{
return $this->getIntersect() + $this->getSlope() * $xValue;
}
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
**/
public function getValueOfXForY($yValue)
{
return ($yValue - $this->getIntersect()) / $this->getSlope();
}
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
**/
public function getValueOfYForX($xValue) {
return $this->getIntersect() + $this->getSlope() * $xValue;
} // function getValueOfYForX()
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getEquation($dp = 0)
{
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
return 'Y = ' . $intersect . ' + ' . $slope . ' * X';
}
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
**/
public function getValueOfXForY($yValue) {
return ($yValue - $this->getIntersect()) / $this->getSlope();
} // function getValueOfXForY()
/**
* Execute the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
private function linearRegression($yValues, $xValues, $const)
{
$this->leastSquareFit($yValues, $xValues, $const);
}
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getEquation($dp=0) {
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
return 'Y = '.$intersect.' + '.$slope.' * X';
} // function getEquation()
/**
* Execute the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
private function _linear_regression($yValues, $xValues, $const) {
$this->_leastSquareFit($yValues, $xValues,$const);
} // function _linear_regression()
/**
* Define the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
function __construct($yValues, $xValues=array(), $const=True) {
if (parent::__construct($yValues, $xValues) !== False) {
$this->_linear_regression($yValues, $xValues, $const);
}
} // function __construct()
} // class linearBestFit
/**
* Define the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
public function __construct($yValues, $xValues = array(), $const = true)
{
if (parent::__construct($yValues, $xValues) !== false) {
$this->linearRegression($yValues, $xValues, $const);
}
}
}

View File

@@ -1,8 +1,11 @@
<?php
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
/**
* PHPExcel
* PHPExcel_Logarithmic_Best_Fit
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,101 +23,88 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Trend
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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##
*/
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
/**
* PHPExcel_Logarithmic_Best_Fit
*
* @category PHPExcel
* @package PHPExcel_Shared_Trend
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
{
/**
* Algorithm type to use for best-fit
* (Name of this trend class)
*
* @var string
**/
protected $_bestFitType = 'logarithmic';
/**
* Algorithm type to use for best-fit
* (Name of this trend class)
*
* @var string
**/
protected $bestFitType = 'logarithmic';
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
**/
public function getValueOfYForX($xValue)
{
return $this->getIntersect() + $this->getSlope() * log($xValue - $this->xOffset);
}
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
**/
public function getValueOfYForX($xValue) {
return $this->getIntersect() + $this->getSlope() * log($xValue - $this->_Xoffset);
} // function getValueOfYForX()
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
**/
public function getValueOfXForY($yValue)
{
return exp(($yValue - $this->getIntersect()) / $this->getSlope());
}
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getEquation($dp = 0)
{
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
**/
public function getValueOfXForY($yValue) {
return exp(($yValue - $this->getIntersect()) / $this->getSlope());
} // function getValueOfXForY()
return 'Y = '.$intersect.' + '.$slope.' * log(X)';
}
/**
* Execute the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
private function logarithmicRegression($yValues, $xValues, $const)
{
foreach ($xValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getEquation($dp=0) {
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
$this->leastSquareFit($yValues, $xValues, $const);
}
return 'Y = '.$intersect.' + '.$slope.' * log(X)';
} // function getEquation()
/**
* Execute the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
private function _logarithmic_regression($yValues, $xValues, $const) {
foreach($xValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
$this->_leastSquareFit($yValues, $xValues, $const);
} // function _logarithmic_regression()
/**
* Define the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
function __construct($yValues, $xValues=array(), $const=True) {
if (parent::__construct($yValues, $xValues) !== False) {
$this->_logarithmic_regression($yValues, $xValues, $const);
}
} // function __construct()
} // class logarithmicBestFit
/**
* Define the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
public function __construct($yValues, $xValues = array(), $const = true)
{
if (parent::__construct($yValues, $xValues) !== false) {
$this->logarithmicRegression($yValues, $xValues, $const);
}
}
}

View File

@@ -1,8 +1,12 @@
<?php
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/JAMA/Matrix.php';
/**
* PHPExcel
* PHPExcel_Polynomial_Best_Fit
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,205 +24,199 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Trend
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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##
*/
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/JAMA/Matrix.php';
/**
* PHPExcel_Polynomial_Best_Fit
*
* @category PHPExcel
* @package PHPExcel_Shared_Trend
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
{
/**
* Algorithm type to use for best-fit
* (Name of this trend class)
*
* @var string
**/
protected $_bestFitType = 'polynomial';
/**
* Algorithm type to use for best-fit
* (Name of this trend class)
*
* @var string
**/
protected $bestFitType = 'polynomial';
/**
* Polynomial order
*
* @protected
* @var int
**/
protected $_order = 0;
/**
* Polynomial order
*
* @protected
* @var int
**/
protected $order = 0;
/**
* Return the order of this polynomial
*
* @return int
**/
public function getOrder() {
return $this->_order;
} // function getOrder()
/**
* Return the order of this polynomial
*
* @return int
**/
public function getOrder()
{
return $this->order;
}
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
**/
public function getValueOfYForX($xValue) {
$retVal = $this->getIntersect();
$slope = $this->getSlope();
foreach($slope as $key => $value) {
if ($value != 0.0) {
$retVal += $value * pow($xValue, $key + 1);
}
}
return $retVal;
} // function getValueOfYForX()
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
**/
public function getValueOfYForX($xValue)
{
$retVal = $this->getIntersect();
$slope = $this->getSlope();
foreach ($slope as $key => $value) {
if ($value != 0.0) {
$retVal += $value * pow($xValue, $key + 1);
}
}
return $retVal;
}
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
**/
public function getValueOfXForY($yValue) {
return ($yValue - $this->getIntersect()) / $this->getSlope();
} // function getValueOfXForY()
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
**/
public function getValueOfXForY($yValue)
{
return ($yValue - $this->getIntersect()) / $this->getSlope();
}
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getEquation($dp=0) {
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getEquation($dp = 0)
{
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
$equation = 'Y = '.$intersect;
foreach($slope as $key => $value) {
if ($value != 0.0) {
$equation .= ' + '.$value.' * X';
if ($key > 0) {
$equation .= '^'.($key + 1);
}
}
}
return $equation;
} // function getEquation()
$equation = 'Y = ' . $intersect;
foreach ($slope as $key => $value) {
if ($value != 0.0) {
$equation .= ' + ' . $value . ' * X';
if ($key > 0) {
$equation .= '^' . ($key + 1);
}
}
}
return $equation;
}
/**
* Return the Slope of the line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getSlope($dp=0) {
if ($dp != 0) {
$coefficients = array();
foreach($this->_slope as $coefficient) {
$coefficients[] = round($coefficient,$dp);
}
return $coefficients;
}
return $this->_slope;
} // function getSlope()
/**
* Return the Slope of the line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getSlope($dp = 0)
{
if ($dp != 0) {
$coefficients = array();
foreach ($this->_slope as $coefficient) {
$coefficients[] = round($coefficient, $dp);
}
return $coefficients;
}
return $this->_slope;
}
public function getCoefficients($dp=0) {
return array_merge(array($this->getIntersect($dp)),$this->getSlope($dp));
} // function getCoefficients()
public function getCoefficients($dp = 0)
{
return array_merge(array($this->getIntersect($dp)), $this->getSlope($dp));
}
/**
* Execute the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param int $order Order of Polynomial for this regression
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
private function _polynomial_regression($order, $yValues, $xValues, $const) {
// calculate sums
$x_sum = array_sum($xValues);
$y_sum = array_sum($yValues);
$xx_sum = $xy_sum = 0;
for($i = 0; $i < $this->_valueCount; ++$i) {
$xy_sum += $xValues[$i] * $yValues[$i];
$xx_sum += $xValues[$i] * $xValues[$i];
$yy_sum += $yValues[$i] * $yValues[$i];
}
/*
* This routine uses logic from the PHP port of polyfit version 0.1
* written by Michael Bommarito and Paul Meagher
*
* The function fits a polynomial function of order $order through
* a series of x-y data points using least squares.
*
*/
for ($i = 0; $i < $this->_valueCount; ++$i) {
for ($j = 0; $j <= $order; ++$j) {
$A[$i][$j] = pow($xValues[$i], $j);
}
}
for ($i=0; $i < $this->_valueCount; ++$i) {
$B[$i] = array($yValues[$i]);
}
$matrixA = new Matrix($A);
$matrixB = new Matrix($B);
$C = $matrixA->solve($matrixB);
/**
* Execute the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param int $order Order of Polynomial for this regression
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
private function polynomialRegression($order, $yValues, $xValues, $const)
{
// calculate sums
$x_sum = array_sum($xValues);
$y_sum = array_sum($yValues);
$xx_sum = $xy_sum = 0;
for ($i = 0; $i < $this->valueCount; ++$i) {
$xy_sum += $xValues[$i] * $yValues[$i];
$xx_sum += $xValues[$i] * $xValues[$i];
$yy_sum += $yValues[$i] * $yValues[$i];
}
/*
* This routine uses logic from the PHP port of polyfit version 0.1
* written by Michael Bommarito and Paul Meagher
*
* The function fits a polynomial function of order $order through
* a series of x-y data points using least squares.
*
*/
for ($i = 0; $i < $this->valueCount; ++$i) {
for ($j = 0; $j <= $order; ++$j) {
$A[$i][$j] = pow($xValues[$i], $j);
}
}
for ($i=0; $i < $this->valueCount; ++$i) {
$B[$i] = array($yValues[$i]);
}
$matrixA = new Matrix($A);
$matrixB = new Matrix($B);
$C = $matrixA->solve($matrixB);
$coefficients = array();
for($i = 0; $i < $C->m; ++$i) {
$r = $C->get($i, 0);
if (abs($r) <= pow(10, -9)) {
$r = 0;
}
$coefficients[] = $r;
}
$coefficients = array();
for ($i = 0; $i < $C->m; ++$i) {
$r = $C->get($i, 0);
if (abs($r) <= pow(10, -9)) {
$r = 0;
}
$coefficients[] = $r;
}
$this->_intersect = array_shift($coefficients);
$this->_slope = $coefficients;
$this->intersect = array_shift($coefficients);
$this->_slope = $coefficients;
$this->_calculateGoodnessOfFit($x_sum,$y_sum,$xx_sum,$yy_sum,$xy_sum);
foreach($this->_xValues as $xKey => $xValue) {
$this->_yBestFitValues[$xKey] = $this->getValueOfYForX($xValue);
}
} // function _polynomial_regression()
$this->calculateGoodnessOfFit($x_sum, $y_sum, $xx_sum, $yy_sum, $xy_sum);
foreach ($this->xValues as $xKey => $xValue) {
$this->yBestFitValues[$xKey] = $this->getValueOfYForX($xValue);
}
}
/**
* Define the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param int $order Order of Polynomial for this regression
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
function __construct($order, $yValues, $xValues=array(), $const=True) {
if (parent::__construct($yValues, $xValues) !== False) {
if ($order < $this->_valueCount) {
$this->_bestFitType .= '_'.$order;
$this->_order = $order;
$this->_polynomial_regression($order, $yValues, $xValues, $const);
if (($this->getGoodnessOfFit() < 0.0) || ($this->getGoodnessOfFit() > 1.0)) {
$this->_error = True;
}
} else {
$this->_error = True;
}
}
} // function __construct()
} // class polynomialBestFit
/**
* Define the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param int $order Order of Polynomial for this regression
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
public function __construct($order, $yValues, $xValues = array(), $const = true)
{
if (parent::__construct($yValues, $xValues) !== false) {
if ($order < $this->valueCount) {
$this->bestFitType .= '_'.$order;
$this->order = $order;
$this->polynomialRegression($order, $yValues, $xValues, $const);
if (($this->getGoodnessOfFit() < 0.0) || ($this->getGoodnessOfFit() > 1.0)) {
$this->_error = true;
}
} else {
$this->_error = true;
}
}
}
}

View File

@@ -1,8 +1,11 @@
<?php
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
/**
* PHPExcel
* PHPExcel_Power_Best_Fit
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,123 +23,116 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Trend
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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##
*/
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
/**
* PHPExcel_Power_Best_Fit
*
* @category PHPExcel
* @package PHPExcel_Shared_Trend
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
{
/**
* Algorithm type to use for best-fit
* (Name of this trend class)
*
* @var string
**/
protected $_bestFitType = 'power';
/**
* Algorithm type to use for best-fit
* (Name of this trend class)
*
* @var string
**/
protected $bestFitType = 'power';
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
**/
public function getValueOfYForX($xValue) {
return $this->getIntersect() * pow(($xValue - $this->_Xoffset),$this->getSlope());
} // function getValueOfYForX()
/**
* Return the Y-Value for a specified value of X
*
* @param float $xValue X-Value
* @return float Y-Value
**/
public function getValueOfYForX($xValue)
{
return $this->getIntersect() * pow(($xValue - $this->xOffset), $this->getSlope());
}
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
**/
public function getValueOfXForY($yValue) {
return pow((($yValue + $this->_Yoffset) / $this->getIntersect()),(1 / $this->getSlope()));
} // function getValueOfXForY()
/**
* Return the X-Value for a specified value of Y
*
* @param float $yValue Y-Value
* @return float X-Value
**/
public function getValueOfXForY($yValue)
{
return pow((($yValue + $this->yOffset) / $this->getIntersect()), (1 / $this->getSlope()));
}
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getEquation($dp=0) {
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
/**
* Return the Equation of the best-fit line
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getEquation($dp = 0)
{
$slope = $this->getSlope($dp);
$intersect = $this->getIntersect($dp);
return 'Y = '.$intersect.' * X^'.$slope;
} // function getEquation()
return 'Y = ' . $intersect . ' * X^' . $slope;
}
/**
* Return the Value of X where it intersects Y = 0
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getIntersect($dp=0) {
if ($dp != 0) {
return round(exp($this->_intersect),$dp);
}
return exp($this->_intersect);
} // function getIntersect()
/**
* Return the Value of X where it intersects Y = 0
*
* @param int $dp Number of places of decimal precision to display
* @return string
**/
public function getIntersect($dp = 0)
{
if ($dp != 0) {
return round(exp($this->intersect), $dp);
}
return exp($this->intersect);
}
/**
* Execute the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
private function _power_regression($yValues, $xValues, $const) {
foreach($xValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
foreach($yValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
/**
* Execute the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
private function powerRegression($yValues, $xValues, $const)
{
foreach ($xValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
foreach ($yValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
$this->_leastSquareFit($yValues, $xValues, $const);
} // function _power_regression()
$this->leastSquareFit($yValues, $xValues, $const);
}
/**
* Define the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
function __construct($yValues, $xValues=array(), $const=True) {
if (parent::__construct($yValues, $xValues) !== False) {
$this->_power_regression($yValues, $xValues, $const);
}
} // function __construct()
} // class powerBestFit
/**
* Define the regression and calculate the goodness of fit for a set of X and Y data values
*
* @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression
* @param boolean $const
*/
public function __construct($yValues, $xValues = array(), $const = true)
{
if (parent::__construct($yValues, $xValues) !== false) {
$this->powerRegression($yValues, $xValues, $const);
}
}
}

View File

@@ -1,8 +1,15 @@
<?php
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/linearBestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/logarithmicBestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/exponentialBestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/powerBestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/polynomialBestFitClass.php';
/**
* PHPExcel
* PHPExcel_trendClass
*
* Copyright (c) 2006 - 2014 PHPExcel
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,137 +27,121 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Trend
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @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##
*/
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/linearBestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/logarithmicBestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/exponentialBestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/powerBestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/polynomialBestFitClass.php';
/**
* PHPExcel_trendClass
*
* @category PHPExcel
* @package PHPExcel_Shared_Trend
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class trendClass
{
const TREND_LINEAR = 'Linear';
const TREND_LOGARITHMIC = 'Logarithmic';
const TREND_EXPONENTIAL = 'Exponential';
const TREND_POWER = 'Power';
const TREND_POLYNOMIAL_2 = 'Polynomial_2';
const TREND_POLYNOMIAL_3 = 'Polynomial_3';
const TREND_POLYNOMIAL_4 = 'Polynomial_4';
const TREND_POLYNOMIAL_5 = 'Polynomial_5';
const TREND_POLYNOMIAL_6 = 'Polynomial_6';
const TREND_BEST_FIT = 'Bestfit';
const TREND_BEST_FIT_NO_POLY = 'Bestfit_no_Polynomials';
const TREND_LINEAR = 'Linear';
const TREND_LOGARITHMIC = 'Logarithmic';
const TREND_EXPONENTIAL = 'Exponential';
const TREND_POWER = 'Power';
const TREND_POLYNOMIAL_2 = 'Polynomial_2';
const TREND_POLYNOMIAL_3 = 'Polynomial_3';
const TREND_POLYNOMIAL_4 = 'Polynomial_4';
const TREND_POLYNOMIAL_5 = 'Polynomial_5';
const TREND_POLYNOMIAL_6 = 'Polynomial_6';
const TREND_BEST_FIT = 'Bestfit';
const TREND_BEST_FIT_NO_POLY = 'Bestfit_no_Polynomials';
/**
* Names of the best-fit trend analysis methods
*
* @var string[]
**/
private static $_trendTypes = array( self::TREND_LINEAR,
self::TREND_LOGARITHMIC,
self::TREND_EXPONENTIAL,
self::TREND_POWER
);
/**
* Names of the best-fit trend polynomial orders
*
* @var string[]
**/
private static $_trendTypePolyOrders = array( self::TREND_POLYNOMIAL_2,
self::TREND_POLYNOMIAL_3,
self::TREND_POLYNOMIAL_4,
self::TREND_POLYNOMIAL_5,
self::TREND_POLYNOMIAL_6
);
/**
* Names of the best-fit trend analysis methods
*
* @var string[]
**/
private static $trendTypes = array(
self::TREND_LINEAR,
self::TREND_LOGARITHMIC,
self::TREND_EXPONENTIAL,
self::TREND_POWER
);
/**
* Cached results for each method when trying to identify which provides the best fit
*
* @var PHPExcel_Best_Fit[]
**/
private static $_trendCache = array();
/**
* Names of the best-fit trend polynomial orders
*
* @var string[]
**/
private static $trendTypePolynomialOrders = array(
self::TREND_POLYNOMIAL_2,
self::TREND_POLYNOMIAL_3,
self::TREND_POLYNOMIAL_4,
self::TREND_POLYNOMIAL_5,
self::TREND_POLYNOMIAL_6
);
/**
* Cached results for each method when trying to identify which provides the best fit
*
* @var PHPExcel_Best_Fit[]
**/
private static $trendCache = array();
public static function calculate($trendType=self::TREND_BEST_FIT, $yValues, $xValues=array(), $const=True) {
// Calculate number of points in each dataset
$nY = count($yValues);
$nX = count($xValues);
public static function calculate($trendType = self::TREND_BEST_FIT, $yValues, $xValues = array(), $const = true)
{
// Calculate number of points in each dataset
$nY = count($yValues);
$nX = count($xValues);
// Define X Values if necessary
if ($nX == 0) {
$xValues = range(1,$nY);
$nX = $nY;
} elseif ($nY != $nX) {
// Ensure both arrays of points are the same size
trigger_error("trend(): Number of elements in coordinate arrays do not match.", E_USER_ERROR);
}
// Define X Values if necessary
if ($nX == 0) {
$xValues = range(1, $nY);
$nX = $nY;
} elseif ($nY != $nX) {
// Ensure both arrays of points are the same size
trigger_error("trend(): Number of elements in coordinate arrays do not match.", E_USER_ERROR);
}
$key = md5($trendType.$const.serialize($yValues).serialize($xValues));
// Determine which trend method has been requested
switch ($trendType) {
// Instantiate and return the class for the requested trend method
case self::TREND_LINEAR :
case self::TREND_LOGARITHMIC :
case self::TREND_EXPONENTIAL :
case self::TREND_POWER :
if (!isset(self::$_trendCache[$key])) {
$className = 'PHPExcel_'.$trendType.'_Best_Fit';
self::$_trendCache[$key] = new $className($yValues,$xValues,$const);
}
return self::$_trendCache[$key];
break;
case self::TREND_POLYNOMIAL_2 :
case self::TREND_POLYNOMIAL_3 :
case self::TREND_POLYNOMIAL_4 :
case self::TREND_POLYNOMIAL_5 :
case self::TREND_POLYNOMIAL_6 :
if (!isset(self::$_trendCache[$key])) {
$order = substr($trendType,-1);
self::$_trendCache[$key] = new PHPExcel_Polynomial_Best_Fit($order,$yValues,$xValues,$const);
}
return self::$_trendCache[$key];
break;
case self::TREND_BEST_FIT :
case self::TREND_BEST_FIT_NO_POLY :
// If the request is to determine the best fit regression, then we test each trend line in turn
// Start by generating an instance of each available trend method
foreach(self::$_trendTypes as $trendMethod) {
$className = 'PHPExcel_'.$trendMethod.'BestFit';
$bestFit[$trendMethod] = new $className($yValues,$xValues,$const);
$bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
}
if ($trendType != self::TREND_BEST_FIT_NO_POLY) {
foreach(self::$_trendTypePolyOrders as $trendMethod) {
$order = substr($trendMethod,-1);
$bestFit[$trendMethod] = new PHPExcel_Polynomial_Best_Fit($order,$yValues,$xValues,$const);
if ($bestFit[$trendMethod]->getError()) {
unset($bestFit[$trendMethod]);
} else {
$bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
}
}
}
// Determine which of our trend lines is the best fit, and then we return the instance of that trend class
arsort($bestFitValue);
$bestFitType = key($bestFitValue);
return $bestFit[$bestFitType];
break;
default :
return false;
}
} // function calculate()
} // class trendClass
$key = md5($trendType.$const.serialize($yValues).serialize($xValues));
// Determine which trend method has been requested
switch ($trendType) {
// Instantiate and return the class for the requested trend method
case self::TREND_LINEAR:
case self::TREND_LOGARITHMIC:
case self::TREND_EXPONENTIAL:
case self::TREND_POWER:
if (!isset(self::$trendCache[$key])) {
$className = 'PHPExcel_'.$trendType.'_Best_Fit';
self::$trendCache[$key] = new $className($yValues, $xValues, $const);
}
return self::$trendCache[$key];
case self::TREND_POLYNOMIAL_2:
case self::TREND_POLYNOMIAL_3:
case self::TREND_POLYNOMIAL_4:
case self::TREND_POLYNOMIAL_5:
case self::TREND_POLYNOMIAL_6:
if (!isset(self::$trendCache[$key])) {
$order = substr($trendType, -1);
self::$trendCache[$key] = new PHPExcel_Polynomial_Best_Fit($order, $yValues, $xValues, $const);
}
return self::$trendCache[$key];
case self::TREND_BEST_FIT:
case self::TREND_BEST_FIT_NO_POLY:
// If the request is to determine the best fit regression, then we test each trend line in turn
// Start by generating an instance of each available trend method
foreach (self::$trendTypes as $trendMethod) {
$className = 'PHPExcel_'.$trendMethod.'BestFit';
$bestFit[$trendMethod] = new $className($yValues, $xValues, $const);
$bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
}
if ($trendType != self::TREND_BEST_FIT_NO_POLY) {
foreach (self::$trendTypePolynomialOrders as $trendMethod) {
$order = substr($trendMethod, -1);
$bestFit[$trendMethod] = new PHPExcel_Polynomial_Best_Fit($order, $yValues, $xValues, $const);
if ($bestFit[$trendMethod]->getError()) {
unset($bestFit[$trendMethod]);
} else {
$bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
}
}
}
// Determine which of our trend lines is the best fit, and then we return the instance of that trend class
arsort($bestFitValue);
$bestFitType = key($bestFitValue);
return $bestFit[$bestFitType];
default:
return false;
}
}
}