187 changed files with 77572 additions and 0 deletions
File diff suppressed because it is too large
@ -0,0 +1,806 @@ |
|||||
|
<?php |
||||
|
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
||||
|
|
||||
|
/** |
||||
|
* Converts to and from JSON format. |
||||
|
* |
||||
|
* JSON (JavaScript Object Notation) is a lightweight data-interchange |
||||
|
* format. It is easy for humans to read and write. It is easy for machines |
||||
|
* to parse and generate. It is based on a subset of the JavaScript |
||||
|
* Programming Language, Standard ECMA-262 3rd Edition - December 1999. |
||||
|
* This feature can also be found in Python. JSON is a text format that is |
||||
|
* completely language independent but uses conventions that are familiar |
||||
|
* to programmers of the C-family of languages, including C, C++, C#, Java, |
||||
|
* JavaScript, Perl, TCL, and many others. These properties make JSON an |
||||
|
* ideal data-interchange language. |
||||
|
* |
||||
|
* This package provides a simple encoder and decoder for JSON notation. It |
||||
|
* is intended for use with client-side Javascript applications that make |
||||
|
* use of HTTPRequest to perform server communication functions - data can |
||||
|
* be encoded into JSON notation for use in a client-side javascript, or |
||||
|
* decoded from incoming Javascript requests. JSON format is native to |
||||
|
* Javascript, and can be directly eval()'ed with no further parsing |
||||
|
* overhead |
||||
|
* |
||||
|
* All strings should be in ASCII or UTF-8 format! |
||||
|
* |
||||
|
* LICENSE: Redistribution and use in source and binary forms, with or |
||||
|
* without modification, are permitted provided that the following |
||||
|
* conditions are met: Redistributions of source code must retain the |
||||
|
* above copyright notice, this list of conditions and the following |
||||
|
* disclaimer. Redistributions in binary form must reproduce the above |
||||
|
* copyright notice, this list of conditions and the following disclaimer |
||||
|
* in the documentation and/or other materials provided with the |
||||
|
* distribution. |
||||
|
* |
||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
||||
|
* NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
||||
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
||||
|
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
||||
|
* DAMAGE. |
||||
|
* |
||||
|
* @category |
||||
|
* @package Services_JSON |
||||
|
* @author Michal Migurski <mike-json@teczno.com> |
||||
|
* @author Matt Knapp <mdknapp[at]gmail[dot]com> |
||||
|
* @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com> |
||||
|
* @copyright 2005 Michal Migurski |
||||
|
* @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $ |
||||
|
* @license http://www.opensource.org/licenses/bsd-license.php |
||||
|
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* Marker constant for Services_JSON::decode(), used to flag stack state |
||||
|
*/ |
||||
|
define('SERVICES_JSON_SLICE', 1); |
||||
|
|
||||
|
/** |
||||
|
* Marker constant for Services_JSON::decode(), used to flag stack state |
||||
|
*/ |
||||
|
define('SERVICES_JSON_IN_STR', 2); |
||||
|
|
||||
|
/** |
||||
|
* Marker constant for Services_JSON::decode(), used to flag stack state |
||||
|
*/ |
||||
|
define('SERVICES_JSON_IN_ARR', 3); |
||||
|
|
||||
|
/** |
||||
|
* Marker constant for Services_JSON::decode(), used to flag stack state |
||||
|
*/ |
||||
|
define('SERVICES_JSON_IN_OBJ', 4); |
||||
|
|
||||
|
/** |
||||
|
* Marker constant for Services_JSON::decode(), used to flag stack state |
||||
|
*/ |
||||
|
define('SERVICES_JSON_IN_CMT', 5); |
||||
|
|
||||
|
/** |
||||
|
* Behavior switch for Services_JSON::decode() |
||||
|
*/ |
||||
|
define('SERVICES_JSON_LOOSE_TYPE', 16); |
||||
|
|
||||
|
/** |
||||
|
* Behavior switch for Services_JSON::decode() |
||||
|
*/ |
||||
|
define('SERVICES_JSON_SUPPRESS_ERRORS', 32); |
||||
|
|
||||
|
/** |
||||
|
* Converts to and from JSON format. |
||||
|
* |
||||
|
* Brief example of use: |
||||
|
* |
||||
|
* <code> |
||||
|
* // create a new instance of Services_JSON |
||||
|
* $json = new Services_JSON(); |
||||
|
* |
||||
|
* // convert a complexe value to JSON notation, and send it to the browser |
||||
|
* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4))); |
||||
|
* $output = $json->encode($value); |
||||
|
* |
||||
|
* print($output); |
||||
|
* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]] |
||||
|
* |
||||
|
* // accept incoming POST data, assumed to be in JSON notation |
||||
|
* $input = file_get_contents('php://input', 1000000); |
||||
|
* $value = $json->decode($input); |
||||
|
* </code> |
||||
|
*/ |
||||
|
class Services_JSON |
||||
|
{ |
||||
|
/** |
||||
|
* constructs a new JSON instance |
||||
|
* |
||||
|
* @param int $use object behavior flags; combine with boolean-OR |
||||
|
* |
||||
|
* possible values: |
||||
|
* - SERVICES_JSON_LOOSE_TYPE: loose typing. |
||||
|
* "{...}" syntax creates associative arrays |
||||
|
* instead of objects in decode(). |
||||
|
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression. |
||||
|
* Values which can't be encoded (e.g. resources) |
||||
|
* appear as NULL instead of throwing errors. |
||||
|
* By default, a deeply-nested resource will |
||||
|
* bubble up with an error, so all return values |
||||
|
* from encode() should be checked with isError() |
||||
|
*/ |
||||
|
function Services_JSON($use = 0) |
||||
|
{ |
||||
|
$this->use = $use; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* convert a string from one UTF-16 char to one UTF-8 char |
||||
|
* |
||||
|
* Normally should be handled by mb_convert_encoding, but |
||||
|
* provides a slower PHP-only method for installations |
||||
|
* that lack the multibye string extension. |
||||
|
* |
||||
|
* @param string $utf16 UTF-16 character |
||||
|
* @return string UTF-8 character |
||||
|
* @access private |
||||
|
*/ |
||||
|
function utf162utf8($utf16) |
||||
|
{ |
||||
|
// oh please oh please oh please oh please oh please |
||||
|
if(function_exists('mb_convert_encoding')) { |
||||
|
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); |
||||
|
} |
||||
|
|
||||
|
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1}); |
||||
|
|
||||
|
switch(true) { |
||||
|
case ((0x7F & $bytes) == $bytes): |
||||
|
// this case should never be reached, because we are in ASCII range |
||||
|
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
return chr(0x7F & $bytes); |
||||
|
|
||||
|
case (0x07FF & $bytes) == $bytes: |
||||
|
// return a 2-byte UTF-8 character |
||||
|
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
return chr(0xC0 | (($bytes >> 6) & 0x1F)) |
||||
|
. chr(0x80 | ($bytes & 0x3F)); |
||||
|
|
||||
|
case (0xFFFF & $bytes) == $bytes: |
||||
|
// return a 3-byte UTF-8 character |
||||
|
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
return chr(0xE0 | (($bytes >> 12) & 0x0F)) |
||||
|
. chr(0x80 | (($bytes >> 6) & 0x3F)) |
||||
|
. chr(0x80 | ($bytes & 0x3F)); |
||||
|
} |
||||
|
|
||||
|
// ignoring UTF-32 for now, sorry |
||||
|
return ''; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* convert a string from one UTF-8 char to one UTF-16 char |
||||
|
* |
||||
|
* Normally should be handled by mb_convert_encoding, but |
||||
|
* provides a slower PHP-only method for installations |
||||
|
* that lack the multibye string extension. |
||||
|
* |
||||
|
* @param string $utf8 UTF-8 character |
||||
|
* @return string UTF-16 character |
||||
|
* @access private |
||||
|
*/ |
||||
|
function utf82utf16($utf8) |
||||
|
{ |
||||
|
// oh please oh please oh please oh please oh please |
||||
|
if(function_exists('mb_convert_encoding')) { |
||||
|
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); |
||||
|
} |
||||
|
|
||||
|
switch(strlen($utf8)) { |
||||
|
case 1: |
||||
|
// this case should never be reached, because we are in ASCII range |
||||
|
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
return $utf8; |
||||
|
|
||||
|
case 2: |
||||
|
// return a UTF-16 character from a 2-byte UTF-8 char |
||||
|
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
return chr(0x07 & (ord($utf8{0}) >> 2)) |
||||
|
. chr((0xC0 & (ord($utf8{0}) << 6)) |
||||
|
| (0x3F & ord($utf8{1}))); |
||||
|
|
||||
|
case 3: |
||||
|
// return a UTF-16 character from a 3-byte UTF-8 char |
||||
|
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
return chr((0xF0 & (ord($utf8{0}) << 4)) |
||||
|
| (0x0F & (ord($utf8{1}) >> 2))) |
||||
|
. chr((0xC0 & (ord($utf8{1}) << 6)) |
||||
|
| (0x7F & ord($utf8{2}))); |
||||
|
} |
||||
|
|
||||
|
// ignoring UTF-32 for now, sorry |
||||
|
return ''; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* encodes an arbitrary variable into JSON format |
||||
|
* |
||||
|
* @param mixed $var any number, boolean, string, array, or object to be encoded. |
||||
|
* see argument 1 to Services_JSON() above for array-parsing behavior. |
||||
|
* if var is a strng, note that encode() always expects it |
||||
|
* to be in ASCII or UTF-8 format! |
||||
|
* |
||||
|
* @return mixed JSON string representation of input var or an error if a problem occurs |
||||
|
* @access public |
||||
|
*/ |
||||
|
function encode($var) |
||||
|
{ |
||||
|
switch (gettype($var)) { |
||||
|
case 'boolean': |
||||
|
return $var ? 'true' : 'false'; |
||||
|
|
||||
|
case 'NULL': |
||||
|
return 'null'; |
||||
|
|
||||
|
case 'integer': |
||||
|
return (int) $var; |
||||
|
|
||||
|
case 'double': |
||||
|
case 'float': |
||||
|
return (float) $var; |
||||
|
|
||||
|
case 'string': |
||||
|
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT |
||||
|
$ascii = ''; |
||||
|
$strlen_var = strlen($var); |
||||
|
|
||||
|
/* |
||||
|
* Iterate over every character in the string, |
||||
|
* escaping with a slash or encoding to UTF-8 where necessary |
||||
|
*/ |
||||
|
for ($c = 0; $c < $strlen_var; ++$c) { |
||||
|
|
||||
|
$ord_var_c = ord($var{$c}); |
||||
|
|
||||
|
switch (true) { |
||||
|
case $ord_var_c == 0x08: |
||||
|
$ascii .= '\b'; |
||||
|
break; |
||||
|
case $ord_var_c == 0x09: |
||||
|
$ascii .= '\t'; |
||||
|
break; |
||||
|
case $ord_var_c == 0x0A: |
||||
|
$ascii .= '\n'; |
||||
|
break; |
||||
|
case $ord_var_c == 0x0C: |
||||
|
$ascii .= '\f'; |
||||
|
break; |
||||
|
case $ord_var_c == 0x0D: |
||||
|
$ascii .= '\r'; |
||||
|
break; |
||||
|
|
||||
|
case $ord_var_c == 0x22: |
||||
|
case $ord_var_c == 0x2F: |
||||
|
case $ord_var_c == 0x5C: |
||||
|
// double quote, slash, slosh |
||||
|
$ascii .= '\\'.$var{$c}; |
||||
|
break; |
||||
|
|
||||
|
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
||||
|
// characters U-00000000 - U-0000007F (same as ASCII) |
||||
|
$ascii .= $var{$c}; |
||||
|
break; |
||||
|
|
||||
|
case (($ord_var_c & 0xE0) == 0xC0): |
||||
|
// characters U-00000080 - U-000007FF, mask 110X XX XX |
||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
$char = pack('C*', $ord_var_c, ord($var{$c + 1})); |
||||
|
$c += 1; |
||||
|
$utf16 = $this->utf82utf16($char); |
||||
|
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
||||
|
break; |
||||
|
|
||||
|
case (($ord_var_c & 0xF0) == 0xE0): |
||||
|
// characters U-00000800 - U-0000FFFF, mask 1110X XX X |
||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
$char = pack('C*', $ord_var_c, |
||||
|
ord($var{$c + 1}), |
||||
|
ord($var{$c + 2})); |
||||
|
$c += 2; |
||||
|
$utf16 = $this->utf82utf16($char); |
||||
|
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
||||
|
break; |
||||
|
|
||||
|
case (($ord_var_c & 0xF8) == 0xF0): |
||||
|
// characters U-00010000 - U-001FFFFF, mask 11110X XX |
||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
$char = pack('C*', $ord_var_c, |
||||
|
ord($var{$c + 1}), |
||||
|
ord($var{$c + 2}), |
||||
|
ord($var{$c + 3})); |
||||
|
$c += 3; |
||||
|
$utf16 = $this->utf82utf16($char); |
||||
|
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
||||
|
break; |
||||
|
|
||||
|
case (($ord_var_c & 0xFC) == 0xF8): |
||||
|
// characters U-00200000 - U-03FFFFFF, mask 111110XX |
||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
$char = pack('C*', $ord_var_c, |
||||
|
ord($var{$c + 1}), |
||||
|
ord($var{$c + 2}), |
||||
|
ord($var{$c + 3}), |
||||
|
ord($var{$c + 4})); |
||||
|
$c += 4; |
||||
|
$utf16 = $this->utf82utf16($char); |
||||
|
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
||||
|
break; |
||||
|
|
||||
|
case (($ord_var_c & 0xFE) == 0xFC): |
||||
|
// characters U-04000000 - U-7FFFFFFF, mask 1111110X |
||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
$char = pack('C*', $ord_var_c, |
||||
|
ord($var{$c + 1}), |
||||
|
ord($var{$c + 2}), |
||||
|
ord($var{$c + 3}), |
||||
|
ord($var{$c + 4}), |
||||
|
ord($var{$c + 5})); |
||||
|
$c += 5; |
||||
|
$utf16 = $this->utf82utf16($char); |
||||
|
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return '"'.$ascii.'"'; |
||||
|
|
||||
|
case 'array': |
||||
|
/* |
||||
|
* As per JSON spec if any array key is not an integer |
||||
|
* we must treat the the whole array as an object. We |
||||
|
* also try to catch a sparsely populated associative |
||||
|
* array with numeric keys here because some JS engines |
||||
|
* will create an array with empty indexes up to |
||||
|
* max_index which can cause memory issues and because |
||||
|
* the keys, which may be relevant, will be remapped |
||||
|
* otherwise. |
||||
|
* |
||||
|
* As per the ECMA and JSON specification an object may |
||||
|
* have any string as a property. Unfortunately due to |
||||
|
* a hole in the ECMA specification if the key is a |
||||
|
* ECMA reserved word or starts with a digit the |
||||
|
* parameter is only accessible using ECMAScript's |
||||
|
* bracket notation. |
||||
|
*/ |
||||
|
|
||||
|
// treat as a JSON object |
||||
|
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) { |
||||
|
$properties = array_map(array($this, 'name_value'), |
||||
|
array_keys($var), |
||||
|
array_values($var)); |
||||
|
|
||||
|
foreach($properties as $property) { |
||||
|
if(Services_JSON::isError($property)) { |
||||
|
return $property; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return '{' . join(',', $properties) . '}'; |
||||
|
} |
||||
|
|
||||
|
// treat it like a regular array |
||||
|
$elements = array_map(array($this, 'encode'), $var); |
||||
|
|
||||
|
foreach($elements as $element) { |
||||
|
if(Services_JSON::isError($element)) { |
||||
|
return $element; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return '[' . join(',', $elements) . ']'; |
||||
|
|
||||
|
case 'object': |
||||
|
$vars = get_object_vars($var); |
||||
|
|
||||
|
$properties = array_map(array($this, 'name_value'), |
||||
|
array_keys($vars), |
||||
|
array_values($vars)); |
||||
|
|
||||
|
foreach($properties as $property) { |
||||
|
if(Services_JSON::isError($property)) { |
||||
|
return $property; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return '{' . join(',', $properties) . '}'; |
||||
|
|
||||
|
default: |
||||
|
return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) |
||||
|
? 'null' |
||||
|
: new Services_JSON_Error(gettype($var)." can not be encoded as JSON string"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* array-walking function for use in generating JSON-formatted name-value pairs |
||||
|
* |
||||
|
* @param string $name name of key to use |
||||
|
* @param mixed $value reference to an array element to be encoded |
||||
|
* |
||||
|
* @return string JSON-formatted name-value pair, like '"name":value' |
||||
|
* @access private |
||||
|
*/ |
||||
|
function name_value($name, $value) |
||||
|
{ |
||||
|
$encoded_value = $this->encode($value); |
||||
|
|
||||
|
if(Services_JSON::isError($encoded_value)) { |
||||
|
return $encoded_value; |
||||
|
} |
||||
|
|
||||
|
return $this->encode(strval($name)) . ':' . $encoded_value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* reduce a string by removing leading and trailing comments and whitespace |
||||
|
* |
||||
|
* @param $str string string value to strip of comments and whitespace |
||||
|
* |
||||
|
* @return string string value stripped of comments and whitespace |
||||
|
* @access private |
||||
|
*/ |
||||
|
function reduce_string($str) |
||||
|
{ |
||||
|
$str = preg_replace(array( |
||||
|
|
||||
|
// eliminate single line comments in '// ...' form |
||||
|
'#^\s*//(.+)$#m', |
||||
|
|
||||
|
// eliminate multi-line comments in '/* ... */' form, at start of string |
||||
|
'#^\s*/\*(.+)\*/#Us', |
||||
|
|
||||
|
// eliminate multi-line comments in '/* ... */' form, at end of string |
||||
|
'#/\*(.+)\*/\s*$#Us' |
||||
|
|
||||
|
), '', $str); |
||||
|
|
||||
|
// eliminate extraneous space |
||||
|
return trim($str); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* decodes a JSON string into appropriate variable |
||||
|
* |
||||
|
* @param string $str JSON-formatted string |
||||
|
* |
||||
|
* @return mixed number, boolean, string, array, or object |
||||
|
* corresponding to given JSON input string. |
||||
|
* See argument 1 to Services_JSON() above for object-output behavior. |
||||
|
* Note that decode() always returns strings |
||||
|
* in ASCII or UTF-8 format! |
||||
|
* @access public |
||||
|
*/ |
||||
|
function decode($str) |
||||
|
{ |
||||
|
$str = $this->reduce_string($str); |
||||
|
|
||||
|
switch (strtolower($str)) { |
||||
|
case 'true': |
||||
|
return true; |
||||
|
|
||||
|
case 'false': |
||||
|
return false; |
||||
|
|
||||
|
case 'null': |
||||
|
return null; |
||||
|
|
||||
|
default: |
||||
|
$m = array(); |
||||
|
|
||||
|
if (is_numeric($str)) { |
||||
|
// Lookie-loo, it's a number |
||||
|
|
||||
|
// This would work on its own, but I'm trying to be |
||||
|
// good about returning integers where appropriate: |
||||
|
// return (float)$str; |
||||
|
|
||||
|
// Return float or int, as appropriate |
||||
|
return ((float)$str == (integer)$str) |
||||
|
? (integer)$str |
||||
|
: (float)$str; |
||||
|
|
||||
|
} elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) { |
||||
|
// STRINGS RETURNED IN UTF-8 FORMAT |
||||
|
$delim = substr($str, 0, 1); |
||||
|
$chrs = substr($str, 1, -1); |
||||
|
$utf8 = ''; |
||||
|
$strlen_chrs = strlen($chrs); |
||||
|
|
||||
|
for ($c = 0; $c < $strlen_chrs; ++$c) { |
||||
|
|
||||
|
$substr_chrs_c_2 = substr($chrs, $c, 2); |
||||
|
$ord_chrs_c = ord($chrs{$c}); |
||||
|
|
||||
|
switch (true) { |
||||
|
case $substr_chrs_c_2 == '\b': |
||||
|
$utf8 .= chr(0x08); |
||||
|
++$c; |
||||
|
break; |
||||
|
case $substr_chrs_c_2 == '\t': |
||||
|
$utf8 .= chr(0x09); |
||||
|
++$c; |
||||
|
break; |
||||
|
case $substr_chrs_c_2 == '\n': |
||||
|
$utf8 .= chr(0x0A); |
||||
|
++$c; |
||||
|
break; |
||||
|
case $substr_chrs_c_2 == '\f': |
||||
|
$utf8 .= chr(0x0C); |
||||
|
++$c; |
||||
|
break; |
||||
|
case $substr_chrs_c_2 == '\r': |
||||
|
$utf8 .= chr(0x0D); |
||||
|
++$c; |
||||
|
break; |
||||
|
|
||||
|
case $substr_chrs_c_2 == '\\"': |
||||
|
case $substr_chrs_c_2 == '\\\'': |
||||
|
case $substr_chrs_c_2 == '\\\\': |
||||
|
case $substr_chrs_c_2 == '\\/': |
||||
|
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') || |
||||
|
($delim == "'" && $substr_chrs_c_2 != '\\"')) { |
||||
|
$utf8 .= $chrs{++$c}; |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)): |
||||
|
// single, escaped unicode character |
||||
|
$utf16 = chr(hexdec(substr($chrs, ($c + 2), 2))) |
||||
|
. chr(hexdec(substr($chrs, ($c + 4), 2))); |
||||
|
$utf8 .= $this->utf162utf8($utf16); |
||||
|
$c += 5; |
||||
|
break; |
||||
|
|
||||
|
case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F): |
||||
|
$utf8 .= $chrs{$c}; |
||||
|
break; |
||||
|
|
||||
|
case ($ord_chrs_c & 0xE0) == 0xC0: |
||||
|
// characters U-00000080 - U-000007FF, mask 110XX X XX |
||||
|
//see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
$utf8 .= substr($chrs, $c, 2); |
||||
|
++$c; |
||||
|
break; |
||||
|
|
||||
|
case ($ord_chrs_c & 0xF0) == 0xE0: |
||||
|
// characters U-00000800 - U-0000FFFF, mask 1110X X XX |
||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
$utf8 .= substr($chrs, $c, 3); |
||||
|
$c += 2; |
||||
|
break; |
||||
|
|
||||
|
case ($ord_chrs_c & 0xF8) == 0xF0: |
||||
|
// characters U-00010000 - U-001FFFFF, mask 11110X XX |
||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
$utf8 .= substr($chrs, $c, 4); |
||||
|
$c += 3; |
||||
|
break; |
||||
|
|
||||
|
case ($ord_chrs_c & 0xFC) == 0xF8: |
||||
|
// characters U-00200000 - U-03FFFFFF, mask 111110XX |
||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
$utf8 .= substr($chrs, $c, 5); |
||||
|
$c += 4; |
||||
|
break; |
||||
|
|
||||
|
case ($ord_chrs_c & 0xFE) == 0xFC: |
||||
|
// characters U-04000000 - U-7FFFFFFF, mask 1111110X |
||||
|
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
||||
|
$utf8 .= substr($chrs, $c, 6); |
||||
|
$c += 5; |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
return $utf8; |
||||
|
|
||||
|
} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) { |
||||
|
// array, or object notation |
||||
|
|
||||
|
if ($str{0} == '[') { |
||||
|
$stk = array(SERVICES_JSON_IN_ARR); |
||||
|
$arr = array(); |
||||
|
} else { |
||||
|
if ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
||||
|
$stk = array(SERVICES_JSON_IN_OBJ); |
||||
|
$obj = array(); |
||||
|
} else { |
||||
|
$stk = array(SERVICES_JSON_IN_OBJ); |
||||
|
$obj = new stdClass(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
array_push($stk, array('what' => SERVICES_JSON_SLICE, |
||||
|
'where' => 0, |
||||
|
'delim' => false)); |
||||
|
|
||||
|
$chrs = substr($str, 1, -1); |
||||
|
$chrs = $this->reduce_string($chrs); |
||||
|
|
||||
|
if ($chrs == '') { |
||||
|
if (reset($stk) == SERVICES_JSON_IN_ARR) { |
||||
|
return $arr; |
||||
|
|
||||
|
} else { |
||||
|
return $obj; |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//print("\nparsing {$chrs}\n"); |
||||
|
|
||||
|
$strlen_chrs = strlen($chrs); |
||||
|
|
||||
|
for ($c = 0; $c <= $strlen_chrs; ++$c) { |
||||
|
|
||||
|
$top = end($stk); |
||||
|
$substr_chrs_c_2 = substr($chrs, $c, 2); |
||||
|
|
||||
|
if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) { |
||||
|
// found a comma that is not inside a string, array, etc., |
||||
|
// OR we've reached the end of the character list |
||||
|
$slice = substr($chrs, $top['where'], ($c - $top['where'])); |
||||
|
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false)); |
||||
|
//print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
||||
|
|
||||
|
if (reset($stk) == SERVICES_JSON_IN_ARR) { |
||||
|
// we are in an array, so just push an element onto the stack |
||||
|
array_push($arr, $this->decode($slice)); |
||||
|
|
||||
|
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) { |
||||
|
// we are in an object, so figure |
||||
|
// out the property name and set an |
||||
|
// element in an associative array, |
||||
|
// for now |
||||
|
$parts = array(); |
||||
|
|
||||
|
if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { |
||||
|
// "name":value pair |
||||
|
$key = $this->decode($parts[1]); |
||||
|
$val = $this->decode($parts[2]); |
||||
|
|
||||
|
if ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
||||
|
$obj[$key] = $val; |
||||
|
} else { |
||||
|
$obj->$key = $val; |
||||
|
} |
||||
|
} elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { |
||||
|
// name:value pair, where name is unquoted |
||||
|
$key = $parts[1]; |
||||
|
$val = $this->decode($parts[2]); |
||||
|
|
||||
|
if ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
||||
|
$obj[$key] = $val; |
||||
|
} else { |
||||
|
$obj->$key = $val; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) { |
||||
|
// found a quote, and we are not inside a string |
||||
|
array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c})); |
||||
|
//print("Found start of string at {$c}\n"); |
||||
|
|
||||
|
} elseif (($chrs{$c} == $top['delim']) && |
||||
|
($top['what'] == SERVICES_JSON_IN_STR) && |
||||
|
((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) { |
||||
|
// found a quote, we're in a string, and it's not escaped |
||||
|
// we know that it's not escaped becase there is _not_ an |
||||
|
// odd number of backslashes at the end of the string so far |
||||
|
array_pop($stk); |
||||
|
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); |
||||
|
|
||||
|
} elseif (($chrs{$c} == '[') && |
||||
|
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { |
||||
|
// found a left-bracket, and we are in an array, object, or slice |
||||
|
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false)); |
||||
|
//print("Found start of array at {$c}\n"); |
||||
|
|
||||
|
} elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) { |
||||
|
// found a right-bracket, and we're in an array |
||||
|
array_pop($stk); |
||||
|
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
||||
|
|
||||
|
} elseif (($chrs{$c} == '{') && |
||||
|
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { |
||||
|
// found a left-brace, and we are in an array, object, or slice |
||||
|
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false)); |
||||
|
//print("Found start of object at {$c}\n"); |
||||
|
|
||||
|
} elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) { |
||||
|
// found a right-brace, and we're in an object |
||||
|
array_pop($stk); |
||||
|
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
||||
|
|
||||
|
} elseif (($substr_chrs_c_2 == '/*') && |
||||
|
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { |
||||
|
// found a comment start, and we are in an array, object, or slice |
||||
|
array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false)); |
||||
|
$c++; |
||||
|
//print("Found start of comment at {$c}\n"); |
||||
|
|
||||
|
} elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) { |
||||
|
// found a comment end, and we're in one now |
||||
|
array_pop($stk); |
||||
|
$c++; |
||||
|
|
||||
|
for ($i = $top['where']; $i <= $c; ++$i) |
||||
|
$chrs = substr_replace($chrs, ' ', $i, 1); |
||||
|
|
||||
|
//print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
if (reset($stk) == SERVICES_JSON_IN_ARR) { |
||||
|
return $arr; |
||||
|
|
||||
|
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) { |
||||
|
return $obj; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @t odo Ultimately, this should just call PEAR::isError() |
||||
|
*/ |
||||
|
function isError($data, $code = null) |
||||
|
{ |
||||
|
if (class_exists('pear')) { |
||||
|
return PEAR::isError($data, $code); |
||||
|
} elseif (is_object($data) && (get_class($data) == 'services_json_error' || |
||||
|
is_subclass_of($data, 'services_json_error'))) { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (class_exists('PEAR_Error')) { |
||||
|
|
||||
|
class Services_JSON_Error extends PEAR_Error |
||||
|
{ |
||||
|
function Services_JSON_Error($message = 'unknown error', $code = null, |
||||
|
$mode = null, $options = null, $userinfo = null) |
||||
|
{ |
||||
|
parent::PEAR_Error($message, $code, $mode, $options, $userinfo); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} else { |
||||
|
|
||||
|
/** |
||||
|
* @t odo Ultimately, this class shall be descended from PEAR_Error |
||||
|
*/ |
||||
|
class Services_JSON_Error |
||||
|
{ |
||||
|
function Services_JSON_Error($message = 'unknown error', $code = null, |
||||
|
$mode = null, $options = null, $userinfo = null) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
?> |
||||
@ -0,0 +1,358 @@ |
|||||
|
<?php |
||||
|
/** File PDO.class.php * |
||||
|
* Porting of native PHP 5.1 PDO * |
||||
|
* object usable with PHP 4.X.X * |
||||
|
* and PHP 5.0.X version. * |
||||
|
* ------------------------------------ * |
||||
|
*(C) Andrea Giammarchi [2005/10/19] * |
||||
|
* ____________________________________ */ |
||||
|
|
||||
|
// check and preserve native PDO driver, for PHP4 or PHP 5.0 users |
||||
|
if(!class_exists('PDO')) { |
||||
|
|
||||
|
// SUPPORTED STATIC ENVIROMENT VARIABLES |
||||
|
define('PDO_ATTR_SERVER_VERSION', 4); // server version |
||||
|
define('PDO_ATTR_CLIENT_VERSION', 5); // client version |
||||
|
define('PDO_ATTR_SERVER_INFO', 6); // server informations |
||||
|
define('PDO_ATTR_PERSISTENT', 12); // connection mode, persistent or normal |
||||
|
|
||||
|
// SUPPORTED STATIC PDO FETCH MODE VARIABLES |
||||
|
define('PDO_FETCH_ASSOC', 2); // such mysql_fetch_assoc |
||||
|
define('PDO_FETCH_NUM', 3); // such mysql_fetch_row |
||||
|
define('PDO_FETCH_BOTH', 4); // such mysql_fetch_array |
||||
|
define('PDO_FETCH_OBJ', 5); // such mysql_fetch_object |
||||
|
|
||||
|
// UNSUPPORTED STATIC PDO FETCH MODE VARIABLES |
||||
|
define('PDO_FETCH_LAZY', 1); // usable but not supported, default is PDO_FETCH_BOTH and will be used |
||||
|
define('PDO_FETCH_BOUND', 6); // usable but not supported, default is PDO_FETCH_BOTH and will be used |
||||
|
|
||||
|
/** |
||||
|
* Class PDO |
||||
|
* PostgreSQL, SQLITE and MYSQL PDO support for PHP 4.X.X or PHP 5.0.X users, compatible with PHP 5.1.0 (RC1). |
||||
|
* |
||||
|
* DESCRIPTION [directly from http://us2.php.net/manual/en/ref.pdo.php] |
||||
|
* The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. |
||||
|
* Each database driver that implements the PDO interface can expose database-specific features as regular extension functions. |
||||
|
* Note that you cannot perform any database functions using the PDO extension by itself; |
||||
|
* you must use a database-specific PDO driver to access a database server. |
||||
|
* |
||||
|
* HOW TO USE |
||||
|
* To know how to use PDO driver and all its methods visit php.net wonderful documentation. |
||||
|
* http://us2.php.net/manual/en/ref.pdo.php |
||||
|
* In this class some methods are not available and actually this porting is only for MySQL, SQLITE and PostgreSQL. |
||||
|
* |
||||
|
* LIMITS |
||||
|
* For some reasons ( time and php used version with this class ) some PDO methods are not availables and |
||||
|
* someother are not totally supported. |
||||
|
* |
||||
|
* PDO :: UNSUPPORTED METHODS: |
||||
|
* - beginTransaction [ mysql 3 has not transaction and manage them is possible only with a direct BEGIN |
||||
|
* or COMMIT query ] |
||||
|
* - commit |
||||
|
* - rollback |
||||
|
* |
||||
|
* PDO :: NOT TOTALLY SUPPORTED METHODS: |
||||
|
* - getAttribute [ accepts only PDO_ATTR_SERVER_INFO, PDO_ATTR_SERVER_VERSION, |
||||
|
* PDO_ATTR_CLIENT_VERSION and PDO_ATTR_PERSISTENT attributes ] |
||||
|
* - setAttribute [ supports only PDO_ATTR_PERSISTENT modification ] |
||||
|
* - lastInsertId [ only fo PostgreSQL , returns only pg_last_oid ] |
||||
|
* |
||||
|
* - - - - - - - - - - - - - - - - - - - - |
||||
|
* |
||||
|
* PDOStatement :: UNSUPPORTED METHODS: |
||||
|
* - bindColumn [ is not possible to undeclare a variable and using global scope is not |
||||
|
* really a good idea ] |
||||
|
* |
||||
|
* PDOStatement :: NOT TOTALLY SUPPORTED METHODS: |
||||
|
* - getAttribute [ accepts only PDO_ATTR_SERVER_INFO, PDO_ATTR_SERVER_VERSION, |
||||
|
* PDO_ATTR_CLIENT_VERSION and PDO_ATTR_PERSISTENT attributes ] |
||||
|
* - setAttribute [ supports only PDO_ATTR_PERSISTENT modification ] |
||||
|
* - setFetchMode [ supports only PDO_FETCH_NUM, PDO_FETCH_ASSOC, PDO_FETCH_OBJ and |
||||
|
* PDO_FETCH_BOTH database reading mode ] |
||||
|
* --------------------------------------------- |
||||
|
* @Compatibility >= PHP 4 |
||||
|
* @Dependencies PDO_mysql.class.php |
||||
|
* PDO_sqlite.class.php |
||||
|
* PDOStatement_mysql.class.php |
||||
|
* PDOStatement_sqlite.class.php |
||||
|
* @Author Andrea Giammarchi |
||||
|
* @Site http://www.devpro.it/ |
||||
|
* @Mail andrea [ at ] 3site [ dot ] it |
||||
|
* @Date 2005/10/13 |
||||
|
* @LastModified 2005/12/01 21:40 |
||||
|
* @Version 0.1b - tested, supports only PostgreSQL, MySQL or SQLITE databases |
||||
|
*/ |
||||
|
class PDO { |
||||
|
|
||||
|
/** Modified on 2005/12/01 to support new PDO constants on PHP 5.1.X */ |
||||
|
const FETCH_ASSOC = PDO_FETCH_ASSOC; |
||||
|
const FETCH_NUM = PDO_FETCH_NUM; |
||||
|
const FETCH_BOTH = PDO_FETCH_BOTH; |
||||
|
const FETCH_OBJ = PDO_FETCH_OBJ; |
||||
|
const FETCH_LAZY = PDO_FETCH_LAZY; |
||||
|
const FETCH_BOUND = PDO_FETCH_BOUND; |
||||
|
const ATTR_SERVER_VERSION = PDO_ATTR_SERVER_VERSION; |
||||
|
const ATTR_CLIENT_VERSION = PDO_ATTR_CLIENT_VERSION; |
||||
|
const ATTR_SERVER_INFO = PDO_ATTR_SERVER_INFO; |
||||
|
const ATTR_PERSISTENT = PDO_ATTR_PERSISTENT; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 'Private' variables: |
||||
|
* __driver:PDO_* Dedicated PDO database class |
||||
|
*/ |
||||
|
var $__driver; |
||||
|
|
||||
|
/** |
||||
|
* Public constructor |
||||
|
* http://us2.php.net/manual/en/function.pdo-construct.php |
||||
|
*/ |
||||
|
function PDO($string_dsn, $string_username = '', $string_password = '', $array_driver_options = null) { |
||||
|
$con = &$this->__getDNS($string_dsn); |
||||
|
if($con['dbtype'] === 'mysql') { |
||||
|
require_once('PDO_mysql.class.php'); |
||||
|
if(isset($con['port'])) |
||||
|
$con['host'] .= ':'.$con['port']; |
||||
|
$this->__driver = new PDO_mysql( |
||||
|
$con['host'], |
||||
|
$con['dbname'], |
||||
|
$string_username, |
||||
|
$string_password |
||||
|
); |
||||
|
} |
||||
|
elseif($con['dbtype'] === 'sqlite2' || $con['dbtype'] === 'sqlite') { |
||||
|
require_once('PDO_sqlite.class.php'); |
||||
|
$this->__driver = new PDO_sqlite($con['dbname']); |
||||
|
} |
||||
|
elseif($con['dbtype'] === 'pgsql') { |
||||
|
require_once('PDO_pgsql.class.php'); |
||||
|
$string_dsn = "host={$con['host']} dbname={$con['dbname']} user={$string_username} password={$string_password}"; |
||||
|
if(isset($con['port'])) |
||||
|
$string_dsn .= " port={$con['port']}"; |
||||
|
$this->__driver = new PDO_pgsql($string_dsn); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** UNSUPPORTED |
||||
|
* Public method |
||||
|
* http://us2.php.net/manual/en/function.pdo-begintransaction.php |
||||
|
*/ |
||||
|
function beginTransaction() { |
||||
|
$this->__driver->beginTransaction(); |
||||
|
} |
||||
|
|
||||
|
/** NOT NATIVE BUT MAYBE USEFULL FOR PHP < 5.1 PDO DRIVER |
||||
|
* Public method |
||||
|
* Calls database_close function. |
||||
|
* this->close( Void ):Boolean |
||||
|
* @Return Boolean True on success, false otherwise |
||||
|
*/ |
||||
|
function close() { |
||||
|
return $this->__driver->close(); |
||||
|
} |
||||
|
|
||||
|
/** UNSUPPORTED |
||||
|
* Public method |
||||
|
* http://us2.php.net/manual/en/function.pdo-commit.php |
||||
|
*/ |
||||
|
function commit() { |
||||
|
$this->__driver->commit(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method |
||||
|
* http://us2.php.net/manual/en/function.pdo-exec.php |
||||
|
*/ |
||||
|
function exec($query) { |
||||
|
return $this->__driver->exec($query); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method |
||||
|
* http://us2.php.net/manual/en/function.pdo-errorcode.php |
||||
|
*/ |
||||
|
function errorCode() { |
||||
|
return $this->__driver->errorCode(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method |
||||
|
* http://us2.php.net/manual/en/function.pdo-errorinfo.php |
||||
|
*/ |
||||
|
function errorInfo() { |
||||
|
return $this->__driver->errorInfo(); |
||||
|
} |
||||
|
|
||||
|
/** NOT TOTALLY UNSUPPORTED |
||||
|
* Public method |
||||
|
* http://us2.php.net/manual/en/function.pdo-getattribute.php |
||||
|
*/ |
||||
|
function getAttribute($attribute) { |
||||
|
return $this->__driver->getAttribute($attribute); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method |
||||
|
* http://us2.php.net/manual/en/function.pdo-lastinsertid.php |
||||
|
*/ |
||||
|
function lastInsertId() { |
||||
|
return $this->__driver->lastInsertId(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method |
||||
|
* http://us2.php.net/manual/en/function.pdo-prepare.php |
||||
|
*/ |
||||
|
function prepare($query, $array = Array()) { |
||||
|
return $this->__driver->prepare($query, $array = Array()); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method |
||||
|
* http://us2.php.net/manual/en/function.pdo-query.php |
||||
|
*/ |
||||
|
function query($query) { |
||||
|
return $this->__driver->query($query); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method |
||||
|
* http://us2.php.net/manual/en/function.pdo-quote.php |
||||
|
*/ |
||||
|
function quote($string) { |
||||
|
return $this->__driver->quote($string); |
||||
|
} |
||||
|
|
||||
|
/** UNSUPPORTED |
||||
|
* Public method |
||||
|
* http://us2.php.net/manual/en/function.pdo-rollback.php |
||||
|
*/ |
||||
|
function rollBack() { |
||||
|
$this->__driver->rollBack(); |
||||
|
} |
||||
|
|
||||
|
/** NOT TOTALLY UNSUPPORTED |
||||
|
* Public method |
||||
|
* http://us2.php.net/manual/en/function.pdo-setattribute.php |
||||
|
*/ |
||||
|
function setAttribute($attribute, $mixed) { |
||||
|
return $this->__driver->setAttribute($attribute, $mixed); |
||||
|
} |
||||
|
|
||||
|
// PRIVATE METHOD [uncommented] |
||||
|
function __getDNS(&$string) { |
||||
|
$result = array(); |
||||
|
$pos = strpos($string, ':'); |
||||
|
$parameters = explode(';', substr($string, ($pos + 1))); |
||||
|
$result['dbtype'] = strtolower(substr($string, 0, $pos)); |
||||
|
for($a = 0, $b = count($parameters); $a < $b; $a++) { |
||||
|
$tmp = explode('=', $parameters[$a]); |
||||
|
if(count($tmp) == 2) |
||||
|
$result[$tmp[0]] = $tmp[1]; |
||||
|
else |
||||
|
$result['dbname'] = $parameters[$a]; |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
// If you have PHP 5.1 but want to test this class, declare PDO variables as _PDO variables |
||||
|
else { |
||||
|
/** |
||||
|
* Class _PDO |
||||
|
* (C) Andrea Giammarchi |
||||
|
* Please read PDO class comments to know more |
||||
|
*/ |
||||
|
class _PDO { |
||||
|
const FETCH_ASSOC = PDO::FETCH_ASSOC; |
||||
|
const FETCH_NUM = PDO::FETCH_NUM; |
||||
|
const FETCH_BOTH = PDO::FETCH_BOTH; |
||||
|
const FETCH_OBJ = PDO::FETCH_OBJ; |
||||
|
const FETCH_LAZY = PDO::FETCH_LAZY; |
||||
|
const FETCH_BOUND = PDO::FETCH_BOUND; |
||||
|
const ATTR_SERVER_VERSION = PDO::ATTR_SERVER_VERSION; |
||||
|
const ATTR_CLIENT_VERSION = PDO::ATTR_CLIENT_VERSION; |
||||
|
const ATTR_SERVER_INFO = PDO::ATTR_SERVER_INFO; |
||||
|
const ATTR_PERSISTENT = PDO::ATTR_PERSISTENT; |
||||
|
var $__driver; |
||||
|
function _PDO($string_dsn, $string_username = '', $string_password = '', $array_driver_options = null) { |
||||
|
$con = &$this->__getDNS($string_dsn); |
||||
|
if($con['dbtype'] === 'mysql') { |
||||
|
require_once('PDO_mysql.class.php'); |
||||
|
if(isset($con['port'])) |
||||
|
$con['host'] .= ':'.$con['port']; |
||||
|
$this->__driver = new PDO_mysql( |
||||
|
$con['host'], |
||||
|
$con['dbname'], |
||||
|
$string_username, |
||||
|
$string_password |
||||
|
); |
||||
|
} |
||||
|
elseif($con['dbtype'] === 'sqlite2' || $con['dbtype'] === 'sqlite') { |
||||
|
require_once('PDO_sqlite.class.php'); |
||||
|
$this->__driver = new PDO_sqlite($con['dbname']); |
||||
|
} |
||||
|
elseif($con['dbtype'] === 'pgsql') { |
||||
|
require_once('PDO_pgsql.class.php'); |
||||
|
$string_dsn = "host={$con['host']} dbname={$con['dbname']} user={$string_username} password={$string_password}"; |
||||
|
if(isset($con['port'])) |
||||
|
$string_dsn .= " port={$con['port']}"; |
||||
|
$this->__driver = new PDO_pgsql($string_dsn); |
||||
|
} |
||||
|
} |
||||
|
function beginTransaction() { |
||||
|
$this->__driver->beginTransaction(); |
||||
|
} |
||||
|
function close() { |
||||
|
return $this->__driver->close(); |
||||
|
} |
||||
|
function commit() { |
||||
|
$this->__driver->commit(); |
||||
|
} |
||||
|
function exec($query) { |
||||
|
return $this->__driver->exec($query); |
||||
|
} |
||||
|
function errorCode() { |
||||
|
return $this->__driver->errorCode(); |
||||
|
} |
||||
|
function errorInfo() { |
||||
|
return $this->__driver->errorInfo(); |
||||
|
} |
||||
|
function getAttribute($attribute) { |
||||
|
return $this->__driver->getAttribute($attribute); |
||||
|
} |
||||
|
function lastInsertId() { |
||||
|
return $this->__driver->lastInsertId(); |
||||
|
} |
||||
|
function prepare($query, $array = Array()) { |
||||
|
return $this->__driver->prepare($query, $array = Array()); |
||||
|
} |
||||
|
function query($query) { |
||||
|
return $this->__driver->query($query); |
||||
|
} |
||||
|
function quote($string) { |
||||
|
return $this->__driver->quote($string); |
||||
|
} |
||||
|
function rollBack() { |
||||
|
$this->__driver->rollBack(); |
||||
|
} |
||||
|
function setAttribute($attribute, $mixed) { |
||||
|
return $this->__driver->setAttribute($attribute, $mixed); |
||||
|
} |
||||
|
function __getDNS(&$string) { |
||||
|
$result = array(); |
||||
|
$pos = strpos($string, ':'); |
||||
|
$parameters = explode(';', substr($string, ($pos + 1))); |
||||
|
$result['dbtype'] = strtolower(substr($string, 0, $pos)); |
||||
|
for($a = 0, $b = count($parameters); $a < $b; $a++) { |
||||
|
$tmp = explode('=', $parameters[$a]); |
||||
|
if(count($tmp) == 2) |
||||
|
$result[$tmp[0]] = $tmp[1]; |
||||
|
else |
||||
|
$result['dbname'] = $parameters[$a]; |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
?> |
||||
@ -0,0 +1,368 @@ |
|||||
|
<?php |
||||
|
/** File PDOStatement_mysql.class.php * |
||||
|
*(C) Andrea Giammarchi [2005/10/13] */ |
||||
|
|
||||
|
/** |
||||
|
* Class PDOStatement_mysql |
||||
|
* This class is used from class PDO_mysql to manage a MySQL database. |
||||
|
* Look at PDO.clas.php file comments to know more about MySQL connection. |
||||
|
* --------------------------------------------- |
||||
|
* @Compatibility >= PHP 4 |
||||
|
* @Dependencies PDO.class.php |
||||
|
* PDO_mysql.class.php |
||||
|
* @Author Andrea Giammarchi |
||||
|
* @Site http://www.devpro.it/ |
||||
|
* @Mail andrea [ at ] 3site [ dot ] it |
||||
|
* @Date 2005/10/13 |
||||
|
* @LastModified 2006/01/29 09:30 [fixed execute bug] |
||||
|
* @Version 0.1b - tested |
||||
|
*/ |
||||
|
class PDOStatement_mysql { |
||||
|
|
||||
|
/** |
||||
|
* 'Private' variables: |
||||
|
* __connection:Resource Database connection |
||||
|
* __dbinfo:Array Array with 4 elements used to manage connection |
||||
|
* __persistent:Boolean Connection mode, is true on persistent, false on normal (deafult) connection |
||||
|
* __query:String Last query used |
||||
|
* __result:Resource Last result from last query |
||||
|
* __fetchmode:Integer constant PDO_FETCH_* result mode |
||||
|
* __errorCode:String Last error string code |
||||
|
* __errorInfo:Array Last error informations, code, number, details |
||||
|
* __boundParams:Array Stored bindParam |
||||
|
*/ |
||||
|
var $__connection; |
||||
|
var $__dbinfo; |
||||
|
var $__persistent = false; |
||||
|
var $__query = ''; |
||||
|
var $__result = null; |
||||
|
var $__fetchmode = PDO::FETCH_BOTH; |
||||
|
var $__errorCode = ''; |
||||
|
var $__errorInfo = Array(''); |
||||
|
var $__boundParams = Array(); |
||||
|
|
||||
|
/** |
||||
|
* Public constructor: |
||||
|
* Called from PDO to create a PDOStatement for this database |
||||
|
* new PDOStatement_sqlite( &$__query:String, &$__connection:Resource, $__dbinfo:Array ) |
||||
|
* @Param String query to prepare |
||||
|
* @Param Resource database connection |
||||
|
* @Param Array 4 elements array to manage connection |
||||
|
*/ |
||||
|
function PDOStatement_mysql(&$__query, &$__connection, &$__dbinfo) { |
||||
|
$this->__query = &$__query; |
||||
|
$this->__connection = &$__connection; |
||||
|
$this->__dbinfo = &$__dbinfo; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Replace ? or :named values to execute prepared query |
||||
|
* this->bindParam( $mixed:Mixed, &$variable:Mixed, $type:Integer, $lenght:Integer ):Void |
||||
|
* @Param Mixed Integer or String to replace prepared value |
||||
|
* @Param Mixed variable to replace |
||||
|
* @Param Integer this variable is not used but respects PDO original accepted parameters |
||||
|
* @Param Integer this variable is not used but respects PDO original accepted parameters |
||||
|
*/ |
||||
|
function bindParam($mixed, &$variable, $type = null, $lenght = null) { |
||||
|
if(is_string($mixed)) |
||||
|
$this->__boundParams[$mixed] = $variable; |
||||
|
else |
||||
|
array_push($this->__boundParams, $variable); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Checks if query was valid and returns how may fields returns |
||||
|
* this->columnCount( void ):Void |
||||
|
*/ |
||||
|
function columnCount() { |
||||
|
$result = 0; |
||||
|
if(!is_null($this->__result)) |
||||
|
$result = mysql_num_fields($this->__result); |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Returns a code rappresentation of an error |
||||
|
* this->errorCode( void ):String |
||||
|
* @Return String String rappresentation of the error |
||||
|
*/ |
||||
|
function errorCode() { |
||||
|
return $this->__errorCode; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Returns an array with error informations |
||||
|
* this->errorInfo( void ):Array |
||||
|
* @Return Array Array with 3 keys: |
||||
|
* 0 => error code |
||||
|
* 1 => error number |
||||
|
* 2 => error string |
||||
|
*/ |
||||
|
function errorInfo() { |
||||
|
return $this->__errorInfo; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Excecutes a query and returns true on success or false. |
||||
|
* this->exec( $array:Array ):Boolean |
||||
|
* @Param Array If present, it should contain all replacements for prepared query |
||||
|
* @Return Boolean true if query has been done without errors, false otherwise |
||||
|
*/ |
||||
|
function execute($array = Array()) { |
||||
|
if(count($this->__boundParams) > 0) |
||||
|
$array = &$this->__boundParams; |
||||
|
$__query = $this->__query; |
||||
|
if(count($array) > 0) { |
||||
|
foreach($array as $k => $v) { |
||||
|
if(!is_int($k) || substr($k, 0, 1) === ':') { |
||||
|
if(!isset($tempf)) |
||||
|
$tempf = $tempr = array(); |
||||
|
array_push($tempf, $k); |
||||
|
if (strexists($v, '\u')) { |
||||
|
$v = str_replace('\u', '\\\\u', $v); |
||||
|
} |
||||
|
if (strexists($v, '\"')) { |
||||
|
$v = str_replace('\"', '\\\\"', $v); |
||||
|
} |
||||
|
array_push($tempr, '"'.mysql_escape_string($v).'"'); |
||||
|
} |
||||
|
else { |
||||
|
$parse = create_function('$v', 'return \'"\'.mysql_escape_string($v).\'"\';'); |
||||
|
$__query = preg_replace("/(\?)/e", '$parse($array[$k++]);', $__query); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
if(isset($tempf)) { |
||||
|
foreach ($tempf as $k=>$v) { |
||||
|
$search[$k] = '/' . preg_quote($tempf[$k],'`') . '\b/'; |
||||
|
} |
||||
|
$__query = preg_replace($search, $tempr, $__query); |
||||
|
//$__query = str_replace($tempf, $tempr, $__query); |
||||
|
} |
||||
|
} |
||||
|
if(is_null($this->__result = &$this->__uquery($__query))) |
||||
|
$keyvars = false; |
||||
|
else |
||||
|
$keyvars = true; |
||||
|
$this->__boundParams = array(); |
||||
|
return $keyvars; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Returns, if present, next row of executed query or false. |
||||
|
* this->fetch( $mode:Integer, $cursor:Integer, $offset:Integer ):Mixed |
||||
|
* @Param Integer PDO_FETCH_* constant to know how to read next row, default PDO_FETCH_BOTH |
||||
|
* NOTE: if $mode is omitted is used default setted mode, PDO_FETCH_BOTH |
||||
|
* @Param Integer this variable is not used but respects PDO original accepted parameters |
||||
|
* @Param Integer this variable is not used but respects PDO original accepted parameters |
||||
|
* @Return Mixed Next row of executed query or false if there is nomore. |
||||
|
*/ |
||||
|
function fetch($mode = PDO_FETCH_ASSOC, $cursor = null, $offset = null) { |
||||
|
if(func_num_args() == 0) |
||||
|
$mode = &$this->__fetchmode; |
||||
|
$result = false; |
||||
|
if(!is_null($this->__result)) { |
||||
|
switch($mode) { |
||||
|
case PDO::FETCH_NUM: |
||||
|
$result = mysql_fetch_row($this->__result); |
||||
|
break; |
||||
|
case PDO::FETCH_ASSOC: |
||||
|
$result = mysql_fetch_assoc($this->__result); |
||||
|
break; |
||||
|
case PDO::FETCH_OBJ: |
||||
|
$result = mysql_fetch_object($this->__result); |
||||
|
break; |
||||
|
case PDO::FETCH_BOTH: |
||||
|
default: |
||||
|
$result = mysql_fetch_array($this->__result); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
if(!$result) |
||||
|
$this->__result = null; |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Returns an array with all rows of executed query. |
||||
|
* this->fetchAll( $mode:Integer ):Array |
||||
|
* @Param Integer PDO_FETCH_* constant to know how to read all rows, default PDO_FETCH_BOTH |
||||
|
* NOTE: this doesn't work as fetch method, then it will use always PDO_FETCH_BOTH |
||||
|
* if this param is omitted |
||||
|
* @Return Array An array with all fetched rows |
||||
|
*/ |
||||
|
function fetchAll($mode = PDO_FETCH_ASSOC) { |
||||
|
$result = array(); |
||||
|
if(!is_null($this->__result)) { |
||||
|
switch($mode) { |
||||
|
case PDO::FETCH_NUM: |
||||
|
while($r = mysql_fetch_row($this->__result)) |
||||
|
array_push($result, $r); |
||||
|
break; |
||||
|
case PDO::FETCH_ASSOC: |
||||
|
while($r = mysql_fetch_assoc($this->__result)) |
||||
|
array_push($result, $r); |
||||
|
break; |
||||
|
case PDO::FETCH_OBJ: |
||||
|
while($r = mysql_fetch_object($this->__result)) |
||||
|
array_push($result, $r); |
||||
|
break; |
||||
|
case PDO::FETCH_BOTH: |
||||
|
default: |
||||
|
while($r = mysql_fetch_array($this->__result)) |
||||
|
array_push($result, $r); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
$this->__result = null; |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Returns, if present, first column of next row of executed query |
||||
|
* this->fetchSingle( void ):Mixed |
||||
|
* @Return Mixed Null or next row's first column |
||||
|
*/ |
||||
|
function fetchSingle() { |
||||
|
$result = null; |
||||
|
if(!is_null($this->__result)) { |
||||
|
$result = @mysql_fetch_row($this->__result); |
||||
|
if($result) |
||||
|
$result = $result[0]; |
||||
|
else |
||||
|
$this->__result = null; |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
function fetchColumn($column=0) { |
||||
|
$row = mysql_fetch_row($this->__result); |
||||
|
return $row[$column]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Returns number of last affected database rows |
||||
|
* this->rowCount( void ):Integer |
||||
|
* @Return Integer number of last affected rows |
||||
|
* NOTE: works with INSERT, UPDATE and DELETE query type |
||||
|
*/ |
||||
|
function rowCount() { |
||||
|
return mysql_affected_rows($this->__connection); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// NOT TOTALLY SUPPORTED PUBLIC METHODS |
||||
|
/** |
||||
|
* Public method: |
||||
|
* Quotes correctly a string for this database |
||||
|
* this->getAttribute( $attribute:Integer ):Mixed |
||||
|
* @Param Integer a constant [ PDO_ATTR_SERVER_INFO, |
||||
|
* PDO_ATTR_SERVER_VERSION, |
||||
|
* PDO_ATTR_CLIENT_VERSION, |
||||
|
* PDO_ATTR_PERSISTENT ] |
||||
|
* @Return Mixed correct information or false |
||||
|
*/ |
||||
|
function getAttribute($attribute) { |
||||
|
$result = false; |
||||
|
switch($attribute) { |
||||
|
case PDO_ATTR_SERVER_INFO: |
||||
|
$result = mysql_get_host_info($this->__connection); |
||||
|
break; |
||||
|
case PDO_ATTR_SERVER_VERSION: |
||||
|
$result = mysql_get_server_info($this->__connection); |
||||
|
break; |
||||
|
case PDO_ATTR_CLIENT_VERSION: |
||||
|
$result = mysql_get_client_info(); |
||||
|
break; |
||||
|
case PDO_ATTR_PERSISTENT: |
||||
|
$result = $this->__persistent; |
||||
|
break; |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Sets database attributes, in this version only connection mode. |
||||
|
* this->setAttribute( $attribute:Integer, $mixed:Mixed ):Boolean |
||||
|
* @Param Integer PDO_* constant, in this case only PDO_ATTR_PERSISTENT |
||||
|
* @Param Mixed value for PDO_* constant, in this case a Boolean value |
||||
|
* true for permanent connection, false for default not permament connection |
||||
|
* @Return Boolean true on change, false otherwise |
||||
|
*/ |
||||
|
function setAttribute($attribute, $mixed) { |
||||
|
$result = false; |
||||
|
if($attribute === PDO_ATTR_PERSISTENT && $mixed != $this->__persistent) { |
||||
|
$result = true; |
||||
|
$this->__persistent = (boolean) $mixed; |
||||
|
mysql_close($this->__connection); |
||||
|
if($this->__persistent === true) |
||||
|
$this->__connection = &mysql_pconnect($this->__dbinfo[0], $this->__dbinfo[1], $this->__dbinfo[2]); |
||||
|
else |
||||
|
$this->__connection = &mysql_connect($this->__dbinfo[0], $this->__dbinfo[1], $this->__dbinfo[2]); |
||||
|
mysql_select_db($this->__dbinfo[3], $this->__connection); |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Sets default fetch mode to use with this->fetch() method. |
||||
|
* this->setFetchMode( $mode:Integer ):Boolean |
||||
|
* @Param Integer PDO_FETCH_* constant to use while reading an execute query with fetch() method. |
||||
|
* NOTE: PDO_FETCH_LAZY and PDO_FETCH_BOUND are not supported |
||||
|
* @Return Boolean true on change, false otherwise |
||||
|
*/ |
||||
|
function setFetchMode($mode) { |
||||
|
$result = false; |
||||
|
switch($mode) { |
||||
|
case PDO_FETCH_NUM: |
||||
|
case PDO_FETCH_ASSOC: |
||||
|
case PDO_FETCH_OBJ: |
||||
|
case PDO_FETCH_BOTH: |
||||
|
$result = true; |
||||
|
$this->__fetchmode = &$mode; |
||||
|
break; |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// UNSUPPORTED PUBLIC METHODS |
||||
|
function bindColumn($mixewd, &$param, $type = null, $max_length = null, $driver_option = null) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
function __setErrors($er) { |
||||
|
if(!is_resource($this->__connection)) { |
||||
|
$errno = mysql_errno(); |
||||
|
$errst = mysql_error(); |
||||
|
} |
||||
|
else { |
||||
|
$errno = mysql_errno($this->__connection); |
||||
|
$errst = mysql_error($this->__connection); |
||||
|
} |
||||
|
$this->__errorCode = &$er; |
||||
|
$this->__errorInfo = Array($this->__errorCode, $errno, $errst); |
||||
|
$this->__result = null; |
||||
|
} |
||||
|
|
||||
|
function __uquery(&$query) { |
||||
|
if(!@$query = mysql_query($query, $this->__connection)) { |
||||
|
$this->__setErrors('SQLER'); |
||||
|
$query = null; |
||||
|
} |
||||
|
return $query; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
?> |
||||
@ -0,0 +1,265 @@ |
|||||
|
<?php |
||||
|
/** File PDO_mysql.class.php * |
||||
|
*(C) Andrea Giammarchi [2005/10/13] */ |
||||
|
|
||||
|
// Requires PDOStatement_mysql.class.php , drived by PDO.class.php file |
||||
|
require_once('PDOStatement_mysql.class.php'); |
||||
|
|
||||
|
/** |
||||
|
* Class PDO_mysql |
||||
|
* This class is used from class PDO to manage a MySQL database. |
||||
|
* Look at PDO.clas.php file comments to know more about MySQL connection. |
||||
|
* --------------------------------------------- |
||||
|
* @Compatibility >= PHP 4 |
||||
|
* @Dependencies PDO.class.php |
||||
|
* PDOStatement_mysql.class.php |
||||
|
* @Author Andrea Giammarchi |
||||
|
* @Site http://www.devpro.it/ |
||||
|
* @Mail andrea [ at ] 3site [ dot ] it |
||||
|
* @Date 2005/10/13 |
||||
|
* @LastModified 2005/18/14 12:30 |
||||
|
* @Version 0.1 - tested |
||||
|
*/ |
||||
|
class PDO_mysql { |
||||
|
|
||||
|
/** |
||||
|
* 'Private' variables: |
||||
|
* __connection:Resource Database connection |
||||
|
* __dbinfo:Array Array with 4 elements used to manage connection |
||||
|
* __persistent:Boolean Connection mode, is true on persistent, false on normal (deafult) connection |
||||
|
* __errorCode:String Last error code |
||||
|
* __errorInfo:Array Detailed errors |
||||
|
*/ |
||||
|
var $__connection; |
||||
|
var $__dbinfo; |
||||
|
var $__persistent = false; |
||||
|
var $__errorCode = ''; |
||||
|
var $__errorInfo = Array(''); |
||||
|
|
||||
|
/** |
||||
|
* Public constructor: |
||||
|
* Checks connection and database selection |
||||
|
* new PDO_mysql( &$host:String, &$db:String, &$user:String, &$pass:String ) |
||||
|
* @Param String host with or without port info |
||||
|
* @Param String database name |
||||
|
* @Param String database user |
||||
|
* @Param String database password |
||||
|
*/ |
||||
|
function PDO_mysql(&$host, &$db, &$user, &$pass) { |
||||
|
if(!@$this->__connection = &mysql_connect($host, $user, $pass)) |
||||
|
$this->__setErrors('DBCON'); |
||||
|
else { |
||||
|
if(!@mysql_select_db($db, $this->__connection)) |
||||
|
$this->__setErrors('DBER'); |
||||
|
else |
||||
|
$this->__dbinfo = Array($host, $user, $pass, $db); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** NOT NATIVE BUT MAYBE USEFULL FOR PHP < 5.1 PDO DRIVER |
||||
|
* Public method |
||||
|
* Calls mysql_close function. |
||||
|
* this->close( Void ):Boolean |
||||
|
* @Return Boolean True on success, false otherwise |
||||
|
*/ |
||||
|
function close() { |
||||
|
$result = is_resource($this->__connection); |
||||
|
if($result) { |
||||
|
mysql_close($this->__connection); |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Returns a code rappresentation of an error |
||||
|
* this->errorCode( void ):String |
||||
|
* @Return String String rappresentation of the error |
||||
|
*/ |
||||
|
function errorCode() { |
||||
|
return $this->__errorCode; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Returns an array with error informations |
||||
|
* this->errorInfo( void ):Array |
||||
|
* @Return Array Array with 3 keys: |
||||
|
* 0 => error code |
||||
|
* 1 => error number |
||||
|
* 2 => error string |
||||
|
*/ |
||||
|
function errorInfo() { |
||||
|
return $this->__errorInfo; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Excecutes a query and returns affected rows |
||||
|
* this->exec( $query:String ):Mixed |
||||
|
* @Param String query to execute |
||||
|
* @Return Mixed Number of affected rows or false on bad query. |
||||
|
*/ |
||||
|
function exec($query) { |
||||
|
$result = 0; |
||||
|
if(!is_null($this->__uquery($query))) |
||||
|
$result = mysql_affected_rows($this->__connection); |
||||
|
if(is_null($result)) |
||||
|
$result = false; |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Returns last inserted id |
||||
|
* this->lastInsertId( void ):Number |
||||
|
* @Return Number Last inserted id |
||||
|
*/ |
||||
|
function lastInsertId() { |
||||
|
$id = mysql_insert_id($this->__connection); |
||||
|
if ($id > 0) { |
||||
|
return $id; |
||||
|
} else { |
||||
|
$query = $this->prepare('SELECT last_insert_id()'); |
||||
|
$query->execute(); |
||||
|
return $query->fetchColumn(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Returns a new PDOStatement |
||||
|
* this->prepare( $query:String, $array:Array ):PDOStatement |
||||
|
* @Param String query to prepare |
||||
|
* @Param Array this variable is not used but respects PDO original accepted parameters |
||||
|
* @Return PDOStatement new PDOStatement to manage |
||||
|
*/ |
||||
|
function prepare($query, $array = Array()) { |
||||
|
return new PDOStatement_mysql($query, $this->__connection, $this->__dbinfo); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Executes directly a query and returns an array with result or false on bad query |
||||
|
* this->query( $query:String ):Mixed |
||||
|
* @Param String query to execute |
||||
|
* @Return Mixed false on error, array with all info on success |
||||
|
*/ |
||||
|
function query($query) { |
||||
|
$query = @mysql_unbuffered_query($query, $this->__connection); |
||||
|
if($query) { |
||||
|
$result = Array(); |
||||
|
while($r = mysql_fetch_assoc($query)) |
||||
|
array_push($result, $r); |
||||
|
} |
||||
|
else { |
||||
|
$result = false; |
||||
|
$this->__setErrors('SQLER'); |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Quotes correctly a string for this database |
||||
|
* this->quote( $string:String ):String |
||||
|
* @Param String string to quote |
||||
|
* @Return String a correctly quoted string |
||||
|
*/ |
||||
|
function quote($string) { |
||||
|
return ('"'.mysql_escape_string($string).'"'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// NOT TOTALLY SUPPORTED PUBLIC METHODS |
||||
|
/** |
||||
|
* Public method: |
||||
|
* Quotes correctly a string for this database |
||||
|
* this->getAttribute( $attribute:Integer ):Mixed |
||||
|
* @Param Integer a constant [ PDO_ATTR_SERVER_INFO, |
||||
|
* PDO_ATTR_SERVER_VERSION, |
||||
|
* PDO_ATTR_CLIENT_VERSION, |
||||
|
* PDO_ATTR_PERSISTENT ] |
||||
|
* @Return Mixed correct information or false |
||||
|
*/ |
||||
|
function getAttribute($attribute) { |
||||
|
$result = false; |
||||
|
switch($attribute) { |
||||
|
case PDO_ATTR_SERVER_INFO: |
||||
|
$result = mysql_get_host_info($this->__connection); |
||||
|
break; |
||||
|
case PDO_ATTR_SERVER_VERSION: |
||||
|
$result = mysql_get_server_info($this->__connection); |
||||
|
break; |
||||
|
case PDO_ATTR_CLIENT_VERSION: |
||||
|
$result = mysql_get_client_info(); |
||||
|
break; |
||||
|
case PDO_ATTR_PERSISTENT: |
||||
|
$result = $this->__persistent; |
||||
|
break; |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Public method: |
||||
|
* Sets database attributes, in this version only connection mode. |
||||
|
* this->setAttribute( $attribute:Integer, $mixed:Mixed ):Boolean |
||||
|
* @Param Integer PDO_* constant, in this case only PDO_ATTR_PERSISTENT |
||||
|
* @Param Mixed value for PDO_* constant, in this case a Boolean value |
||||
|
* true for permanent connection, false for default not permament connection |
||||
|
* @Return Boolean true on change, false otherwise |
||||
|
*/ |
||||
|
function setAttribute($attribute, $mixed) { |
||||
|
$result = false; |
||||
|
if($attribute === PDO_ATTR_PERSISTENT && $mixed != $this->__persistent) { |
||||
|
$result = true; |
||||
|
$this->__persistent = (boolean) $mixed; |
||||
|
mysql_close($this->__connection); |
||||
|
if($this->__persistent === true) |
||||
|
$this->__connection = &mysql_pconnect($this->__dbinfo[0], $this->__dbinfo[1], $this->__dbinfo[2]); |
||||
|
else |
||||
|
$this->__connection = &mysql_connect($this->__dbinfo[0], $this->__dbinfo[1], $this->__dbinfo[2]); |
||||
|
mysql_select_db($this->__dbinfo[3], $this->__connection); |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// UNSUPPORTED PUBLIC METHODS |
||||
|
function beginTransaction() { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
function commit() { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
function rollBack() { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// PRIVATE METHODS [ UNCOMMENTED ] |
||||
|
function __setErrors($er) { |
||||
|
if(!is_resource($this->__connection)) { |
||||
|
$errno = mysql_errno(); |
||||
|
$errst = mysql_error(); |
||||
|
} |
||||
|
else { |
||||
|
$errno = mysql_errno($this->__connection); |
||||
|
$errst = mysql_error($this->__connection); |
||||
|
} |
||||
|
$this->__errorCode = &$er; |
||||
|
$this->__errorInfo = Array($this->__errorCode, $errno, $errst); |
||||
|
} |
||||
|
|
||||
|
function __uquery(&$query) { |
||||
|
if(!@$query = mysql_query($query, $this->__connection)) { |
||||
|
$this->__setErrors('SQLER'); |
||||
|
$query = null; |
||||
|
} |
||||
|
return $query; |
||||
|
} |
||||
|
} |
||||
|
?> |
||||
@ -0,0 +1,295 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CachedObjectStorage_APC |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { |
||||
|
|
||||
|
/** |
||||
|
* Prefix used to uniquely identify cache data for this worksheet |
||||
|
* |
||||
|
* @access private |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_cachePrefix = null; |
||||
|
|
||||
|
/** |
||||
|
* Cache timeout |
||||
|
* |
||||
|
* @access private |
||||
|
* @var integer |
||||
|
*/ |
||||
|
private $_cacheTime = 600; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Store cell data in cache for the current cell object if it's "dirty", |
||||
|
* and the 'nullify' the current cell object |
||||
|
* |
||||
|
* @access private |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
protected function _storeData() { |
||||
|
if ($this->_currentCellIsDirty) { |
||||
|
$this->_currentObject->detach(); |
||||
|
|
||||
|
if (!apc_store($this->_cachePrefix.$this->_currentObjectID.'.cache',serialize($this->_currentObject),$this->_cacheTime)) { |
||||
|
$this->__destruct(); |
||||
|
throw new PHPExcel_Exception('Failed to store cell '.$this->_currentObjectID.' in APC'); |
||||
|
} |
||||
|
$this->_currentCellIsDirty = false; |
||||
|
} |
||||
|
$this->_currentObjectID = $this->_currentObject = null; |
||||
|
} // function _storeData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Add or Update a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @access public |
||||
|
* @param string $pCoord Coordinate address of the cell to update |
||||
|
* @param PHPExcel_Cell $cell Cell to update |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
||||
|
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
$this->_cellCache[$pCoord] = true; |
||||
|
|
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = $cell; |
||||
|
$this->_currentCellIsDirty = true; |
||||
|
|
||||
|
return $cell; |
||||
|
} // function addCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell? |
||||
|
* |
||||
|
* @access public |
||||
|
* @param string $pCoord Coordinate address of the cell to check |
||||
|
* @return void |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function isDataSet($pCoord) { |
||||
|
// Check if the requested entry is the current object, or exists in the cache |
||||
|
if (parent::isDataSet($pCoord)) { |
||||
|
if ($this->_currentObjectID == $pCoord) { |
||||
|
return true; |
||||
|
} |
||||
|
// Check if the requested entry still exists in apc |
||||
|
$success = apc_fetch($this->_cachePrefix.$pCoord.'.cache'); |
||||
|
if ($success === FALSE) { |
||||
|
// Entry no longer exists in APC, so clear it from the cache array |
||||
|
parent::deleteCacheData($pCoord); |
||||
|
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache'); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} // function isDataSet() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get cell at a specific coordinate |
||||
|
* |
||||
|
* @access public |
||||
|
* @param string $pCoord Coordinate of the cell |
||||
|
* @throws PHPExcel_Exception |
||||
|
* @return PHPExcel_Cell Cell that was found, or null if not found |
||||
|
*/ |
||||
|
public function getCacheData($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
return $this->_currentObject; |
||||
|
} |
||||
|
$this->_storeData(); |
||||
|
|
||||
|
// Check if the entry that has been requested actually exists |
||||
|
if (parent::isDataSet($pCoord)) { |
||||
|
$obj = apc_fetch($this->_cachePrefix.$pCoord.'.cache'); |
||||
|
if ($obj === FALSE) { |
||||
|
// Entry no longer exists in APC, so clear it from the cache array |
||||
|
parent::deleteCacheData($pCoord); |
||||
|
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache'); |
||||
|
} |
||||
|
} else { |
||||
|
// Return null if requested entry doesn't exist in cache |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
// Set current entry to the requested entry |
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = unserialize($obj); |
||||
|
// Re-attach this as the cell's parent |
||||
|
$this->_currentObject->attach($this); |
||||
|
|
||||
|
// Return requested entry |
||||
|
return $this->_currentObject; |
||||
|
} // function getCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get a list of all cell addresses currently held in cache |
||||
|
* |
||||
|
* @return array of string |
||||
|
*/ |
||||
|
public function getCellList() { |
||||
|
if ($this->_currentObjectID !== null) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
return parent::getCellList(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Delete a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @access public |
||||
|
* @param string $pCoord Coordinate address of the cell to delete |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function deleteCacheData($pCoord) { |
||||
|
// Delete the entry from APC |
||||
|
apc_delete($this->_cachePrefix.$pCoord.'.cache'); |
||||
|
|
||||
|
// Delete the entry from our cell address array |
||||
|
parent::deleteCacheData($pCoord); |
||||
|
} // function deleteCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clone the cell collection |
||||
|
* |
||||
|
* @access public |
||||
|
* @param PHPExcel_Worksheet $parent The new worksheet |
||||
|
* @throws PHPExcel_Exception |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function copyCellCollection(PHPExcel_Worksheet $parent) { |
||||
|
parent::copyCellCollection($parent); |
||||
|
// Get a new id for the new file name |
||||
|
$baseUnique = $this->_getUniqueID(); |
||||
|
$newCachePrefix = substr(md5($baseUnique),0,8).'.'; |
||||
|
$cacheList = $this->getCellList(); |
||||
|
foreach($cacheList as $cellID) { |
||||
|
if ($cellID != $this->_currentObjectID) { |
||||
|
$obj = apc_fetch($this->_cachePrefix.$cellID.'.cache'); |
||||
|
if ($obj === FALSE) { |
||||
|
// Entry no longer exists in APC, so clear it from the cache array |
||||
|
parent::deleteCacheData($cellID); |
||||
|
throw new PHPExcel_Exception('Cell entry '.$cellID.' no longer exists in APC'); |
||||
|
} |
||||
|
if (!apc_store($newCachePrefix.$cellID.'.cache',$obj,$this->_cacheTime)) { |
||||
|
$this->__destruct(); |
||||
|
throw new PHPExcel_Exception('Failed to store cell '.$cellID.' in APC'); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$this->_cachePrefix = $newCachePrefix; |
||||
|
} // function copyCellCollection() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clear the cell collection and disconnect from our parent |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function unsetWorksheetCells() { |
||||
|
if ($this->_currentObject !== NULL) { |
||||
|
$this->_currentObject->detach(); |
||||
|
$this->_currentObject = $this->_currentObjectID = null; |
||||
|
} |
||||
|
|
||||
|
// Flush the APC cache |
||||
|
$this->__destruct(); |
||||
|
|
||||
|
$this->_cellCache = array(); |
||||
|
|
||||
|
// detach ourself from the worksheet, so that it can then delete this object successfully |
||||
|
$this->_parent = null; |
||||
|
} // function unsetWorksheetCells() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Initialise this new cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection |
||||
|
* @param array of mixed $arguments Additional initialisation arguments |
||||
|
*/ |
||||
|
public function __construct(PHPExcel_Worksheet $parent, $arguments) { |
||||
|
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; |
||||
|
|
||||
|
if ($this->_cachePrefix === NULL) { |
||||
|
$baseUnique = $this->_getUniqueID(); |
||||
|
$this->_cachePrefix = substr(md5($baseUnique),0,8).'.'; |
||||
|
$this->_cacheTime = $cacheTime; |
||||
|
|
||||
|
parent::__construct($parent); |
||||
|
} |
||||
|
} // function __construct() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Destroy this cell collection |
||||
|
*/ |
||||
|
public function __destruct() { |
||||
|
$cacheList = $this->getCellList(); |
||||
|
foreach($cacheList as $cellID) { |
||||
|
apc_delete($this->_cachePrefix.$cellID.'.cache'); |
||||
|
} |
||||
|
} // function __destruct() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Identify whether the caching method is currently available |
||||
|
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function cacheMethodIsAvailable() { |
||||
|
if (!function_exists('apc_store')) { |
||||
|
return FALSE; |
||||
|
} |
||||
|
if (apc_sma_info() === FALSE) { |
||||
|
return FALSE; |
||||
|
} |
||||
|
|
||||
|
return TRUE; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,318 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CachedObjectStorage_CacheBase |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
abstract class PHPExcel_CachedObjectStorage_CacheBase { |
||||
|
|
||||
|
/** |
||||
|
* Parent worksheet |
||||
|
* |
||||
|
* @var PHPExcel_Worksheet |
||||
|
*/ |
||||
|
protected $_parent; |
||||
|
|
||||
|
/** |
||||
|
* The currently active Cell |
||||
|
* |
||||
|
* @var PHPExcel_Cell |
||||
|
*/ |
||||
|
protected $_currentObject = null; |
||||
|
|
||||
|
/** |
||||
|
* Coordinate address of the currently active Cell |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $_currentObjectID = null; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Flag indicating whether the currently active Cell requires saving |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
protected $_currentCellIsDirty = true; |
||||
|
|
||||
|
/** |
||||
|
* An array of cells or cell pointers for the worksheet cells held in this cache, |
||||
|
* and indexed by their coordinate address within the worksheet |
||||
|
* |
||||
|
* @var array of mixed |
||||
|
*/ |
||||
|
protected $_cellCache = array(); |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Initialise this new cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection |
||||
|
*/ |
||||
|
public function __construct(PHPExcel_Worksheet $parent) { |
||||
|
// Set our parent worksheet. |
||||
|
// This is maintained within the cache controller to facilitate re-attaching it to PHPExcel_Cell objects when |
||||
|
// they are woken from a serialized state |
||||
|
$this->_parent = $parent; |
||||
|
} // function __construct() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Return the parent worksheet for this cell collection |
||||
|
* |
||||
|
* @return PHPExcel_Worksheet |
||||
|
*/ |
||||
|
public function getParent() |
||||
|
{ |
||||
|
return $this->_parent; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell? |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function isDataSet($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
return true; |
||||
|
} |
||||
|
// Check if the requested entry exists in the cache |
||||
|
return isset($this->_cellCache[$pCoord]); |
||||
|
} // function isDataSet() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Move a cell object from one address to another |
||||
|
* |
||||
|
* @param string $fromAddress Current address of the cell to move |
||||
|
* @param string $toAddress Destination address of the cell to move |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function moveCell($fromAddress, $toAddress) { |
||||
|
if ($fromAddress === $this->_currentObjectID) { |
||||
|
$this->_currentObjectID = $toAddress; |
||||
|
} |
||||
|
$this->_currentCellIsDirty = true; |
||||
|
if (isset($this->_cellCache[$fromAddress])) { |
||||
|
$this->_cellCache[$toAddress] = &$this->_cellCache[$fromAddress]; |
||||
|
unset($this->_cellCache[$fromAddress]); |
||||
|
} |
||||
|
|
||||
|
return TRUE; |
||||
|
} // function moveCell() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Add or Update a cell in cache |
||||
|
* |
||||
|
* @param PHPExcel_Cell $cell Cell to update |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function updateCacheData(PHPExcel_Cell $cell) { |
||||
|
return $this->addCacheData($cell->getCoordinate(),$cell); |
||||
|
} // function updateCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Delete a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to delete |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function deleteCacheData($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
$this->_currentObject->detach(); |
||||
|
$this->_currentObjectID = $this->_currentObject = null; |
||||
|
} |
||||
|
|
||||
|
if (is_object($this->_cellCache[$pCoord])) { |
||||
|
$this->_cellCache[$pCoord]->detach(); |
||||
|
unset($this->_cellCache[$pCoord]); |
||||
|
} |
||||
|
$this->_currentCellIsDirty = false; |
||||
|
} // function deleteCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get a list of all cell addresses currently held in cache |
||||
|
* |
||||
|
* @return array of string |
||||
|
*/ |
||||
|
public function getCellList() { |
||||
|
return array_keys($this->_cellCache); |
||||
|
} // function getCellList() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Sort the list of all cell addresses currently held in cache by row and column |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function getSortedCellList() { |
||||
|
$sortKeys = array(); |
||||
|
foreach ($this->getCellList() as $coord) { |
||||
|
sscanf($coord,'%[A-Z]%d', $column, $row); |
||||
|
$sortKeys[sprintf('%09d%3s',$row,$column)] = $coord; |
||||
|
} |
||||
|
ksort($sortKeys); |
||||
|
|
||||
|
return array_values($sortKeys); |
||||
|
} // function sortCellList() |
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get highest worksheet column and highest row that have cell records |
||||
|
* |
||||
|
* @return array Highest column name and highest row number |
||||
|
*/ |
||||
|
public function getHighestRowAndColumn() |
||||
|
{ |
||||
|
// Lookup highest column and highest row |
||||
|
$col = array('A' => '1A'); |
||||
|
$row = array(1); |
||||
|
foreach ($this->getCellList() as $coord) { |
||||
|
sscanf($coord,'%[A-Z]%d', $c, $r); |
||||
|
$row[$r] = $r; |
||||
|
$col[$c] = strlen($c).$c; |
||||
|
} |
||||
|
if (!empty($row)) { |
||||
|
// Determine highest column and row |
||||
|
$highestRow = max($row); |
||||
|
$highestColumn = substr(max($col),1); |
||||
|
} |
||||
|
|
||||
|
return array( 'row' => $highestRow, |
||||
|
'column' => $highestColumn |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Return the cell address of the currently active cell object |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getCurrentAddress() |
||||
|
{ |
||||
|
return $this->_currentObjectID; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Return the column address of the currently active cell object |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getCurrentColumn() |
||||
|
{ |
||||
|
sscanf($this->_currentObjectID, '%[A-Z]%d', $column, $row); |
||||
|
return $column; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Return the row address of the currently active cell object |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getCurrentRow() |
||||
|
{ |
||||
|
sscanf($this->_currentObjectID, '%[A-Z]%d', $column, $row); |
||||
|
return $row; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get highest worksheet column |
||||
|
* |
||||
|
* @return string Highest column name |
||||
|
*/ |
||||
|
public function getHighestColumn() |
||||
|
{ |
||||
|
$colRow = $this->getHighestRowAndColumn(); |
||||
|
return $colRow['column']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get highest worksheet row |
||||
|
* |
||||
|
* @return int Highest row number |
||||
|
*/ |
||||
|
public function getHighestRow() |
||||
|
{ |
||||
|
$colRow = $this->getHighestRowAndColumn(); |
||||
|
return $colRow['row']; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Generate a unique ID for cache referencing |
||||
|
* |
||||
|
* @return string Unique Reference |
||||
|
*/ |
||||
|
protected function _getUniqueID() { |
||||
|
if (function_exists('posix_getpid')) { |
||||
|
$baseUnique = posix_getpid(); |
||||
|
} else { |
||||
|
$baseUnique = mt_rand(); |
||||
|
} |
||||
|
return uniqid($baseUnique,true); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Clone the cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The new worksheet |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function copyCellCollection(PHPExcel_Worksheet $parent) { |
||||
|
$this->_currentCellIsDirty; |
||||
|
$this->_storeData(); |
||||
|
|
||||
|
$this->_parent = $parent; |
||||
|
if (($this->_currentObject !== NULL) && (is_object($this->_currentObject))) { |
||||
|
$this->_currentObject->attach($this); |
||||
|
} |
||||
|
} // function copyCellCollection() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Identify whether the caching method is currently available |
||||
|
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function cacheMethodIsAvailable() { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,219 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CachedObjectStorage_DiscISAM |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { |
||||
|
|
||||
|
/** |
||||
|
* Name of the file for this cache |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_fileName = NULL; |
||||
|
|
||||
|
/** |
||||
|
* File handle for this cache file |
||||
|
* |
||||
|
* @var resource |
||||
|
*/ |
||||
|
private $_fileHandle = NULL; |
||||
|
|
||||
|
/** |
||||
|
* Directory/Folder where the cache file is located |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_cacheDirectory = NULL; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Store cell data in cache for the current cell object if it's "dirty", |
||||
|
* and the 'nullify' the current cell object |
||||
|
* |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
protected function _storeData() { |
||||
|
if ($this->_currentCellIsDirty) { |
||||
|
$this->_currentObject->detach(); |
||||
|
|
||||
|
fseek($this->_fileHandle,0,SEEK_END); |
||||
|
$offset = ftell($this->_fileHandle); |
||||
|
fwrite($this->_fileHandle, serialize($this->_currentObject)); |
||||
|
$this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset, |
||||
|
'sz' => ftell($this->_fileHandle) - $offset |
||||
|
); |
||||
|
$this->_currentCellIsDirty = false; |
||||
|
} |
||||
|
$this->_currentObjectID = $this->_currentObject = null; |
||||
|
} // function _storeData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Add or Update a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to update |
||||
|
* @param PHPExcel_Cell $cell Cell to update |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
||||
|
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = $cell; |
||||
|
$this->_currentCellIsDirty = true; |
||||
|
|
||||
|
return $cell; |
||||
|
} // function addCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get cell at a specific coordinate |
||||
|
* |
||||
|
* @param string $pCoord Coordinate of the cell |
||||
|
* @throws PHPExcel_Exception |
||||
|
* @return PHPExcel_Cell Cell that was found, or null if not found |
||||
|
*/ |
||||
|
public function getCacheData($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
return $this->_currentObject; |
||||
|
} |
||||
|
$this->_storeData(); |
||||
|
|
||||
|
// Check if the entry that has been requested actually exists |
||||
|
if (!isset($this->_cellCache[$pCoord])) { |
||||
|
// Return null if requested entry doesn't exist in cache |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
// Set current entry to the requested entry |
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']); |
||||
|
$this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz'])); |
||||
|
// Re-attach this as the cell's parent |
||||
|
$this->_currentObject->attach($this); |
||||
|
|
||||
|
// Return requested entry |
||||
|
return $this->_currentObject; |
||||
|
} // function getCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get a list of all cell addresses currently held in cache |
||||
|
* |
||||
|
* @return array of string |
||||
|
*/ |
||||
|
public function getCellList() { |
||||
|
if ($this->_currentObjectID !== null) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
return parent::getCellList(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clone the cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The new worksheet |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function copyCellCollection(PHPExcel_Worksheet $parent) { |
||||
|
parent::copyCellCollection($parent); |
||||
|
// Get a new id for the new file name |
||||
|
$baseUnique = $this->_getUniqueID(); |
||||
|
$newFileName = $this->_cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache'; |
||||
|
// Copy the existing cell cache file |
||||
|
copy ($this->_fileName,$newFileName); |
||||
|
$this->_fileName = $newFileName; |
||||
|
// Open the copied cell cache file |
||||
|
$this->_fileHandle = fopen($this->_fileName,'a+'); |
||||
|
} // function copyCellCollection() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clear the cell collection and disconnect from our parent |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function unsetWorksheetCells() { |
||||
|
if(!is_null($this->_currentObject)) { |
||||
|
$this->_currentObject->detach(); |
||||
|
$this->_currentObject = $this->_currentObjectID = null; |
||||
|
} |
||||
|
$this->_cellCache = array(); |
||||
|
|
||||
|
// detach ourself from the worksheet, so that it can then delete this object successfully |
||||
|
$this->_parent = null; |
||||
|
|
||||
|
// Close down the temporary cache file |
||||
|
$this->__destruct(); |
||||
|
} // function unsetWorksheetCells() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Initialise this new cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection |
||||
|
* @param array of mixed $arguments Additional initialisation arguments |
||||
|
*/ |
||||
|
public function __construct(PHPExcel_Worksheet $parent, $arguments) { |
||||
|
$this->_cacheDirectory = ((isset($arguments['dir'])) && ($arguments['dir'] !== NULL)) |
||||
|
? $arguments['dir'] |
||||
|
: PHPExcel_Shared_File::sys_get_temp_dir(); |
||||
|
|
||||
|
parent::__construct($parent); |
||||
|
if (is_null($this->_fileHandle)) { |
||||
|
$baseUnique = $this->_getUniqueID(); |
||||
|
$this->_fileName = $this->_cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache'; |
||||
|
$this->_fileHandle = fopen($this->_fileName,'a+'); |
||||
|
} |
||||
|
} // function __construct() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Destroy this cell collection |
||||
|
*/ |
||||
|
public function __destruct() { |
||||
|
if (!is_null($this->_fileHandle)) { |
||||
|
fclose($this->_fileHandle); |
||||
|
unlink($this->_fileName); |
||||
|
} |
||||
|
$this->_fileHandle = null; |
||||
|
} // function __destruct() |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,112 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CachedObjectStorage_ICache |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
interface PHPExcel_CachedObjectStorage_ICache |
||||
|
{ |
||||
|
/** |
||||
|
* Add or Update a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to update |
||||
|
* @param PHPExcel_Cell $cell Cell to update |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function addCacheData($pCoord, PHPExcel_Cell $cell); |
||||
|
|
||||
|
/** |
||||
|
* Add or Update a cell in cache |
||||
|
* |
||||
|
* @param PHPExcel_Cell $cell Cell to update |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function updateCacheData(PHPExcel_Cell $cell); |
||||
|
|
||||
|
/** |
||||
|
* Fetch a cell from cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to retrieve |
||||
|
* @return PHPExcel_Cell Cell that was found, or null if not found |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function getCacheData($pCoord); |
||||
|
|
||||
|
/** |
||||
|
* Delete a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to delete |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function deleteCacheData($pCoord); |
||||
|
|
||||
|
/** |
||||
|
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell? |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function isDataSet($pCoord); |
||||
|
|
||||
|
/** |
||||
|
* Get a list of all cell addresses currently held in cache |
||||
|
* |
||||
|
* @return array of string |
||||
|
*/ |
||||
|
public function getCellList(); |
||||
|
|
||||
|
/** |
||||
|
* Get the list of all cell addresses currently held in cache sorted by column and row |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function getSortedCellList(); |
||||
|
|
||||
|
/** |
||||
|
* Clone the cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The new worksheet |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function copyCellCollection(PHPExcel_Worksheet $parent); |
||||
|
|
||||
|
/** |
||||
|
* Identify whether the caching method is currently available |
||||
|
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function cacheMethodIsAvailable(); |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,152 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CachedObjectStorage_Igbinary |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { |
||||
|
|
||||
|
/** |
||||
|
* Store cell data in cache for the current cell object if it's "dirty", |
||||
|
* and the 'nullify' the current cell object |
||||
|
* |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
protected function _storeData() { |
||||
|
if ($this->_currentCellIsDirty) { |
||||
|
$this->_currentObject->detach(); |
||||
|
|
||||
|
$this->_cellCache[$this->_currentObjectID] = igbinary_serialize($this->_currentObject); |
||||
|
$this->_currentCellIsDirty = false; |
||||
|
} |
||||
|
$this->_currentObjectID = $this->_currentObject = null; |
||||
|
} // function _storeData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Add or Update a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to update |
||||
|
* @param PHPExcel_Cell $cell Cell to update |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
||||
|
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = $cell; |
||||
|
$this->_currentCellIsDirty = true; |
||||
|
|
||||
|
return $cell; |
||||
|
} // function addCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get cell at a specific coordinate |
||||
|
* |
||||
|
* @param string $pCoord Coordinate of the cell |
||||
|
* @throws PHPExcel_Exception |
||||
|
* @return PHPExcel_Cell Cell that was found, or null if not found |
||||
|
*/ |
||||
|
public function getCacheData($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
return $this->_currentObject; |
||||
|
} |
||||
|
$this->_storeData(); |
||||
|
|
||||
|
// Check if the entry that has been requested actually exists |
||||
|
if (!isset($this->_cellCache[$pCoord])) { |
||||
|
// Return null if requested entry doesn't exist in cache |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
// Set current entry to the requested entry |
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = igbinary_unserialize($this->_cellCache[$pCoord]); |
||||
|
// Re-attach this as the cell's parent |
||||
|
$this->_currentObject->attach($this); |
||||
|
|
||||
|
// Return requested entry |
||||
|
return $this->_currentObject; |
||||
|
} // function getCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get a list of all cell addresses currently held in cache |
||||
|
* |
||||
|
* @return array of string |
||||
|
*/ |
||||
|
public function getCellList() { |
||||
|
if ($this->_currentObjectID !== null) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
return parent::getCellList(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clear the cell collection and disconnect from our parent |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function unsetWorksheetCells() { |
||||
|
if(!is_null($this->_currentObject)) { |
||||
|
$this->_currentObject->detach(); |
||||
|
$this->_currentObject = $this->_currentObjectID = null; |
||||
|
} |
||||
|
$this->_cellCache = array(); |
||||
|
|
||||
|
// detach ourself from the worksheet, so that it can then delete this object successfully |
||||
|
$this->_parent = null; |
||||
|
} // function unsetWorksheetCells() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Identify whether the caching method is currently available |
||||
|
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function cacheMethodIsAvailable() { |
||||
|
if (!function_exists('igbinary_serialize')) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,312 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CachedObjectStorage_Memcache |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { |
||||
|
|
||||
|
/** |
||||
|
* Prefix used to uniquely identify cache data for this worksheet |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_cachePrefix = null; |
||||
|
|
||||
|
/** |
||||
|
* Cache timeout |
||||
|
* |
||||
|
* @var integer |
||||
|
*/ |
||||
|
private $_cacheTime = 600; |
||||
|
|
||||
|
/** |
||||
|
* Memcache interface |
||||
|
* |
||||
|
* @var resource |
||||
|
*/ |
||||
|
private $_memcache = null; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Store cell data in cache for the current cell object if it's "dirty", |
||||
|
* and the 'nullify' the current cell object |
||||
|
* |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
protected function _storeData() { |
||||
|
if ($this->_currentCellIsDirty) { |
||||
|
$this->_currentObject->detach(); |
||||
|
|
||||
|
$obj = serialize($this->_currentObject); |
||||
|
if (!$this->_memcache->replace($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj,NULL,$this->_cacheTime)) { |
||||
|
if (!$this->_memcache->add($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj,NULL,$this->_cacheTime)) { |
||||
|
$this->__destruct(); |
||||
|
throw new PHPExcel_Exception('Failed to store cell '.$this->_currentObjectID.' in MemCache'); |
||||
|
} |
||||
|
} |
||||
|
$this->_currentCellIsDirty = false; |
||||
|
} |
||||
|
$this->_currentObjectID = $this->_currentObject = null; |
||||
|
} // function _storeData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Add or Update a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to update |
||||
|
* @param PHPExcel_Cell $cell Cell to update |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
||||
|
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
$this->_cellCache[$pCoord] = true; |
||||
|
|
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = $cell; |
||||
|
$this->_currentCellIsDirty = true; |
||||
|
|
||||
|
return $cell; |
||||
|
} // function addCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell? |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to check |
||||
|
* @return void |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function isDataSet($pCoord) { |
||||
|
// Check if the requested entry is the current object, or exists in the cache |
||||
|
if (parent::isDataSet($pCoord)) { |
||||
|
if ($this->_currentObjectID == $pCoord) { |
||||
|
return true; |
||||
|
} |
||||
|
// Check if the requested entry still exists in Memcache |
||||
|
$success = $this->_memcache->get($this->_cachePrefix.$pCoord.'.cache'); |
||||
|
if ($success === false) { |
||||
|
// Entry no longer exists in Memcache, so clear it from the cache array |
||||
|
parent::deleteCacheData($pCoord); |
||||
|
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in MemCache'); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} // function isDataSet() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get cell at a specific coordinate |
||||
|
* |
||||
|
* @param string $pCoord Coordinate of the cell |
||||
|
* @throws PHPExcel_Exception |
||||
|
* @return PHPExcel_Cell Cell that was found, or null if not found |
||||
|
*/ |
||||
|
public function getCacheData($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
return $this->_currentObject; |
||||
|
} |
||||
|
$this->_storeData(); |
||||
|
|
||||
|
// Check if the entry that has been requested actually exists |
||||
|
if (parent::isDataSet($pCoord)) { |
||||
|
$obj = $this->_memcache->get($this->_cachePrefix.$pCoord.'.cache'); |
||||
|
if ($obj === false) { |
||||
|
// Entry no longer exists in Memcache, so clear it from the cache array |
||||
|
parent::deleteCacheData($pCoord); |
||||
|
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in MemCache'); |
||||
|
} |
||||
|
} else { |
||||
|
// Return null if requested entry doesn't exist in cache |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
// Set current entry to the requested entry |
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = unserialize($obj); |
||||
|
// Re-attach this as the cell's parent |
||||
|
$this->_currentObject->attach($this); |
||||
|
|
||||
|
// Return requested entry |
||||
|
return $this->_currentObject; |
||||
|
} // function getCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get a list of all cell addresses currently held in cache |
||||
|
* |
||||
|
* @return array of string |
||||
|
*/ |
||||
|
public function getCellList() { |
||||
|
if ($this->_currentObjectID !== null) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
return parent::getCellList(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Delete a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to delete |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function deleteCacheData($pCoord) { |
||||
|
// Delete the entry from Memcache |
||||
|
$this->_memcache->delete($this->_cachePrefix.$pCoord.'.cache'); |
||||
|
|
||||
|
// Delete the entry from our cell address array |
||||
|
parent::deleteCacheData($pCoord); |
||||
|
} // function deleteCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clone the cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The new worksheet |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function copyCellCollection(PHPExcel_Worksheet $parent) { |
||||
|
parent::copyCellCollection($parent); |
||||
|
// Get a new id for the new file name |
||||
|
$baseUnique = $this->_getUniqueID(); |
||||
|
$newCachePrefix = substr(md5($baseUnique),0,8).'.'; |
||||
|
$cacheList = $this->getCellList(); |
||||
|
foreach($cacheList as $cellID) { |
||||
|
if ($cellID != $this->_currentObjectID) { |
||||
|
$obj = $this->_memcache->get($this->_cachePrefix.$cellID.'.cache'); |
||||
|
if ($obj === false) { |
||||
|
// Entry no longer exists in Memcache, so clear it from the cache array |
||||
|
parent::deleteCacheData($cellID); |
||||
|
throw new PHPExcel_Exception('Cell entry '.$cellID.' no longer exists in MemCache'); |
||||
|
} |
||||
|
if (!$this->_memcache->add($newCachePrefix.$cellID.'.cache',$obj,NULL,$this->_cacheTime)) { |
||||
|
$this->__destruct(); |
||||
|
throw new PHPExcel_Exception('Failed to store cell '.$cellID.' in MemCache'); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$this->_cachePrefix = $newCachePrefix; |
||||
|
} // function copyCellCollection() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clear the cell collection and disconnect from our parent |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function unsetWorksheetCells() { |
||||
|
if(!is_null($this->_currentObject)) { |
||||
|
$this->_currentObject->detach(); |
||||
|
$this->_currentObject = $this->_currentObjectID = null; |
||||
|
} |
||||
|
|
||||
|
// Flush the Memcache cache |
||||
|
$this->__destruct(); |
||||
|
|
||||
|
$this->_cellCache = array(); |
||||
|
|
||||
|
// detach ourself from the worksheet, so that it can then delete this object successfully |
||||
|
$this->_parent = null; |
||||
|
} // function unsetWorksheetCells() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Initialise this new cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection |
||||
|
* @param array of mixed $arguments Additional initialisation arguments |
||||
|
*/ |
||||
|
public function __construct(PHPExcel_Worksheet $parent, $arguments) { |
||||
|
$memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost'; |
||||
|
$memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211; |
||||
|
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; |
||||
|
|
||||
|
if (is_null($this->_cachePrefix)) { |
||||
|
$baseUnique = $this->_getUniqueID(); |
||||
|
$this->_cachePrefix = substr(md5($baseUnique),0,8).'.'; |
||||
|
|
||||
|
// Set a new Memcache object and connect to the Memcache server |
||||
|
$this->_memcache = new Memcache(); |
||||
|
if (!$this->_memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback'))) { |
||||
|
throw new PHPExcel_Exception('Could not connect to MemCache server at '.$memcacheServer.':'.$memcachePort); |
||||
|
} |
||||
|
$this->_cacheTime = $cacheTime; |
||||
|
|
||||
|
parent::__construct($parent); |
||||
|
} |
||||
|
} // function __construct() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Memcache error handler |
||||
|
* |
||||
|
* @param string $host Memcache server |
||||
|
* @param integer $port Memcache port |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function failureCallback($host, $port) { |
||||
|
throw new PHPExcel_Exception('memcache '.$host.':'.$port.' failed'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Destroy this cell collection |
||||
|
*/ |
||||
|
public function __destruct() { |
||||
|
$cacheList = $this->getCellList(); |
||||
|
foreach($cacheList as $cellID) { |
||||
|
$this->_memcache->delete($this->_cachePrefix.$cellID.'.cache'); |
||||
|
} |
||||
|
} // function __destruct() |
||||
|
|
||||
|
/** |
||||
|
* Identify whether the caching method is currently available |
||||
|
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function cacheMethodIsAvailable() { |
||||
|
if (!function_exists('memcache_add')) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,125 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CachedObjectStorage_Memory |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { |
||||
|
|
||||
|
/** |
||||
|
* Dummy method callable from CacheBase, but unused by Memory cache |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
protected function _storeData() { |
||||
|
} // function _storeData() |
||||
|
|
||||
|
/** |
||||
|
* Add or Update a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to update |
||||
|
* @param PHPExcel_Cell $cell Cell to update |
||||
|
* @return PHPExcel_Cell |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
||||
|
$this->_cellCache[$pCoord] = $cell; |
||||
|
|
||||
|
// Set current entry to the new/updated entry |
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
|
||||
|
return $cell; |
||||
|
} // function addCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get cell at a specific coordinate |
||||
|
* |
||||
|
* @param string $pCoord Coordinate of the cell |
||||
|
* @throws PHPExcel_Exception |
||||
|
* @return PHPExcel_Cell Cell that was found, or null if not found |
||||
|
*/ |
||||
|
public function getCacheData($pCoord) { |
||||
|
// Check if the entry that has been requested actually exists |
||||
|
if (!isset($this->_cellCache[$pCoord])) { |
||||
|
$this->_currentObjectID = NULL; |
||||
|
// Return null if requested entry doesn't exist in cache |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
// Set current entry to the requested entry |
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
|
||||
|
// Return requested entry |
||||
|
return $this->_cellCache[$pCoord]; |
||||
|
} // function getCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clone the cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The new worksheet |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function copyCellCollection(PHPExcel_Worksheet $parent) { |
||||
|
parent::copyCellCollection($parent); |
||||
|
|
||||
|
$newCollection = array(); |
||||
|
foreach($this->_cellCache as $k => &$cell) { |
||||
|
$newCollection[$k] = clone $cell; |
||||
|
$newCollection[$k]->attach($parent); |
||||
|
} |
||||
|
|
||||
|
$this->_cellCache = $newCollection; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clear the cell collection and disconnect from our parent |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function unsetWorksheetCells() { |
||||
|
// Because cells are all stored as intact objects in memory, we need to detach each one from the parent |
||||
|
foreach($this->_cellCache as $k => &$cell) { |
||||
|
$cell->detach(); |
||||
|
$this->_cellCache[$k] = null; |
||||
|
} |
||||
|
unset($cell); |
||||
|
|
||||
|
$this->_cellCache = array(); |
||||
|
|
||||
|
// detach ourself from the worksheet, so that it can then delete this object successfully |
||||
|
$this->_parent = null; |
||||
|
} // function unsetWorksheetCells() |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,137 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CachedObjectStorage_MemoryGZip |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { |
||||
|
|
||||
|
/** |
||||
|
* Store cell data in cache for the current cell object if it's "dirty", |
||||
|
* and the 'nullify' the current cell object |
||||
|
* |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
protected function _storeData() { |
||||
|
if ($this->_currentCellIsDirty) { |
||||
|
$this->_currentObject->detach(); |
||||
|
|
||||
|
$this->_cellCache[$this->_currentObjectID] = gzdeflate(serialize($this->_currentObject)); |
||||
|
$this->_currentCellIsDirty = false; |
||||
|
} |
||||
|
$this->_currentObjectID = $this->_currentObject = null; |
||||
|
} // function _storeData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Add or Update a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to update |
||||
|
* @param PHPExcel_Cell $cell Cell to update |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
||||
|
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = $cell; |
||||
|
$this->_currentCellIsDirty = true; |
||||
|
|
||||
|
return $cell; |
||||
|
} // function addCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get cell at a specific coordinate |
||||
|
* |
||||
|
* @param string $pCoord Coordinate of the cell |
||||
|
* @throws PHPExcel_Exception |
||||
|
* @return PHPExcel_Cell Cell that was found, or null if not found |
||||
|
*/ |
||||
|
public function getCacheData($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
return $this->_currentObject; |
||||
|
} |
||||
|
$this->_storeData(); |
||||
|
|
||||
|
// Check if the entry that has been requested actually exists |
||||
|
if (!isset($this->_cellCache[$pCoord])) { |
||||
|
// Return null if requested entry doesn't exist in cache |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
// Set current entry to the requested entry |
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = unserialize(gzinflate($this->_cellCache[$pCoord])); |
||||
|
// Re-attach this as the cell's parent |
||||
|
$this->_currentObject->attach($this); |
||||
|
|
||||
|
// Return requested entry |
||||
|
return $this->_currentObject; |
||||
|
} // function getCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get a list of all cell addresses currently held in cache |
||||
|
* |
||||
|
* @return array of string |
||||
|
*/ |
||||
|
public function getCellList() { |
||||
|
if ($this->_currentObjectID !== null) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
return parent::getCellList(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clear the cell collection and disconnect from our parent |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function unsetWorksheetCells() { |
||||
|
if(!is_null($this->_currentObject)) { |
||||
|
$this->_currentObject->detach(); |
||||
|
$this->_currentObject = $this->_currentObjectID = null; |
||||
|
} |
||||
|
$this->_cellCache = array(); |
||||
|
|
||||
|
// detach ourself from the worksheet, so that it can then delete this object successfully |
||||
|
$this->_parent = null; |
||||
|
} // function unsetWorksheetCells() |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,137 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CachedObjectStorage_MemorySerialized |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { |
||||
|
|
||||
|
/** |
||||
|
* Store cell data in cache for the current cell object if it's "dirty", |
||||
|
* and the 'nullify' the current cell object |
||||
|
* |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
protected function _storeData() { |
||||
|
if ($this->_currentCellIsDirty) { |
||||
|
$this->_currentObject->detach(); |
||||
|
|
||||
|
$this->_cellCache[$this->_currentObjectID] = serialize($this->_currentObject); |
||||
|
$this->_currentCellIsDirty = false; |
||||
|
} |
||||
|
$this->_currentObjectID = $this->_currentObject = null; |
||||
|
} // function _storeData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Add or Update a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to update |
||||
|
* @param PHPExcel_Cell $cell Cell to update |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
||||
|
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = $cell; |
||||
|
$this->_currentCellIsDirty = true; |
||||
|
|
||||
|
return $cell; |
||||
|
} // function addCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get cell at a specific coordinate |
||||
|
* |
||||
|
* @param string $pCoord Coordinate of the cell |
||||
|
* @throws PHPExcel_Exception |
||||
|
* @return PHPExcel_Cell Cell that was found, or null if not found |
||||
|
*/ |
||||
|
public function getCacheData($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
return $this->_currentObject; |
||||
|
} |
||||
|
$this->_storeData(); |
||||
|
|
||||
|
// Check if the entry that has been requested actually exists |
||||
|
if (!isset($this->_cellCache[$pCoord])) { |
||||
|
// Return null if requested entry doesn't exist in cache |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
// Set current entry to the requested entry |
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = unserialize($this->_cellCache[$pCoord]); |
||||
|
// Re-attach this as the cell's parent |
||||
|
$this->_currentObject->attach($this); |
||||
|
|
||||
|
// Return requested entry |
||||
|
return $this->_currentObject; |
||||
|
} // function getCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get a list of all cell addresses currently held in cache |
||||
|
* |
||||
|
* @return array of string |
||||
|
*/ |
||||
|
public function getCellList() { |
||||
|
if ($this->_currentObjectID !== null) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
return parent::getCellList(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clear the cell collection and disconnect from our parent |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function unsetWorksheetCells() { |
||||
|
if(!is_null($this->_currentObject)) { |
||||
|
$this->_currentObject->detach(); |
||||
|
$this->_currentObject = $this->_currentObjectID = null; |
||||
|
} |
||||
|
$this->_cellCache = array(); |
||||
|
|
||||
|
// detach ourself from the worksheet, so that it can then delete this object successfully |
||||
|
$this->_parent = null; |
||||
|
} // function unsetWorksheetCells() |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,206 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CachedObjectStorage_PHPTemp |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { |
||||
|
|
||||
|
/** |
||||
|
* Name of the file for this cache |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_fileHandle = null; |
||||
|
|
||||
|
/** |
||||
|
* Memory limit to use before reverting to file cache |
||||
|
* |
||||
|
* @var integer |
||||
|
*/ |
||||
|
private $_memoryCacheSize = null; |
||||
|
|
||||
|
/** |
||||
|
* Store cell data in cache for the current cell object if it's "dirty", |
||||
|
* and the 'nullify' the current cell object |
||||
|
* |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
protected function _storeData() { |
||||
|
if ($this->_currentCellIsDirty) { |
||||
|
$this->_currentObject->detach(); |
||||
|
|
||||
|
fseek($this->_fileHandle,0,SEEK_END); |
||||
|
$offset = ftell($this->_fileHandle); |
||||
|
fwrite($this->_fileHandle, serialize($this->_currentObject)); |
||||
|
$this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset, |
||||
|
'sz' => ftell($this->_fileHandle) - $offset |
||||
|
); |
||||
|
$this->_currentCellIsDirty = false; |
||||
|
} |
||||
|
$this->_currentObjectID = $this->_currentObject = null; |
||||
|
} // function _storeData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Add or Update a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to update |
||||
|
* @param PHPExcel_Cell $cell Cell to update |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
||||
|
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = $cell; |
||||
|
$this->_currentCellIsDirty = true; |
||||
|
|
||||
|
return $cell; |
||||
|
} // function addCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get cell at a specific coordinate |
||||
|
* |
||||
|
* @param string $pCoord Coordinate of the cell |
||||
|
* @throws PHPExcel_Exception |
||||
|
* @return PHPExcel_Cell Cell that was found, or null if not found |
||||
|
*/ |
||||
|
public function getCacheData($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
return $this->_currentObject; |
||||
|
} |
||||
|
$this->_storeData(); |
||||
|
|
||||
|
// Check if the entry that has been requested actually exists |
||||
|
if (!isset($this->_cellCache[$pCoord])) { |
||||
|
// Return null if requested entry doesn't exist in cache |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
// Set current entry to the requested entry |
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']); |
||||
|
$this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz'])); |
||||
|
// Re-attach this as the cell's parent |
||||
|
$this->_currentObject->attach($this); |
||||
|
|
||||
|
// Return requested entry |
||||
|
return $this->_currentObject; |
||||
|
} // function getCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get a list of all cell addresses currently held in cache |
||||
|
* |
||||
|
* @return array of string |
||||
|
*/ |
||||
|
public function getCellList() { |
||||
|
if ($this->_currentObjectID !== null) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
return parent::getCellList(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clone the cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The new worksheet |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function copyCellCollection(PHPExcel_Worksheet $parent) { |
||||
|
parent::copyCellCollection($parent); |
||||
|
// Open a new stream for the cell cache data |
||||
|
$newFileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+'); |
||||
|
// Copy the existing cell cache data to the new stream |
||||
|
fseek($this->_fileHandle,0); |
||||
|
while (!feof($this->_fileHandle)) { |
||||
|
fwrite($newFileHandle,fread($this->_fileHandle, 1024)); |
||||
|
} |
||||
|
$this->_fileHandle = $newFileHandle; |
||||
|
} // function copyCellCollection() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clear the cell collection and disconnect from our parent |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function unsetWorksheetCells() { |
||||
|
if(!is_null($this->_currentObject)) { |
||||
|
$this->_currentObject->detach(); |
||||
|
$this->_currentObject = $this->_currentObjectID = null; |
||||
|
} |
||||
|
$this->_cellCache = array(); |
||||
|
|
||||
|
// detach ourself from the worksheet, so that it can then delete this object successfully |
||||
|
$this->_parent = null; |
||||
|
|
||||
|
// Close down the php://temp file |
||||
|
$this->__destruct(); |
||||
|
} // function unsetWorksheetCells() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Initialise this new cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection |
||||
|
* @param array of mixed $arguments Additional initialisation arguments |
||||
|
*/ |
||||
|
public function __construct(PHPExcel_Worksheet $parent, $arguments) { |
||||
|
$this->_memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB'; |
||||
|
|
||||
|
parent::__construct($parent); |
||||
|
if (is_null($this->_fileHandle)) { |
||||
|
$this->_fileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+'); |
||||
|
} |
||||
|
} // function __construct() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Destroy this cell collection |
||||
|
*/ |
||||
|
public function __destruct() { |
||||
|
if (!is_null($this->_fileHandle)) { |
||||
|
fclose($this->_fileHandle); |
||||
|
} |
||||
|
$this->_fileHandle = null; |
||||
|
} // function __destruct() |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,306 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CachedObjectStorage_SQLite |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { |
||||
|
|
||||
|
/** |
||||
|
* Database table name |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_TableName = null; |
||||
|
|
||||
|
/** |
||||
|
* Database handle |
||||
|
* |
||||
|
* @var resource |
||||
|
*/ |
||||
|
private $_DBHandle = null; |
||||
|
|
||||
|
/** |
||||
|
* Store cell data in cache for the current cell object if it's "dirty", |
||||
|
* and the 'nullify' the current cell object |
||||
|
* |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
protected function _storeData() { |
||||
|
if ($this->_currentCellIsDirty) { |
||||
|
$this->_currentObject->detach(); |
||||
|
|
||||
|
if (!$this->_DBHandle->queryExec("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES('".$this->_currentObjectID."','".sqlite_escape_string(serialize($this->_currentObject))."')")) |
||||
|
throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); |
||||
|
$this->_currentCellIsDirty = false; |
||||
|
} |
||||
|
$this->_currentObjectID = $this->_currentObject = null; |
||||
|
} // function _storeData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Add or Update a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to update |
||||
|
* @param PHPExcel_Cell $cell Cell to update |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
||||
|
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = $cell; |
||||
|
$this->_currentCellIsDirty = true; |
||||
|
|
||||
|
return $cell; |
||||
|
} // function addCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get cell at a specific coordinate |
||||
|
* |
||||
|
* @param string $pCoord Coordinate of the cell |
||||
|
* @throws PHPExcel_Exception |
||||
|
* @return PHPExcel_Cell Cell that was found, or null if not found |
||||
|
*/ |
||||
|
public function getCacheData($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
return $this->_currentObject; |
||||
|
} |
||||
|
$this->_storeData(); |
||||
|
|
||||
|
$query = "SELECT value FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'"; |
||||
|
$cellResultSet = $this->_DBHandle->query($query,SQLITE_ASSOC); |
||||
|
if ($cellResultSet === false) { |
||||
|
throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); |
||||
|
} elseif ($cellResultSet->numRows() == 0) { |
||||
|
// Return null if requested entry doesn't exist in cache |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
// Set current entry to the requested entry |
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
|
||||
|
$cellResult = $cellResultSet->fetchSingle(); |
||||
|
$this->_currentObject = unserialize($cellResult); |
||||
|
// Re-attach this as the cell's parent |
||||
|
$this->_currentObject->attach($this); |
||||
|
|
||||
|
// Return requested entry |
||||
|
return $this->_currentObject; |
||||
|
} // function getCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Is a value set for an indexed cell? |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function isDataSet($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// Check if the requested entry exists in the cache |
||||
|
$query = "SELECT id FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'"; |
||||
|
$cellResultSet = $this->_DBHandle->query($query,SQLITE_ASSOC); |
||||
|
if ($cellResultSet === false) { |
||||
|
throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); |
||||
|
} elseif ($cellResultSet->numRows() == 0) { |
||||
|
// Return null if requested entry doesn't exist in cache |
||||
|
return false; |
||||
|
} |
||||
|
return true; |
||||
|
} // function isDataSet() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Delete a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to delete |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function deleteCacheData($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
$this->_currentObject->detach(); |
||||
|
$this->_currentObjectID = $this->_currentObject = null; |
||||
|
} |
||||
|
|
||||
|
// Check if the requested entry exists in the cache |
||||
|
$query = "DELETE FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'"; |
||||
|
if (!$this->_DBHandle->queryExec($query)) |
||||
|
throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); |
||||
|
|
||||
|
$this->_currentCellIsDirty = false; |
||||
|
} // function deleteCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Move a cell object from one address to another |
||||
|
* |
||||
|
* @param string $fromAddress Current address of the cell to move |
||||
|
* @param string $toAddress Destination address of the cell to move |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function moveCell($fromAddress, $toAddress) { |
||||
|
if ($fromAddress === $this->_currentObjectID) { |
||||
|
$this->_currentObjectID = $toAddress; |
||||
|
} |
||||
|
|
||||
|
$query = "DELETE FROM kvp_".$this->_TableName." WHERE id='".$toAddress."'"; |
||||
|
$result = $this->_DBHandle->exec($query); |
||||
|
if ($result === false) |
||||
|
throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); |
||||
|
|
||||
|
$query = "UPDATE kvp_".$this->_TableName." SET id='".$toAddress."' WHERE id='".$fromAddress."'"; |
||||
|
$result = $this->_DBHandle->exec($query); |
||||
|
if ($result === false) |
||||
|
throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); |
||||
|
|
||||
|
return TRUE; |
||||
|
} // function moveCell() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get a list of all cell addresses currently held in cache |
||||
|
* |
||||
|
* @return array of string |
||||
|
*/ |
||||
|
public function getCellList() { |
||||
|
if ($this->_currentObjectID !== null) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
$query = "SELECT id FROM kvp_".$this->_TableName; |
||||
|
$cellIdsResult = $this->_DBHandle->unbufferedQuery($query,SQLITE_ASSOC); |
||||
|
if ($cellIdsResult === false) |
||||
|
throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); |
||||
|
|
||||
|
$cellKeys = array(); |
||||
|
foreach($cellIdsResult as $row) { |
||||
|
$cellKeys[] = $row['id']; |
||||
|
} |
||||
|
|
||||
|
return $cellKeys; |
||||
|
} // function getCellList() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clone the cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The new worksheet |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function copyCellCollection(PHPExcel_Worksheet $parent) { |
||||
|
$this->_currentCellIsDirty; |
||||
|
$this->_storeData(); |
||||
|
|
||||
|
// Get a new id for the new table name |
||||
|
$tableName = str_replace('.','_',$this->_getUniqueID()); |
||||
|
if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB) |
||||
|
AS SELECT * FROM kvp_'.$this->_TableName)) |
||||
|
throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); |
||||
|
|
||||
|
// Copy the existing cell cache file |
||||
|
$this->_TableName = $tableName; |
||||
|
} // function copyCellCollection() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clear the cell collection and disconnect from our parent |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function unsetWorksheetCells() { |
||||
|
if(!is_null($this->_currentObject)) { |
||||
|
$this->_currentObject->detach(); |
||||
|
$this->_currentObject = $this->_currentObjectID = null; |
||||
|
} |
||||
|
// detach ourself from the worksheet, so that it can then delete this object successfully |
||||
|
$this->_parent = null; |
||||
|
|
||||
|
// Close down the temporary cache file |
||||
|
$this->__destruct(); |
||||
|
} // function unsetWorksheetCells() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Initialise this new cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection |
||||
|
*/ |
||||
|
public function __construct(PHPExcel_Worksheet $parent) { |
||||
|
parent::__construct($parent); |
||||
|
if (is_null($this->_DBHandle)) { |
||||
|
$this->_TableName = str_replace('.','_',$this->_getUniqueID()); |
||||
|
$_DBName = ':memory:'; |
||||
|
|
||||
|
$this->_DBHandle = new SQLiteDatabase($_DBName); |
||||
|
if ($this->_DBHandle === false) |
||||
|
throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); |
||||
|
if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) |
||||
|
throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); |
||||
|
} |
||||
|
} // function __construct() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Destroy this cell collection |
||||
|
*/ |
||||
|
public function __destruct() { |
||||
|
if (!is_null($this->_DBHandle)) { |
||||
|
$this->_DBHandle->queryExec('DROP TABLE kvp_'.$this->_TableName); |
||||
|
} |
||||
|
$this->_DBHandle = null; |
||||
|
} // function __destruct() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Identify whether the caching method is currently available |
||||
|
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function cacheMethodIsAvailable() { |
||||
|
if (!function_exists('sqlite_open')) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,345 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CachedObjectStorage_SQLite3 |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { |
||||
|
|
||||
|
/** |
||||
|
* Database table name |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_TableName = null; |
||||
|
|
||||
|
/** |
||||
|
* Database handle |
||||
|
* |
||||
|
* @var resource |
||||
|
*/ |
||||
|
private $_DBHandle = null; |
||||
|
|
||||
|
/** |
||||
|
* Prepared statement for a SQLite3 select query |
||||
|
* |
||||
|
* @var SQLite3Stmt |
||||
|
*/ |
||||
|
private $_selectQuery; |
||||
|
|
||||
|
/** |
||||
|
* Prepared statement for a SQLite3 insert query |
||||
|
* |
||||
|
* @var SQLite3Stmt |
||||
|
*/ |
||||
|
private $_insertQuery; |
||||
|
|
||||
|
/** |
||||
|
* Prepared statement for a SQLite3 update query |
||||
|
* |
||||
|
* @var SQLite3Stmt |
||||
|
*/ |
||||
|
private $_updateQuery; |
||||
|
|
||||
|
/** |
||||
|
* Prepared statement for a SQLite3 delete query |
||||
|
* |
||||
|
* @var SQLite3Stmt |
||||
|
*/ |
||||
|
private $_deleteQuery; |
||||
|
|
||||
|
/** |
||||
|
* Store cell data in cache for the current cell object if it's "dirty", |
||||
|
* and the 'nullify' the current cell object |
||||
|
* |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
protected function _storeData() { |
||||
|
if ($this->_currentCellIsDirty) { |
||||
|
$this->_currentObject->detach(); |
||||
|
|
||||
|
$this->_insertQuery->bindValue('id',$this->_currentObjectID,SQLITE3_TEXT); |
||||
|
$this->_insertQuery->bindValue('data',serialize($this->_currentObject),SQLITE3_BLOB); |
||||
|
$result = $this->_insertQuery->execute(); |
||||
|
if ($result === false) |
||||
|
throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); |
||||
|
$this->_currentCellIsDirty = false; |
||||
|
} |
||||
|
$this->_currentObjectID = $this->_currentObject = null; |
||||
|
} // function _storeData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Add or Update a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to update |
||||
|
* @param PHPExcel_Cell $cell Cell to update |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
||||
|
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = $cell; |
||||
|
$this->_currentCellIsDirty = true; |
||||
|
|
||||
|
return $cell; |
||||
|
} // function addCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get cell at a specific coordinate |
||||
|
* |
||||
|
* @param string $pCoord Coordinate of the cell |
||||
|
* @throws PHPExcel_Exception |
||||
|
* @return PHPExcel_Cell Cell that was found, or null if not found |
||||
|
*/ |
||||
|
public function getCacheData($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
return $this->_currentObject; |
||||
|
} |
||||
|
$this->_storeData(); |
||||
|
|
||||
|
$this->_selectQuery->bindValue('id',$pCoord,SQLITE3_TEXT); |
||||
|
$cellResult = $this->_selectQuery->execute(); |
||||
|
if ($cellResult === FALSE) { |
||||
|
throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); |
||||
|
} |
||||
|
$cellData = $cellResult->fetchArray(SQLITE3_ASSOC); |
||||
|
if ($cellData === FALSE) { |
||||
|
// Return null if requested entry doesn't exist in cache |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
// Set current entry to the requested entry |
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
|
||||
|
$this->_currentObject = unserialize($cellData['value']); |
||||
|
// Re-attach this as the cell's parent |
||||
|
$this->_currentObject->attach($this); |
||||
|
|
||||
|
// Return requested entry |
||||
|
return $this->_currentObject; |
||||
|
} // function getCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Is a value set for an indexed cell? |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function isDataSet($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
return TRUE; |
||||
|
} |
||||
|
|
||||
|
// Check if the requested entry exists in the cache |
||||
|
$this->_selectQuery->bindValue('id',$pCoord,SQLITE3_TEXT); |
||||
|
$cellResult = $this->_selectQuery->execute(); |
||||
|
if ($cellResult === FALSE) { |
||||
|
throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); |
||||
|
} |
||||
|
$cellData = $cellResult->fetchArray(SQLITE3_ASSOC); |
||||
|
|
||||
|
return ($cellData === FALSE) ? FALSE : TRUE; |
||||
|
} // function isDataSet() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Delete a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to delete |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function deleteCacheData($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
$this->_currentObject->detach(); |
||||
|
$this->_currentObjectID = $this->_currentObject = NULL; |
||||
|
} |
||||
|
|
||||
|
// Check if the requested entry exists in the cache |
||||
|
$this->_deleteQuery->bindValue('id',$pCoord,SQLITE3_TEXT); |
||||
|
$result = $this->_deleteQuery->execute(); |
||||
|
if ($result === FALSE) |
||||
|
throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); |
||||
|
|
||||
|
$this->_currentCellIsDirty = FALSE; |
||||
|
} // function deleteCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Move a cell object from one address to another |
||||
|
* |
||||
|
* @param string $fromAddress Current address of the cell to move |
||||
|
* @param string $toAddress Destination address of the cell to move |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function moveCell($fromAddress, $toAddress) { |
||||
|
if ($fromAddress === $this->_currentObjectID) { |
||||
|
$this->_currentObjectID = $toAddress; |
||||
|
} |
||||
|
|
||||
|
$this->_deleteQuery->bindValue('id',$toAddress,SQLITE3_TEXT); |
||||
|
$result = $this->_deleteQuery->execute(); |
||||
|
if ($result === false) |
||||
|
throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); |
||||
|
|
||||
|
$this->_updateQuery->bindValue('toid',$toAddress,SQLITE3_TEXT); |
||||
|
$this->_updateQuery->bindValue('fromid',$fromAddress,SQLITE3_TEXT); |
||||
|
$result = $this->_updateQuery->execute(); |
||||
|
if ($result === false) |
||||
|
throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); |
||||
|
|
||||
|
return TRUE; |
||||
|
} // function moveCell() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get a list of all cell addresses currently held in cache |
||||
|
* |
||||
|
* @return array of string |
||||
|
*/ |
||||
|
public function getCellList() { |
||||
|
if ($this->_currentObjectID !== null) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
$query = "SELECT id FROM kvp_".$this->_TableName; |
||||
|
$cellIdsResult = $this->_DBHandle->query($query); |
||||
|
if ($cellIdsResult === false) |
||||
|
throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); |
||||
|
|
||||
|
$cellKeys = array(); |
||||
|
while ($row = $cellIdsResult->fetchArray(SQLITE3_ASSOC)) { |
||||
|
$cellKeys[] = $row['id']; |
||||
|
} |
||||
|
|
||||
|
return $cellKeys; |
||||
|
} // function getCellList() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clone the cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The new worksheet |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function copyCellCollection(PHPExcel_Worksheet $parent) { |
||||
|
$this->_currentCellIsDirty; |
||||
|
$this->_storeData(); |
||||
|
|
||||
|
// Get a new id for the new table name |
||||
|
$tableName = str_replace('.','_',$this->_getUniqueID()); |
||||
|
if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB) |
||||
|
AS SELECT * FROM kvp_'.$this->_TableName)) |
||||
|
throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); |
||||
|
|
||||
|
// Copy the existing cell cache file |
||||
|
$this->_TableName = $tableName; |
||||
|
} // function copyCellCollection() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clear the cell collection and disconnect from our parent |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function unsetWorksheetCells() { |
||||
|
if(!is_null($this->_currentObject)) { |
||||
|
$this->_currentObject->detach(); |
||||
|
$this->_currentObject = $this->_currentObjectID = null; |
||||
|
} |
||||
|
// detach ourself from the worksheet, so that it can then delete this object successfully |
||||
|
$this->_parent = null; |
||||
|
|
||||
|
// Close down the temporary cache file |
||||
|
$this->__destruct(); |
||||
|
} // function unsetWorksheetCells() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Initialise this new cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection |
||||
|
*/ |
||||
|
public function __construct(PHPExcel_Worksheet $parent) { |
||||
|
parent::__construct($parent); |
||||
|
if (is_null($this->_DBHandle)) { |
||||
|
$this->_TableName = str_replace('.','_',$this->_getUniqueID()); |
||||
|
$_DBName = ':memory:'; |
||||
|
|
||||
|
$this->_DBHandle = new SQLite3($_DBName); |
||||
|
if ($this->_DBHandle === false) |
||||
|
throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); |
||||
|
if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) |
||||
|
throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); |
||||
|
} |
||||
|
|
||||
|
$this->_selectQuery = $this->_DBHandle->prepare("SELECT value FROM kvp_".$this->_TableName." WHERE id = :id"); |
||||
|
$this->_insertQuery = $this->_DBHandle->prepare("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES(:id,:data)"); |
||||
|
$this->_updateQuery = $this->_DBHandle->prepare("UPDATE kvp_".$this->_TableName." SET id=:toId WHERE id=:fromId"); |
||||
|
$this->_deleteQuery = $this->_DBHandle->prepare("DELETE FROM kvp_".$this->_TableName." WHERE id = :id"); |
||||
|
} // function __construct() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Destroy this cell collection |
||||
|
*/ |
||||
|
public function __destruct() { |
||||
|
if (!is_null($this->_DBHandle)) { |
||||
|
$this->_DBHandle->exec('DROP TABLE kvp_'.$this->_TableName); |
||||
|
$this->_DBHandle->close(); |
||||
|
} |
||||
|
$this->_DBHandle = null; |
||||
|
} // function __destruct() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Identify whether the caching method is currently available |
||||
|
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function cacheMethodIsAvailable() { |
||||
|
if (!class_exists('SQLite3',FALSE)) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,294 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CachedObjectStorage_Wincache |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_CachedObjectStorage |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { |
||||
|
|
||||
|
/** |
||||
|
* Prefix used to uniquely identify cache data for this worksheet |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_cachePrefix = null; |
||||
|
|
||||
|
/** |
||||
|
* Cache timeout |
||||
|
* |
||||
|
* @var integer |
||||
|
*/ |
||||
|
private $_cacheTime = 600; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Store cell data in cache for the current cell object if it's "dirty", |
||||
|
* and the 'nullify' the current cell object |
||||
|
* |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
protected function _storeData() { |
||||
|
if ($this->_currentCellIsDirty) { |
||||
|
$this->_currentObject->detach(); |
||||
|
|
||||
|
$obj = serialize($this->_currentObject); |
||||
|
if (wincache_ucache_exists($this->_cachePrefix.$this->_currentObjectID.'.cache')) { |
||||
|
if (!wincache_ucache_set($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) { |
||||
|
$this->__destruct(); |
||||
|
throw new PHPExcel_Exception('Failed to store cell '.$this->_currentObjectID.' in WinCache'); |
||||
|
} |
||||
|
} else { |
||||
|
if (!wincache_ucache_add($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) { |
||||
|
$this->__destruct(); |
||||
|
throw new PHPExcel_Exception('Failed to store cell '.$this->_currentObjectID.' in WinCache'); |
||||
|
} |
||||
|
} |
||||
|
$this->_currentCellIsDirty = false; |
||||
|
} |
||||
|
|
||||
|
$this->_currentObjectID = $this->_currentObject = null; |
||||
|
} // function _storeData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Add or Update a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to update |
||||
|
* @param PHPExcel_Cell $cell Cell to update |
||||
|
* @return void |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
||||
|
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
$this->_cellCache[$pCoord] = true; |
||||
|
|
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = $cell; |
||||
|
$this->_currentCellIsDirty = true; |
||||
|
|
||||
|
return $cell; |
||||
|
} // function addCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell? |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function isDataSet($pCoord) { |
||||
|
// Check if the requested entry is the current object, or exists in the cache |
||||
|
if (parent::isDataSet($pCoord)) { |
||||
|
if ($this->_currentObjectID == $pCoord) { |
||||
|
return true; |
||||
|
} |
||||
|
// Check if the requested entry still exists in cache |
||||
|
$success = wincache_ucache_exists($this->_cachePrefix.$pCoord.'.cache'); |
||||
|
if ($success === false) { |
||||
|
// Entry no longer exists in Wincache, so clear it from the cache array |
||||
|
parent::deleteCacheData($pCoord); |
||||
|
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in WinCache'); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} // function isDataSet() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get cell at a specific coordinate |
||||
|
* |
||||
|
* @param string $pCoord Coordinate of the cell |
||||
|
* @throws PHPExcel_Exception |
||||
|
* @return PHPExcel_Cell Cell that was found, or null if not found |
||||
|
*/ |
||||
|
public function getCacheData($pCoord) { |
||||
|
if ($pCoord === $this->_currentObjectID) { |
||||
|
return $this->_currentObject; |
||||
|
} |
||||
|
$this->_storeData(); |
||||
|
|
||||
|
// Check if the entry that has been requested actually exists |
||||
|
$obj = null; |
||||
|
if (parent::isDataSet($pCoord)) { |
||||
|
$success = false; |
||||
|
$obj = wincache_ucache_get($this->_cachePrefix.$pCoord.'.cache', $success); |
||||
|
if ($success === false) { |
||||
|
// Entry no longer exists in WinCache, so clear it from the cache array |
||||
|
parent::deleteCacheData($pCoord); |
||||
|
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in WinCache'); |
||||
|
} |
||||
|
} else { |
||||
|
// Return null if requested entry doesn't exist in cache |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
// Set current entry to the requested entry |
||||
|
$this->_currentObjectID = $pCoord; |
||||
|
$this->_currentObject = unserialize($obj); |
||||
|
// Re-attach this as the cell's parent |
||||
|
$this->_currentObject->attach($this); |
||||
|
|
||||
|
// Return requested entry |
||||
|
return $this->_currentObject; |
||||
|
} // function getCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get a list of all cell addresses currently held in cache |
||||
|
* |
||||
|
* @return array of string |
||||
|
*/ |
||||
|
public function getCellList() { |
||||
|
if ($this->_currentObjectID !== null) { |
||||
|
$this->_storeData(); |
||||
|
} |
||||
|
|
||||
|
return parent::getCellList(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Delete a cell in cache identified by coordinate address |
||||
|
* |
||||
|
* @param string $pCoord Coordinate address of the cell to delete |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public function deleteCacheData($pCoord) { |
||||
|
// Delete the entry from Wincache |
||||
|
wincache_ucache_delete($this->_cachePrefix.$pCoord.'.cache'); |
||||
|
|
||||
|
// Delete the entry from our cell address array |
||||
|
parent::deleteCacheData($pCoord); |
||||
|
} // function deleteCacheData() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clone the cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The new worksheet |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function copyCellCollection(PHPExcel_Worksheet $parent) { |
||||
|
parent::copyCellCollection($parent); |
||||
|
// Get a new id for the new file name |
||||
|
$baseUnique = $this->_getUniqueID(); |
||||
|
$newCachePrefix = substr(md5($baseUnique),0,8).'.'; |
||||
|
$cacheList = $this->getCellList(); |
||||
|
foreach($cacheList as $cellID) { |
||||
|
if ($cellID != $this->_currentObjectID) { |
||||
|
$success = false; |
||||
|
$obj = wincache_ucache_get($this->_cachePrefix.$cellID.'.cache', $success); |
||||
|
if ($success === false) { |
||||
|
// Entry no longer exists in WinCache, so clear it from the cache array |
||||
|
parent::deleteCacheData($cellID); |
||||
|
throw new PHPExcel_Exception('Cell entry '.$cellID.' no longer exists in Wincache'); |
||||
|
} |
||||
|
if (!wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->_cacheTime)) { |
||||
|
$this->__destruct(); |
||||
|
throw new PHPExcel_Exception('Failed to store cell '.$cellID.' in Wincache'); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$this->_cachePrefix = $newCachePrefix; |
||||
|
} // function copyCellCollection() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Clear the cell collection and disconnect from our parent |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function unsetWorksheetCells() { |
||||
|
if(!is_null($this->_currentObject)) { |
||||
|
$this->_currentObject->detach(); |
||||
|
$this->_currentObject = $this->_currentObjectID = null; |
||||
|
} |
||||
|
|
||||
|
// Flush the WinCache cache |
||||
|
$this->__destruct(); |
||||
|
|
||||
|
$this->_cellCache = array(); |
||||
|
|
||||
|
// detach ourself from the worksheet, so that it can then delete this object successfully |
||||
|
$this->_parent = null; |
||||
|
} // function unsetWorksheetCells() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Initialise this new cell collection |
||||
|
* |
||||
|
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection |
||||
|
* @param array of mixed $arguments Additional initialisation arguments |
||||
|
*/ |
||||
|
public function __construct(PHPExcel_Worksheet $parent, $arguments) { |
||||
|
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; |
||||
|
|
||||
|
if (is_null($this->_cachePrefix)) { |
||||
|
$baseUnique = $this->_getUniqueID(); |
||||
|
$this->_cachePrefix = substr(md5($baseUnique),0,8).'.'; |
||||
|
$this->_cacheTime = $cacheTime; |
||||
|
|
||||
|
parent::__construct($parent); |
||||
|
} |
||||
|
} // function __construct() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Destroy this cell collection |
||||
|
*/ |
||||
|
public function __destruct() { |
||||
|
$cacheList = $this->getCellList(); |
||||
|
foreach($cacheList as $cellID) { |
||||
|
wincache_ucache_delete($this->_cachePrefix.$cellID.'.cache'); |
||||
|
} |
||||
|
} // function __destruct() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Identify whether the caching method is currently available |
||||
|
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function cacheMethodIsAvailable() { |
||||
|
if (!function_exists('wincache_ucache_add')) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,98 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CalcEngine_CyclicReferenceStack |
||||
|
* |
||||
|
* @category PHPExcel_CalcEngine_CyclicReferenceStack |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_CalcEngine_CyclicReferenceStack { |
||||
|
|
||||
|
/** |
||||
|
* The call stack for calculated cells |
||||
|
* |
||||
|
* @var mixed[] |
||||
|
*/ |
||||
|
private $_stack = array(); |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Return the number of entries on the stack |
||||
|
* |
||||
|
* @return integer |
||||
|
*/ |
||||
|
public function count() { |
||||
|
return count($this->_stack); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Push a new entry onto the stack |
||||
|
* |
||||
|
* @param mixed $value |
||||
|
*/ |
||||
|
public function push($value) { |
||||
|
$this->_stack[] = $value; |
||||
|
} // function push() |
||||
|
|
||||
|
/** |
||||
|
* Pop the last entry from the stack |
||||
|
* |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function pop() { |
||||
|
return array_pop($this->_stack); |
||||
|
} // function pop() |
||||
|
|
||||
|
/** |
||||
|
* Test to see if a specified entry exists on the stack |
||||
|
* |
||||
|
* @param mixed $value The value to test |
||||
|
*/ |
||||
|
public function onStack($value) { |
||||
|
return in_array($value, $this->_stack); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Clear the stack |
||||
|
*/ |
||||
|
public function clear() { |
||||
|
$this->_stack = array(); |
||||
|
} // function push() |
||||
|
|
||||
|
/** |
||||
|
* Return an array of all entries on the stack |
||||
|
* |
||||
|
* @return mixed[] |
||||
|
*/ |
||||
|
public function showStack() { |
||||
|
return $this->_stack; |
||||
|
} |
||||
|
|
||||
|
} // class PHPExcel_CalcEngine_CyclicReferenceStack |
||||
@ -0,0 +1,153 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_CalcEngine_Logger |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_CalcEngine_Logger { |
||||
|
|
||||
|
/** |
||||
|
* Flag to determine whether a debug log should be generated by the calculation engine |
||||
|
* If true, then a debug log will be generated |
||||
|
* If false, then a debug log will not be generated |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_writeDebugLog = FALSE; |
||||
|
|
||||
|
/** |
||||
|
* Flag to determine whether a debug log should be echoed by the calculation engine |
||||
|
* If true, then a debug log will be echoed |
||||
|
* If false, then a debug log will not be echoed |
||||
|
* A debug log can only be echoed if it is generated |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_echoDebugLog = FALSE; |
||||
|
|
||||
|
/** |
||||
|
* The debug log generated by the calculation engine |
||||
|
* |
||||
|
* @var string[] |
||||
|
*/ |
||||
|
private $_debugLog = array(); |
||||
|
|
||||
|
/** |
||||
|
* The calculation engine cell reference stack |
||||
|
* |
||||
|
* @var PHPExcel_CalcEngine_CyclicReferenceStack |
||||
|
*/ |
||||
|
private $_cellStack; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Instantiate a Calculation engine logger |
||||
|
* |
||||
|
* @param PHPExcel_CalcEngine_CyclicReferenceStack $stack |
||||
|
*/ |
||||
|
public function __construct(PHPExcel_CalcEngine_CyclicReferenceStack $stack) { |
||||
|
$this->_cellStack = $stack; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Enable/Disable Calculation engine logging |
||||
|
* |
||||
|
* @param boolean $pValue |
||||
|
*/ |
||||
|
public function setWriteDebugLog($pValue = FALSE) { |
||||
|
$this->_writeDebugLog = $pValue; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Return whether calculation engine logging is enabled or disabled |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getWriteDebugLog() { |
||||
|
return $this->_writeDebugLog; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Enable/Disable echoing of debug log information |
||||
|
* |
||||
|
* @param boolean $pValue |
||||
|
*/ |
||||
|
public function setEchoDebugLog($pValue = FALSE) { |
||||
|
$this->_echoDebugLog = $pValue; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Return whether echoing of debug log information is enabled or disabled |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getEchoDebugLog() { |
||||
|
return $this->_echoDebugLog; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Write an entry to the calculation engine debug log |
||||
|
*/ |
||||
|
public function writeDebugLog() { |
||||
|
// Only write the debug log if logging is enabled |
||||
|
if ($this->_writeDebugLog) { |
||||
|
$message = implode(func_get_args()); |
||||
|
$cellReference = implode(' -> ', $this->_cellStack->showStack()); |
||||
|
if ($this->_echoDebugLog) { |
||||
|
echo $cellReference, |
||||
|
($this->_cellStack->count() > 0 ? ' => ' : ''), |
||||
|
$message, |
||||
|
PHP_EOL; |
||||
|
} |
||||
|
$this->_debugLog[] = $cellReference . |
||||
|
($this->_cellStack->count() > 0 ? ' => ' : '') . |
||||
|
$message; |
||||
|
} |
||||
|
} // function _writeDebug() |
||||
|
|
||||
|
/** |
||||
|
* Clear the calculation engine debug log |
||||
|
*/ |
||||
|
public function clearLog() { |
||||
|
$this->_debugLog = array(); |
||||
|
} // function flushLogger() |
||||
|
|
||||
|
/** |
||||
|
* Return the calculation engine debug log |
||||
|
* |
||||
|
* @return string[] |
||||
|
*/ |
||||
|
public function getLog() { |
||||
|
return $this->_debugLog; |
||||
|
} // function flushLogger() |
||||
|
|
||||
|
} // class PHPExcel_CalcEngine_Logger |
||||
|
|
||||
@ -0,0 +1,725 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** PHPExcel root directory */ |
||||
|
if (!defined('PHPEXCEL_ROOT')) { |
||||
|
/** |
||||
|
* @ignore |
||||
|
*/ |
||||
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
||||
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Calculation_Database |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Calculation_Database { |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* __fieldExtract |
||||
|
* |
||||
|
* Extracts the column ID to use for the data field. |
||||
|
* |
||||
|
* @access private |
||||
|
* @param mixed[] $database The range of cells that makes up the list or database. |
||||
|
* A database is a list of related data in which rows of related |
||||
|
* information are records, and columns of data are fields. The |
||||
|
* first row of the list contains labels for each column. |
||||
|
* @param mixed $field Indicates which column is used in the function. Enter the |
||||
|
* column label enclosed between double quotation marks, such as |
||||
|
* "Age" or "Yield," or a number (without quotation marks) that |
||||
|
* represents the position of the column within the list: 1 for |
||||
|
* the first column, 2 for the second column, and so on. |
||||
|
* @return string|NULL |
||||
|
* |
||||
|
*/ |
||||
|
private static function __fieldExtract($database,$field) { |
||||
|
$field = strtoupper(PHPExcel_Calculation_Functions::flattenSingleValue($field)); |
||||
|
$fieldNames = array_map('strtoupper',array_shift($database)); |
||||
|
|
||||
|
if (is_numeric($field)) { |
||||
|
$keys = array_keys($fieldNames); |
||||
|
return $keys[$field-1]; |
||||
|
} |
||||
|
$key = array_search($field,$fieldNames); |
||||
|
return ($key) ? $key : NULL; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* __filter |
||||
|
* |
||||
|
* Parses the selection criteria, extracts the database rows that match those criteria, and |
||||
|
* returns that subset of rows. |
||||
|
* |
||||
|
* @access private |
||||
|
* @param mixed[] $database The range of cells that makes up the list or database. |
||||
|
* A database is a list of related data in which rows of related |
||||
|
* information are records, and columns of data are fields. The |
||||
|
* first row of the list contains labels for each column. |
||||
|
* @param mixed[] $criteria The range of cells that contains the conditions you specify. |
||||
|
* You can use any range for the criteria argument, as long as it |
||||
|
* includes at least one column label and at least one cell below |
||||
|
* the column label in which you specify a condition for the |
||||
|
* column. |
||||
|
* @return array of mixed |
||||
|
* |
||||
|
*/ |
||||
|
private static function __filter($database,$criteria) { |
||||
|
$fieldNames = array_shift($database); |
||||
|
$criteriaNames = array_shift($criteria); |
||||
|
|
||||
|
// Convert the criteria into a set of AND/OR conditions with [:placeholders] |
||||
|
$testConditions = $testValues = array(); |
||||
|
$testConditionsCount = 0; |
||||
|
foreach($criteriaNames as $key => $criteriaName) { |
||||
|
$testCondition = array(); |
||||
|
$testConditionCount = 0; |
||||
|
foreach($criteria as $row => $criterion) { |
||||
|
if ($criterion[$key] > '') { |
||||
|
$testCondition[] = '[:'.$criteriaName.']'.PHPExcel_Calculation_Functions::_ifCondition($criterion[$key]); |
||||
|
$testConditionCount++; |
||||
|
} |
||||
|
} |
||||
|
if ($testConditionCount > 1) { |
||||
|
$testConditions[] = 'OR('.implode(',',$testCondition).')'; |
||||
|
$testConditionsCount++; |
||||
|
} elseif($testConditionCount == 1) { |
||||
|
$testConditions[] = $testCondition[0]; |
||||
|
$testConditionsCount++; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if ($testConditionsCount > 1) { |
||||
|
$testConditionSet = 'AND('.implode(',',$testConditions).')'; |
||||
|
} elseif($testConditionsCount == 1) { |
||||
|
$testConditionSet = $testConditions[0]; |
||||
|
} |
||||
|
|
||||
|
// Loop through each row of the database |
||||
|
foreach($database as $dataRow => $dataValues) { |
||||
|
// Substitute actual values from the database row for our [:placeholders] |
||||
|
$testConditionList = $testConditionSet; |
||||
|
foreach($criteriaNames as $key => $criteriaName) { |
||||
|
$k = array_search($criteriaName,$fieldNames); |
||||
|
if (isset($dataValues[$k])) { |
||||
|
$dataValue = $dataValues[$k]; |
||||
|
$dataValue = (is_string($dataValue)) ? PHPExcel_Calculation::_wrapResult(strtoupper($dataValue)) : $dataValue; |
||||
|
$testConditionList = str_replace('[:'.$criteriaName.']',$dataValue,$testConditionList); |
||||
|
} |
||||
|
} |
||||
|
// evaluate the criteria against the row data |
||||
|
$result = PHPExcel_Calculation::getInstance()->_calculateFormulaValue('='.$testConditionList); |
||||
|
// If the row failed to meet the criteria, remove it from the database |
||||
|
if (!$result) { |
||||
|
unset($database[$dataRow]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $database; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DAVERAGE |
||||
|
* |
||||
|
* Averages the values in a column of a list or database that match conditions you specify. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* DAVERAGE(database,field,criteria) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Database Functions |
||||
|
* @param mixed[] $database The range of cells that makes up the list or database. |
||||
|
* A database is a list of related data in which rows of related |
||||
|
* information are records, and columns of data are fields. The |
||||
|
* first row of the list contains labels for each column. |
||||
|
* @param string|integer $field Indicates which column is used in the function. Enter the |
||||
|
* column label enclosed between double quotation marks, such as |
||||
|
* "Age" or "Yield," or a number (without quotation marks) that |
||||
|
* represents the position of the column within the list: 1 for |
||||
|
* the first column, 2 for the second column, and so on. |
||||
|
* @param mixed[] $criteria The range of cells that contains the conditions you specify. |
||||
|
* You can use any range for the criteria argument, as long as it |
||||
|
* includes at least one column label and at least one cell below |
||||
|
* the column label in which you specify a condition for the |
||||
|
* column. |
||||
|
* @return float |
||||
|
* |
||||
|
*/ |
||||
|
public static function DAVERAGE($database,$field,$criteria) { |
||||
|
$field = self::__fieldExtract($database,$field); |
||||
|
if (is_null($field)) { |
||||
|
return NULL; |
||||
|
} |
||||
|
// reduce the database to a set of rows that match all the criteria |
||||
|
$database = self::__filter($database,$criteria); |
||||
|
// extract an array of values for the requested column |
||||
|
$colData = array(); |
||||
|
foreach($database as $row) { |
||||
|
$colData[] = $row[$field]; |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
return PHPExcel_Calculation_Statistical::AVERAGE($colData); |
||||
|
} // function DAVERAGE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DCOUNT |
||||
|
* |
||||
|
* Counts the cells that contain numbers in a column of a list or database that match conditions |
||||
|
* that you specify. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* DCOUNT(database,[field],criteria) |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* DAVERAGE(database,field,criteria) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Database Functions |
||||
|
* @param mixed[] $database The range of cells that makes up the list or database. |
||||
|
* A database is a list of related data in which rows of related |
||||
|
* information are records, and columns of data are fields. The |
||||
|
* first row of the list contains labels for each column. |
||||
|
* @param string|integer $field Indicates which column is used in the function. Enter the |
||||
|
* column label enclosed between double quotation marks, such as |
||||
|
* "Age" or "Yield," or a number (without quotation marks) that |
||||
|
* represents the position of the column within the list: 1 for |
||||
|
* the first column, 2 for the second column, and so on. |
||||
|
* @param mixed[] $criteria The range of cells that contains the conditions you specify. |
||||
|
* You can use any range for the criteria argument, as long as it |
||||
|
* includes at least one column label and at least one cell below |
||||
|
* the column label in which you specify a condition for the |
||||
|
* column. |
||||
|
* @return integer |
||||
|
* |
||||
|
* @TODO The field argument is optional. If field is omitted, DCOUNT counts all records in the |
||||
|
* database that match the criteria. |
||||
|
* |
||||
|
*/ |
||||
|
public static function DCOUNT($database,$field,$criteria) { |
||||
|
$field = self::__fieldExtract($database,$field); |
||||
|
if (is_null($field)) { |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
// reduce the database to a set of rows that match all the criteria |
||||
|
$database = self::__filter($database,$criteria); |
||||
|
// extract an array of values for the requested column |
||||
|
$colData = array(); |
||||
|
foreach($database as $row) { |
||||
|
$colData[] = $row[$field]; |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
return PHPExcel_Calculation_Statistical::COUNT($colData); |
||||
|
} // function DCOUNT() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DCOUNTA |
||||
|
* |
||||
|
* Counts the nonblank cells in a column of a list or database that match conditions that you specify. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* DCOUNTA(database,[field],criteria) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Database Functions |
||||
|
* @param mixed[] $database The range of cells that makes up the list or database. |
||||
|
* A database is a list of related data in which rows of related |
||||
|
* information are records, and columns of data are fields. The |
||||
|
* first row of the list contains labels for each column. |
||||
|
* @param string|integer $field Indicates which column is used in the function. Enter the |
||||
|
* column label enclosed between double quotation marks, such as |
||||
|
* "Age" or "Yield," or a number (without quotation marks) that |
||||
|
* represents the position of the column within the list: 1 for |
||||
|
* the first column, 2 for the second column, and so on. |
||||
|
* @param mixed[] $criteria The range of cells that contains the conditions you specify. |
||||
|
* You can use any range for the criteria argument, as long as it |
||||
|
* includes at least one column label and at least one cell below |
||||
|
* the column label in which you specify a condition for the |
||||
|
* column. |
||||
|
* @return integer |
||||
|
* |
||||
|
* @TODO The field argument is optional. If field is omitted, DCOUNTA counts all records in the |
||||
|
* database that match the criteria. |
||||
|
* |
||||
|
*/ |
||||
|
public static function DCOUNTA($database,$field,$criteria) { |
||||
|
$field = self::__fieldExtract($database,$field); |
||||
|
if (is_null($field)) { |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
// reduce the database to a set of rows that match all the criteria |
||||
|
$database = self::__filter($database,$criteria); |
||||
|
// extract an array of values for the requested column |
||||
|
$colData = array(); |
||||
|
foreach($database as $row) { |
||||
|
$colData[] = $row[$field]; |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
return PHPExcel_Calculation_Statistical::COUNTA($colData); |
||||
|
} // function DCOUNTA() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DGET |
||||
|
* |
||||
|
* Extracts a single value from a column of a list or database that matches conditions that you |
||||
|
* specify. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* DGET(database,field,criteria) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Database Functions |
||||
|
* @param mixed[] $database The range of cells that makes up the list or database. |
||||
|
* A database is a list of related data in which rows of related |
||||
|
* information are records, and columns of data are fields. The |
||||
|
* first row of the list contains labels for each column. |
||||
|
* @param string|integer $field Indicates which column is used in the function. Enter the |
||||
|
* column label enclosed between double quotation marks, such as |
||||
|
* "Age" or "Yield," or a number (without quotation marks) that |
||||
|
* represents the position of the column within the list: 1 for |
||||
|
* the first column, 2 for the second column, and so on. |
||||
|
* @param mixed[] $criteria The range of cells that contains the conditions you specify. |
||||
|
* You can use any range for the criteria argument, as long as it |
||||
|
* includes at least one column label and at least one cell below |
||||
|
* the column label in which you specify a condition for the |
||||
|
* column. |
||||
|
* @return mixed |
||||
|
* |
||||
|
*/ |
||||
|
public static function DGET($database,$field,$criteria) { |
||||
|
$field = self::__fieldExtract($database,$field); |
||||
|
if (is_null($field)) { |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
// reduce the database to a set of rows that match all the criteria |
||||
|
$database = self::__filter($database,$criteria); |
||||
|
// extract an array of values for the requested column |
||||
|
$colData = array(); |
||||
|
foreach($database as $row) { |
||||
|
$colData[] = $row[$field]; |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
if (count($colData) > 1) { |
||||
|
return PHPExcel_Calculation_Functions::NaN(); |
||||
|
} |
||||
|
|
||||
|
return $colData[0]; |
||||
|
} // function DGET() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DMAX |
||||
|
* |
||||
|
* Returns the largest number in a column of a list or database that matches conditions you that |
||||
|
* specify. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* DMAX(database,field,criteria) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Database Functions |
||||
|
* @param mixed[] $database The range of cells that makes up the list or database. |
||||
|
* A database is a list of related data in which rows of related |
||||
|
* information are records, and columns of data are fields. The |
||||
|
* first row of the list contains labels for each column. |
||||
|
* @param string|integer $field Indicates which column is used in the function. Enter the |
||||
|
* column label enclosed between double quotation marks, such as |
||||
|
* "Age" or "Yield," or a number (without quotation marks) that |
||||
|
* represents the position of the column within the list: 1 for |
||||
|
* the first column, 2 for the second column, and so on. |
||||
|
* @param mixed[] $criteria The range of cells that contains the conditions you specify. |
||||
|
* You can use any range for the criteria argument, as long as it |
||||
|
* includes at least one column label and at least one cell below |
||||
|
* the column label in which you specify a condition for the |
||||
|
* column. |
||||
|
* @return float |
||||
|
* |
||||
|
*/ |
||||
|
public static function DMAX($database,$field,$criteria) { |
||||
|
$field = self::__fieldExtract($database,$field); |
||||
|
if (is_null($field)) { |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
// reduce the database to a set of rows that match all the criteria |
||||
|
$database = self::__filter($database,$criteria); |
||||
|
// extract an array of values for the requested column |
||||
|
$colData = array(); |
||||
|
foreach($database as $row) { |
||||
|
$colData[] = $row[$field]; |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
return PHPExcel_Calculation_Statistical::MAX($colData); |
||||
|
} // function DMAX() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DMIN |
||||
|
* |
||||
|
* Returns the smallest number in a column of a list or database that matches conditions you that |
||||
|
* specify. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* DMIN(database,field,criteria) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Database Functions |
||||
|
* @param mixed[] $database The range of cells that makes up the list or database. |
||||
|
* A database is a list of related data in which rows of related |
||||
|
* information are records, and columns of data are fields. The |
||||
|
* first row of the list contains labels for each column. |
||||
|
* @param string|integer $field Indicates which column is used in the function. Enter the |
||||
|
* column label enclosed between double quotation marks, such as |
||||
|
* "Age" or "Yield," or a number (without quotation marks) that |
||||
|
* represents the position of the column within the list: 1 for |
||||
|
* the first column, 2 for the second column, and so on. |
||||
|
* @param mixed[] $criteria The range of cells that contains the conditions you specify. |
||||
|
* You can use any range for the criteria argument, as long as it |
||||
|
* includes at least one column label and at least one cell below |
||||
|
* the column label in which you specify a condition for the |
||||
|
* column. |
||||
|
* @return float |
||||
|
* |
||||
|
*/ |
||||
|
public static function DMIN($database,$field,$criteria) { |
||||
|
$field = self::__fieldExtract($database,$field); |
||||
|
if (is_null($field)) { |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
// reduce the database to a set of rows that match all the criteria |
||||
|
$database = self::__filter($database,$criteria); |
||||
|
// extract an array of values for the requested column |
||||
|
$colData = array(); |
||||
|
foreach($database as $row) { |
||||
|
$colData[] = $row[$field]; |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
return PHPExcel_Calculation_Statistical::MIN($colData); |
||||
|
} // function DMIN() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DPRODUCT |
||||
|
* |
||||
|
* Multiplies the values in a column of a list or database that match conditions that you specify. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* DPRODUCT(database,field,criteria) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Database Functions |
||||
|
* @param mixed[] $database The range of cells that makes up the list or database. |
||||
|
* A database is a list of related data in which rows of related |
||||
|
* information are records, and columns of data are fields. The |
||||
|
* first row of the list contains labels for each column. |
||||
|
* @param string|integer $field Indicates which column is used in the function. Enter the |
||||
|
* column label enclosed between double quotation marks, such as |
||||
|
* "Age" or "Yield," or a number (without quotation marks) that |
||||
|
* represents the position of the column within the list: 1 for |
||||
|
* the first column, 2 for the second column, and so on. |
||||
|
* @param mixed[] $criteria The range of cells that contains the conditions you specify. |
||||
|
* You can use any range for the criteria argument, as long as it |
||||
|
* includes at least one column label and at least one cell below |
||||
|
* the column label in which you specify a condition for the |
||||
|
* column. |
||||
|
* @return float |
||||
|
* |
||||
|
*/ |
||||
|
public static function DPRODUCT($database,$field,$criteria) { |
||||
|
$field = self::__fieldExtract($database,$field); |
||||
|
if (is_null($field)) { |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
// reduce the database to a set of rows that match all the criteria |
||||
|
$database = self::__filter($database,$criteria); |
||||
|
// extract an array of values for the requested column |
||||
|
$colData = array(); |
||||
|
foreach($database as $row) { |
||||
|
$colData[] = $row[$field]; |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
return PHPExcel_Calculation_MathTrig::PRODUCT($colData); |
||||
|
} // function DPRODUCT() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DSTDEV |
||||
|
* |
||||
|
* Estimates the standard deviation of a population based on a sample by using the numbers in a |
||||
|
* column of a list or database that match conditions that you specify. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* DSTDEV(database,field,criteria) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Database Functions |
||||
|
* @param mixed[] $database The range of cells that makes up the list or database. |
||||
|
* A database is a list of related data in which rows of related |
||||
|
* information are records, and columns of data are fields. The |
||||
|
* first row of the list contains labels for each column. |
||||
|
* @param string|integer $field Indicates which column is used in the function. Enter the |
||||
|
* column label enclosed between double quotation marks, such as |
||||
|
* "Age" or "Yield," or a number (without quotation marks) that |
||||
|
* represents the position of the column within the list: 1 for |
||||
|
* the first column, 2 for the second column, and so on. |
||||
|
* @param mixed[] $criteria The range of cells that contains the conditions you specify. |
||||
|
* You can use any range for the criteria argument, as long as it |
||||
|
* includes at least one column label and at least one cell below |
||||
|
* the column label in which you specify a condition for the |
||||
|
* column. |
||||
|
* @return float |
||||
|
* |
||||
|
*/ |
||||
|
public static function DSTDEV($database,$field,$criteria) { |
||||
|
$field = self::__fieldExtract($database,$field); |
||||
|
if (is_null($field)) { |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
// reduce the database to a set of rows that match all the criteria |
||||
|
$database = self::__filter($database,$criteria); |
||||
|
// extract an array of values for the requested column |
||||
|
$colData = array(); |
||||
|
foreach($database as $row) { |
||||
|
$colData[] = $row[$field]; |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
return PHPExcel_Calculation_Statistical::STDEV($colData); |
||||
|
} // function DSTDEV() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DSTDEVP |
||||
|
* |
||||
|
* Calculates the standard deviation of a population based on the entire population by using the |
||||
|
* numbers in a column of a list or database that match conditions that you specify. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* DSTDEVP(database,field,criteria) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Database Functions |
||||
|
* @param mixed[] $database The range of cells that makes up the list or database. |
||||
|
* A database is a list of related data in which rows of related |
||||
|
* information are records, and columns of data are fields. The |
||||
|
* first row of the list contains labels for each column. |
||||
|
* @param string|integer $field Indicates which column is used in the function. Enter the |
||||
|
* column label enclosed between double quotation marks, such as |
||||
|
* "Age" or "Yield," or a number (without quotation marks) that |
||||
|
* represents the position of the column within the list: 1 for |
||||
|
* the first column, 2 for the second column, and so on. |
||||
|
* @param mixed[] $criteria The range of cells that contains the conditions you specify. |
||||
|
* You can use any range for the criteria argument, as long as it |
||||
|
* includes at least one column label and at least one cell below |
||||
|
* the column label in which you specify a condition for the |
||||
|
* column. |
||||
|
* @return float |
||||
|
* |
||||
|
*/ |
||||
|
public static function DSTDEVP($database,$field,$criteria) { |
||||
|
$field = self::__fieldExtract($database,$field); |
||||
|
if (is_null($field)) { |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
// reduce the database to a set of rows that match all the criteria |
||||
|
$database = self::__filter($database,$criteria); |
||||
|
// extract an array of values for the requested column |
||||
|
$colData = array(); |
||||
|
foreach($database as $row) { |
||||
|
$colData[] = $row[$field]; |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
return PHPExcel_Calculation_Statistical::STDEVP($colData); |
||||
|
} // function DSTDEVP() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DSUM |
||||
|
* |
||||
|
* Adds the numbers in a column of a list or database that match conditions that you specify. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* DSUM(database,field,criteria) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Database Functions |
||||
|
* @param mixed[] $database The range of cells that makes up the list or database. |
||||
|
* A database is a list of related data in which rows of related |
||||
|
* information are records, and columns of data are fields. The |
||||
|
* first row of the list contains labels for each column. |
||||
|
* @param string|integer $field Indicates which column is used in the function. Enter the |
||||
|
* column label enclosed between double quotation marks, such as |
||||
|
* "Age" or "Yield," or a number (without quotation marks) that |
||||
|
* represents the position of the column within the list: 1 for |
||||
|
* the first column, 2 for the second column, and so on. |
||||
|
* @param mixed[] $criteria The range of cells that contains the conditions you specify. |
||||
|
* You can use any range for the criteria argument, as long as it |
||||
|
* includes at least one column label and at least one cell below |
||||
|
* the column label in which you specify a condition for the |
||||
|
* column. |
||||
|
* @return float |
||||
|
* |
||||
|
*/ |
||||
|
public static function DSUM($database,$field,$criteria) { |
||||
|
$field = self::__fieldExtract($database,$field); |
||||
|
if (is_null($field)) { |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
// reduce the database to a set of rows that match all the criteria |
||||
|
$database = self::__filter($database,$criteria); |
||||
|
// extract an array of values for the requested column |
||||
|
$colData = array(); |
||||
|
foreach($database as $row) { |
||||
|
$colData[] = $row[$field]; |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
return PHPExcel_Calculation_MathTrig::SUM($colData); |
||||
|
} // function DSUM() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DVAR |
||||
|
* |
||||
|
* Estimates the variance of a population based on a sample by using the numbers in a column |
||||
|
* of a list or database that match conditions that you specify. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* DVAR(database,field,criteria) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Database Functions |
||||
|
* @param mixed[] $database The range of cells that makes up the list or database. |
||||
|
* A database is a list of related data in which rows of related |
||||
|
* information are records, and columns of data are fields. The |
||||
|
* first row of the list contains labels for each column. |
||||
|
* @param string|integer $field Indicates which column is used in the function. Enter the |
||||
|
* column label enclosed between double quotation marks, such as |
||||
|
* "Age" or "Yield," or a number (without quotation marks) that |
||||
|
* represents the position of the column within the list: 1 for |
||||
|
* the first column, 2 for the second column, and so on. |
||||
|
* @param mixed[] $criteria The range of cells that contains the conditions you specify. |
||||
|
* You can use any range for the criteria argument, as long as it |
||||
|
* includes at least one column label and at least one cell below |
||||
|
* the column label in which you specify a condition for the |
||||
|
* column. |
||||
|
* @return float |
||||
|
* |
||||
|
*/ |
||||
|
public static function DVAR($database,$field,$criteria) { |
||||
|
$field = self::__fieldExtract($database,$field); |
||||
|
if (is_null($field)) { |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
// reduce the database to a set of rows that match all the criteria |
||||
|
$database = self::__filter($database,$criteria); |
||||
|
// extract an array of values for the requested column |
||||
|
$colData = array(); |
||||
|
foreach($database as $row) { |
||||
|
$colData[] = $row[$field]; |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
return PHPExcel_Calculation_Statistical::VARFunc($colData); |
||||
|
} // function DVAR() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DVARP |
||||
|
* |
||||
|
* Calculates the variance of a population based on the entire population by using the numbers |
||||
|
* in a column of a list or database that match conditions that you specify. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* DVARP(database,field,criteria) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Database Functions |
||||
|
* @param mixed[] $database The range of cells that makes up the list or database. |
||||
|
* A database is a list of related data in which rows of related |
||||
|
* information are records, and columns of data are fields. The |
||||
|
* first row of the list contains labels for each column. |
||||
|
* @param string|integer $field Indicates which column is used in the function. Enter the |
||||
|
* column label enclosed between double quotation marks, such as |
||||
|
* "Age" or "Yield," or a number (without quotation marks) that |
||||
|
* represents the position of the column within the list: 1 for |
||||
|
* the first column, 2 for the second column, and so on. |
||||
|
* @param mixed[] $criteria The range of cells that contains the conditions you specify. |
||||
|
* You can use any range for the criteria argument, as long as it |
||||
|
* includes at least one column label and at least one cell below |
||||
|
* the column label in which you specify a condition for the |
||||
|
* column. |
||||
|
* @return float |
||||
|
* |
||||
|
*/ |
||||
|
public static function DVARP($database,$field,$criteria) { |
||||
|
$field = self::__fieldExtract($database,$field); |
||||
|
if (is_null($field)) { |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
// reduce the database to a set of rows that match all the criteria |
||||
|
$database = self::__filter($database,$criteria); |
||||
|
// extract an array of values for the requested column |
||||
|
$colData = array(); |
||||
|
foreach($database as $row) { |
||||
|
$colData[] = $row[$field]; |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
return PHPExcel_Calculation_Statistical::VARP($colData); |
||||
|
} // function DVARP() |
||||
|
|
||||
|
|
||||
|
} // class PHPExcel_Calculation_Database |
||||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,52 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Calculation_Exception |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Calculation_Exception extends PHPExcel_Exception { |
||||
|
/** |
||||
|
* Error handler callback |
||||
|
* |
||||
|
* @param mixed $code |
||||
|
* @param mixed $string |
||||
|
* @param mixed $file |
||||
|
* @param mixed $line |
||||
|
* @param mixed $context |
||||
|
*/ |
||||
|
public static function errorHandlerCallback($code, $string, $file, $line, $context) { |
||||
|
$e = new self($string, $code); |
||||
|
$e->line = $line; |
||||
|
$e->file = $file; |
||||
|
throw $e; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,49 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Calculation_ExceptionHandler |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Calculation_ExceptionHandler { |
||||
|
/** |
||||
|
* Register errorhandler |
||||
|
*/ |
||||
|
public function __construct() { |
||||
|
set_error_handler(array('PHPExcel_Calculation_Exception', 'errorHandlerCallback'), E_ALL); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Unregister errorhandler |
||||
|
*/ |
||||
|
public function __destruct() { |
||||
|
restore_error_handler(); |
||||
|
} |
||||
|
} |
||||
File diff suppressed because it is too large
@ -0,0 +1,614 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/* |
||||
|
PARTLY BASED ON: |
||||
|
Copyright (c) 2007 E. W. Bachtal, Inc. |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
||||
|
and associated documentation files (the "Software"), to deal in the Software without restriction, |
||||
|
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
|
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, |
||||
|
subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial |
||||
|
portions of the Software. |
||||
|
|
||||
|
The software is provided "as is", without warranty of any kind, express or implied, including but not |
||||
|
limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In |
||||
|
no event shall the authors or copyright holders be liable for any claim, damages or other liability, |
||||
|
whether in an action of contract, tort or otherwise, arising from, out of or in connection with the |
||||
|
software or the use or other dealings in the software. |
||||
|
|
||||
|
http://ewbi.blogs.com/develops/2007/03/excel_formula_p.html |
||||
|
http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Calculation_FormulaParser |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Calculation_FormulaParser { |
||||
|
/* Character constants */ |
||||
|
const QUOTE_DOUBLE = '"'; |
||||
|
const QUOTE_SINGLE = '\''; |
||||
|
const BRACKET_CLOSE = ']'; |
||||
|
const BRACKET_OPEN = '['; |
||||
|
const BRACE_OPEN = '{'; |
||||
|
const BRACE_CLOSE = '}'; |
||||
|
const PAREN_OPEN = '('; |
||||
|
const PAREN_CLOSE = ')'; |
||||
|
const SEMICOLON = ';'; |
||||
|
const WHITESPACE = ' '; |
||||
|
const COMMA = ','; |
||||
|
const ERROR_START = '#'; |
||||
|
|
||||
|
const OPERATORS_SN = "+-"; |
||||
|
const OPERATORS_INFIX = "+-*/^&=><"; |
||||
|
const OPERATORS_POSTFIX = "%"; |
||||
|
|
||||
|
/** |
||||
|
* Formula |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_formula; |
||||
|
|
||||
|
/** |
||||
|
* Tokens |
||||
|
* |
||||
|
* @var PHPExcel_Calculation_FormulaToken[] |
||||
|
*/ |
||||
|
private $_tokens = array(); |
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Calculation_FormulaParser |
||||
|
* |
||||
|
* @param string $pFormula Formula to parse |
||||
|
* @throws PHPExcel_Calculation_Exception |
||||
|
*/ |
||||
|
public function __construct($pFormula = '') |
||||
|
{ |
||||
|
// Check parameters |
||||
|
if (is_null($pFormula)) { |
||||
|
throw new PHPExcel_Calculation_Exception("Invalid parameter passed: formula"); |
||||
|
} |
||||
|
|
||||
|
// Initialise values |
||||
|
$this->_formula = trim($pFormula); |
||||
|
// Parse! |
||||
|
$this->_parseToTokens(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Formula |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getFormula() { |
||||
|
return $this->_formula; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Token |
||||
|
* |
||||
|
* @param int $pId Token id |
||||
|
* @return string |
||||
|
* @throws PHPExcel_Calculation_Exception |
||||
|
*/ |
||||
|
public function getToken($pId = 0) { |
||||
|
if (isset($this->_tokens[$pId])) { |
||||
|
return $this->_tokens[$pId]; |
||||
|
} else { |
||||
|
throw new PHPExcel_Calculation_Exception("Token with id $pId does not exist."); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Token count |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getTokenCount() { |
||||
|
return count($this->_tokens); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Tokens |
||||
|
* |
||||
|
* @return PHPExcel_Calculation_FormulaToken[] |
||||
|
*/ |
||||
|
public function getTokens() { |
||||
|
return $this->_tokens; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Parse to tokens |
||||
|
*/ |
||||
|
private function _parseToTokens() { |
||||
|
// No attempt is made to verify formulas; assumes formulas are derived from Excel, where |
||||
|
// they can only exist if valid; stack overflows/underflows sunk as nulls without exceptions. |
||||
|
|
||||
|
// Check if the formula has a valid starting = |
||||
|
$formulaLength = strlen($this->_formula); |
||||
|
if ($formulaLength < 2 || $this->_formula{0} != '=') return; |
||||
|
|
||||
|
// Helper variables |
||||
|
$tokens1 = $tokens2 = $stack = array(); |
||||
|
$inString = $inPath = $inRange = $inError = false; |
||||
|
$token = $previousToken = $nextToken = null; |
||||
|
|
||||
|
$index = 1; |
||||
|
$value = ''; |
||||
|
|
||||
|
$ERRORS = array("#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A"); |
||||
|
$COMPARATORS_MULTI = array(">=", "<=", "<>"); |
||||
|
|
||||
|
while ($index < $formulaLength) { |
||||
|
// state-dependent character evaluation (order is important) |
||||
|
|
||||
|
// double-quoted strings |
||||
|
// embeds are doubled |
||||
|
// end marks token |
||||
|
if ($inString) { |
||||
|
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) { |
||||
|
if ((($index + 2) <= $formulaLength) && ($this->_formula{$index + 1} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE)) { |
||||
|
$value .= PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE; |
||||
|
++$index; |
||||
|
} else { |
||||
|
$inString = false; |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_TEXT); |
||||
|
$value = ""; |
||||
|
} |
||||
|
} else { |
||||
|
$value .= $this->_formula{$index}; |
||||
|
} |
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// single-quoted strings (links) |
||||
|
// embeds are double |
||||
|
// end does not mark a token |
||||
|
if ($inPath) { |
||||
|
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) { |
||||
|
if ((($index + 2) <= $formulaLength) && ($this->_formula{$index + 1} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE)) { |
||||
|
$value .= PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE; |
||||
|
++$index; |
||||
|
} else { |
||||
|
$inPath = false; |
||||
|
} |
||||
|
} else { |
||||
|
$value .= $this->_formula{$index}; |
||||
|
} |
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// bracked strings (R1C1 range index or linked workbook name) |
||||
|
// no embeds (changed to "()" by Excel) |
||||
|
// end does not mark a token |
||||
|
if ($inRange) { |
||||
|
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACKET_CLOSE) { |
||||
|
$inRange = false; |
||||
|
} |
||||
|
$value .= $this->_formula{$index}; |
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// error values |
||||
|
// end marks a token, determined from absolute list of values |
||||
|
if ($inError) { |
||||
|
$value .= $this->_formula{$index}; |
||||
|
++$index; |
||||
|
if (in_array($value, $ERRORS)) { |
||||
|
$inError = false; |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_ERROR); |
||||
|
$value = ""; |
||||
|
} |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// scientific notation check |
||||
|
if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_SN, $this->_formula{$index}) !== false) { |
||||
|
if (strlen($value) > 1) { |
||||
|
if (preg_match("/^[1-9]{1}(\.[0-9]+)?E{1}$/", $this->_formula{$index}) != 0) { |
||||
|
$value .= $this->_formula{$index}; |
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// independent character evaluation (order not important) |
||||
|
|
||||
|
// establish state-dependent character evaluations |
||||
|
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) { |
||||
|
if (strlen($value > 0)) { // unexpected |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); |
||||
|
$value = ""; |
||||
|
} |
||||
|
$inString = true; |
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) { |
||||
|
if (strlen($value) > 0) { // unexpected |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); |
||||
|
$value = ""; |
||||
|
} |
||||
|
$inPath = true; |
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACKET_OPEN) { |
||||
|
$inRange = true; |
||||
|
$value .= PHPExcel_Calculation_FormulaParser::BRACKET_OPEN; |
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::ERROR_START) { |
||||
|
if (strlen($value) > 0) { // unexpected |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); |
||||
|
$value = ""; |
||||
|
} |
||||
|
$inError = true; |
||||
|
$value .= PHPExcel_Calculation_FormulaParser::ERROR_START; |
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// mark start and end of arrays and array rows |
||||
|
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACE_OPEN) { |
||||
|
if (strlen($value) > 0) { // unexpected |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); |
||||
|
$value = ""; |
||||
|
} |
||||
|
|
||||
|
$tmp = new PHPExcel_Calculation_FormulaToken("ARRAY", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); |
||||
|
$tokens1[] = $tmp; |
||||
|
$stack[] = clone $tmp; |
||||
|
|
||||
|
$tmp = new PHPExcel_Calculation_FormulaToken("ARRAYROW", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); |
||||
|
$tokens1[] = $tmp; |
||||
|
$stack[] = clone $tmp; |
||||
|
|
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::SEMICOLON) { |
||||
|
if (strlen($value) > 0) { |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); |
||||
|
$value = ""; |
||||
|
} |
||||
|
|
||||
|
$tmp = array_pop($stack); |
||||
|
$tmp->setValue(""); |
||||
|
$tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); |
||||
|
$tokens1[] = $tmp; |
||||
|
|
||||
|
$tmp = new PHPExcel_Calculation_FormulaToken(",", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_ARGUMENT); |
||||
|
$tokens1[] = $tmp; |
||||
|
|
||||
|
$tmp = new PHPExcel_Calculation_FormulaToken("ARRAYROW", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); |
||||
|
$tokens1[] = $tmp; |
||||
|
$stack[] = clone $tmp; |
||||
|
|
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACE_CLOSE) { |
||||
|
if (strlen($value) > 0) { |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); |
||||
|
$value = ""; |
||||
|
} |
||||
|
|
||||
|
$tmp = array_pop($stack); |
||||
|
$tmp->setValue(""); |
||||
|
$tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); |
||||
|
$tokens1[] = $tmp; |
||||
|
|
||||
|
$tmp = array_pop($stack); |
||||
|
$tmp->setValue(""); |
||||
|
$tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); |
||||
|
$tokens1[] = $tmp; |
||||
|
|
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// trim white-space |
||||
|
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::WHITESPACE) { |
||||
|
if (strlen($value) > 0) { |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); |
||||
|
$value = ""; |
||||
|
} |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken("", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_WHITESPACE); |
||||
|
++$index; |
||||
|
while (($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::WHITESPACE) && ($index < $formulaLength)) { |
||||
|
++$index; |
||||
|
} |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// multi-character comparators |
||||
|
if (($index + 2) <= $formulaLength) { |
||||
|
if (in_array(substr($this->_formula, $index, 2), $COMPARATORS_MULTI)) { |
||||
|
if (strlen($value) > 0) { |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); |
||||
|
$value = ""; |
||||
|
} |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken(substr($this->_formula, $index, 2), PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL); |
||||
|
$index += 2; |
||||
|
continue; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// standard infix operators |
||||
|
if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_INFIX, $this->_formula{$index}) !== false) { |
||||
|
if (strlen($value) > 0) { |
||||
|
$tokens1[] =new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); |
||||
|
$value = ""; |
||||
|
} |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($this->_formula{$index}, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX); |
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// standard postfix operators (only one) |
||||
|
if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_POSTFIX, $this->_formula{$index}) !== false) { |
||||
|
if (strlen($value) > 0) { |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); |
||||
|
$value = ""; |
||||
|
} |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($this->_formula{$index}, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX); |
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// start subexpression or function |
||||
|
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::PAREN_OPEN) { |
||||
|
if (strlen($value) > 0) { |
||||
|
$tmp = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); |
||||
|
$tokens1[] = $tmp; |
||||
|
$stack[] = clone $tmp; |
||||
|
$value = ""; |
||||
|
} else { |
||||
|
$tmp = new PHPExcel_Calculation_FormulaToken("", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); |
||||
|
$tokens1[] = $tmp; |
||||
|
$stack[] = clone $tmp; |
||||
|
} |
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// function, subexpression, or array parameters, or operand unions |
||||
|
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::COMMA) { |
||||
|
if (strlen($value) > 0) { |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); |
||||
|
$value = ""; |
||||
|
} |
||||
|
|
||||
|
$tmp = array_pop($stack); |
||||
|
$tmp->setValue(""); |
||||
|
$tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); |
||||
|
$stack[] = $tmp; |
||||
|
|
||||
|
if ($tmp->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) { |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken(",", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_UNION); |
||||
|
} else { |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken(",", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_ARGUMENT); |
||||
|
} |
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// stop subexpression |
||||
|
if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::PAREN_CLOSE) { |
||||
|
if (strlen($value) > 0) { |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); |
||||
|
$value = ""; |
||||
|
} |
||||
|
|
||||
|
$tmp = array_pop($stack); |
||||
|
$tmp->setValue(""); |
||||
|
$tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP); |
||||
|
$tokens1[] = $tmp; |
||||
|
|
||||
|
++$index; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// token accumulation |
||||
|
$value .= $this->_formula{$index}; |
||||
|
++$index; |
||||
|
} |
||||
|
|
||||
|
// dump remaining accumulation |
||||
|
if (strlen($value) > 0) { |
||||
|
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); |
||||
|
} |
||||
|
|
||||
|
// move tokenList to new set, excluding unnecessary white-space tokens and converting necessary ones to intersections |
||||
|
$tokenCount = count($tokens1); |
||||
|
for ($i = 0; $i < $tokenCount; ++$i) { |
||||
|
$token = $tokens1[$i]; |
||||
|
if (isset($tokens1[$i - 1])) { |
||||
|
$previousToken = $tokens1[$i - 1]; |
||||
|
} else { |
||||
|
$previousToken = null; |
||||
|
} |
||||
|
if (isset($tokens1[$i + 1])) { |
||||
|
$nextToken = $tokens1[$i + 1]; |
||||
|
} else { |
||||
|
$nextToken = null; |
||||
|
} |
||||
|
|
||||
|
if (is_null($token)) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if ($token->getTokenType() != PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_WHITESPACE) { |
||||
|
$tokens2[] = $token; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if (is_null($previousToken)) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if (! ( |
||||
|
(($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || |
||||
|
(($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || |
||||
|
($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND) |
||||
|
) ) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if (is_null($nextToken)) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if (! ( |
||||
|
(($nextToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && ($nextToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START)) || |
||||
|
(($nextToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && ($nextToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START)) || |
||||
|
($nextToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND) |
||||
|
) ) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
$tokens2[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_INTERSECTION); |
||||
|
} |
||||
|
|
||||
|
// move tokens to final list, switching infix "-" operators to prefix when appropriate, switching infix "+" operators |
||||
|
// to noop when appropriate, identifying operand and infix-operator subtypes, and pulling "@" from function names |
||||
|
$this->_tokens = array(); |
||||
|
|
||||
|
$tokenCount = count($tokens2); |
||||
|
for ($i = 0; $i < $tokenCount; ++$i) { |
||||
|
$token = $tokens2[$i]; |
||||
|
if (isset($tokens2[$i - 1])) { |
||||
|
$previousToken = $tokens2[$i - 1]; |
||||
|
} else { |
||||
|
$previousToken = null; |
||||
|
} |
||||
|
if (isset($tokens2[$i + 1])) { |
||||
|
$nextToken = $tokens2[$i + 1]; |
||||
|
} else { |
||||
|
$nextToken = null; |
||||
|
} |
||||
|
|
||||
|
if (is_null($token)) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $token->getValue() == "-") { |
||||
|
if ($i == 0) { |
||||
|
$token->setTokenType(PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPREFIX); |
||||
|
} else if ( |
||||
|
(($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || |
||||
|
(($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || |
||||
|
($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX) || |
||||
|
($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND) |
||||
|
) { |
||||
|
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH); |
||||
|
} else { |
||||
|
$token->setTokenType(PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPREFIX); |
||||
|
} |
||||
|
|
||||
|
$this->_tokens[] = $token; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $token->getValue() == "+") { |
||||
|
if ($i == 0) { |
||||
|
continue; |
||||
|
} else if ( |
||||
|
(($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || |
||||
|
(($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || |
||||
|
($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX) || |
||||
|
($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND) |
||||
|
) { |
||||
|
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH); |
||||
|
} else { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
$this->_tokens[] = $token; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $token->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) { |
||||
|
if (strpos("<>=", substr($token->getValue(), 0, 1)) !== false) { |
||||
|
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL); |
||||
|
} else if ($token->getValue() == "&") { |
||||
|
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_CONCATENATION); |
||||
|
} else { |
||||
|
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH); |
||||
|
} |
||||
|
|
||||
|
$this->_tokens[] = $token; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND && $token->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) { |
||||
|
if (!is_numeric($token->getValue())) { |
||||
|
if (strtoupper($token->getValue()) == "TRUE" || strtoupper($token->getValue() == "FALSE")) { |
||||
|
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL); |
||||
|
} else { |
||||
|
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_RANGE); |
||||
|
} |
||||
|
} else { |
||||
|
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NUMBER); |
||||
|
} |
||||
|
|
||||
|
$this->_tokens[] = $token; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) { |
||||
|
if (strlen($token->getValue() > 0)) { |
||||
|
if (substr($token->getValue(), 0, 1) == "@") { |
||||
|
$token->setValue(substr($token->getValue(), 1)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$this->_tokens[] = $token; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,176 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/* |
||||
|
PARTLY BASED ON: |
||||
|
Copyright (c) 2007 E. W. Bachtal, Inc. |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
||||
|
and associated documentation files (the "Software"), to deal in the Software without restriction, |
||||
|
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
|
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, |
||||
|
subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial |
||||
|
portions of the Software. |
||||
|
|
||||
|
The software is provided "as is", without warranty of any kind, express or implied, including but not |
||||
|
limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In |
||||
|
no event shall the authors or copyright holders be liable for any claim, damages or other liability, |
||||
|
whether in an action of contract, tort or otherwise, arising from, out of or in connection with the |
||||
|
software or the use or other dealings in the software. |
||||
|
|
||||
|
http://ewbi.blogs.com/develops/2007/03/excel_formula_p.html |
||||
|
http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Calculation_FormulaToken |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Calculation_FormulaToken { |
||||
|
/* Token types */ |
||||
|
const TOKEN_TYPE_NOOP = 'Noop'; |
||||
|
const TOKEN_TYPE_OPERAND = 'Operand'; |
||||
|
const TOKEN_TYPE_FUNCTION = 'Function'; |
||||
|
const TOKEN_TYPE_SUBEXPRESSION = 'Subexpression'; |
||||
|
const TOKEN_TYPE_ARGUMENT = 'Argument'; |
||||
|
const TOKEN_TYPE_OPERATORPREFIX = 'OperatorPrefix'; |
||||
|
const TOKEN_TYPE_OPERATORINFIX = 'OperatorInfix'; |
||||
|
const TOKEN_TYPE_OPERATORPOSTFIX = 'OperatorPostfix'; |
||||
|
const TOKEN_TYPE_WHITESPACE = 'Whitespace'; |
||||
|
const TOKEN_TYPE_UNKNOWN = 'Unknown'; |
||||
|
|
||||
|
/* Token subtypes */ |
||||
|
const TOKEN_SUBTYPE_NOTHING = 'Nothing'; |
||||
|
const TOKEN_SUBTYPE_START = 'Start'; |
||||
|
const TOKEN_SUBTYPE_STOP = 'Stop'; |
||||
|
const TOKEN_SUBTYPE_TEXT = 'Text'; |
||||
|
const TOKEN_SUBTYPE_NUMBER = 'Number'; |
||||
|
const TOKEN_SUBTYPE_LOGICAL = 'Logical'; |
||||
|
const TOKEN_SUBTYPE_ERROR = 'Error'; |
||||
|
const TOKEN_SUBTYPE_RANGE = 'Range'; |
||||
|
const TOKEN_SUBTYPE_MATH = 'Math'; |
||||
|
const TOKEN_SUBTYPE_CONCATENATION = 'Concatenation'; |
||||
|
const TOKEN_SUBTYPE_INTERSECTION = 'Intersection'; |
||||
|
const TOKEN_SUBTYPE_UNION = 'Union'; |
||||
|
|
||||
|
/** |
||||
|
* Value |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_value; |
||||
|
|
||||
|
/** |
||||
|
* Token Type (represented by TOKEN_TYPE_*) |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_tokenType; |
||||
|
|
||||
|
/** |
||||
|
* Token SubType (represented by TOKEN_SUBTYPE_*) |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_tokenSubType; |
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Calculation_FormulaToken |
||||
|
* |
||||
|
* @param string $pValue |
||||
|
* @param string $pTokenType Token type (represented by TOKEN_TYPE_*) |
||||
|
* @param string $pTokenSubType Token Subtype (represented by TOKEN_SUBTYPE_*) |
||||
|
*/ |
||||
|
public function __construct($pValue, $pTokenType = PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN, $pTokenSubType = PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) |
||||
|
{ |
||||
|
// Initialise values |
||||
|
$this->_value = $pValue; |
||||
|
$this->_tokenType = $pTokenType; |
||||
|
$this->_tokenSubType = $pTokenSubType; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Value |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getValue() { |
||||
|
return $this->_value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Value |
||||
|
* |
||||
|
* @param string $value |
||||
|
*/ |
||||
|
public function setValue($value) { |
||||
|
$this->_value = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Token Type (represented by TOKEN_TYPE_*) |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getTokenType() { |
||||
|
return $this->_tokenType; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Token Type |
||||
|
* |
||||
|
* @param string $value |
||||
|
*/ |
||||
|
public function setTokenType($value = PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN) { |
||||
|
$this->_tokenType = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Token SubType (represented by TOKEN_SUBTYPE_*) |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getTokenSubType() { |
||||
|
return $this->_tokenSubType; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Token SubType |
||||
|
* |
||||
|
* @param string $value |
||||
|
*/ |
||||
|
public function setTokenSubType($value = PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) { |
||||
|
$this->_tokenSubType = $value; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,149 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Calculation_Function |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Calculation_Function { |
||||
|
/* Function categories */ |
||||
|
const CATEGORY_CUBE = 'Cube'; |
||||
|
const CATEGORY_DATABASE = 'Database'; |
||||
|
const CATEGORY_DATE_AND_TIME = 'Date and Time'; |
||||
|
const CATEGORY_ENGINEERING = 'Engineering'; |
||||
|
const CATEGORY_FINANCIAL = 'Financial'; |
||||
|
const CATEGORY_INFORMATION = 'Information'; |
||||
|
const CATEGORY_LOGICAL = 'Logical'; |
||||
|
const CATEGORY_LOOKUP_AND_REFERENCE = 'Lookup and Reference'; |
||||
|
const CATEGORY_MATH_AND_TRIG = 'Math and Trig'; |
||||
|
const CATEGORY_STATISTICAL = 'Statistical'; |
||||
|
const CATEGORY_TEXT_AND_DATA = 'Text and Data'; |
||||
|
|
||||
|
/** |
||||
|
* Category (represented by CATEGORY_*) |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_category; |
||||
|
|
||||
|
/** |
||||
|
* Excel name |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_excelName; |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel name |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_phpExcelName; |
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Calculation_Function |
||||
|
* |
||||
|
* @param string $pCategory Category (represented by CATEGORY_*) |
||||
|
* @param string $pExcelName Excel function name |
||||
|
* @param string $pPHPExcelName PHPExcel function mapping |
||||
|
* @throws PHPExcel_Calculation_Exception |
||||
|
*/ |
||||
|
public function __construct($pCategory = NULL, $pExcelName = NULL, $pPHPExcelName = NULL) |
||||
|
{ |
||||
|
if (($pCategory !== NULL) && ($pExcelName !== NULL) && ($pPHPExcelName !== NULL)) { |
||||
|
// Initialise values |
||||
|
$this->_category = $pCategory; |
||||
|
$this->_excelName = $pExcelName; |
||||
|
$this->_phpExcelName = $pPHPExcelName; |
||||
|
} else { |
||||
|
throw new PHPExcel_Calculation_Exception("Invalid parameters passed."); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Category (represented by CATEGORY_*) |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getCategory() { |
||||
|
return $this->_category; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Category (represented by CATEGORY_*) |
||||
|
* |
||||
|
* @param string $value |
||||
|
* @throws PHPExcel_Calculation_Exception |
||||
|
*/ |
||||
|
public function setCategory($value = null) { |
||||
|
if (!is_null($value)) { |
||||
|
$this->_category = $value; |
||||
|
} else { |
||||
|
throw new PHPExcel_Calculation_Exception("Invalid parameter passed."); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Excel name |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getExcelName() { |
||||
|
return $this->_excelName; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Excel name |
||||
|
* |
||||
|
* @param string $value |
||||
|
*/ |
||||
|
public function setExcelName($value) { |
||||
|
$this->_excelName = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get PHPExcel name |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getPHPExcelName() { |
||||
|
return $this->_phpExcelName; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set PHPExcel name |
||||
|
* |
||||
|
* @param string $value |
||||
|
*/ |
||||
|
public function setPHPExcelName($value) { |
||||
|
$this->_phpExcelName = $value; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,814 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** PHPExcel root directory */ |
||||
|
if (!defined('PHPEXCEL_ROOT')) { |
||||
|
/** |
||||
|
* @ignore |
||||
|
*/ |
||||
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
||||
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** MAX_VALUE */ |
||||
|
define('MAX_VALUE', 1.2e308); |
||||
|
|
||||
|
/** 2 / PI */ |
||||
|
define('M_2DIVPI', 0.63661977236758134307553505349006); |
||||
|
|
||||
|
/** MAX_ITERATIONS */ |
||||
|
define('MAX_ITERATIONS', 256); |
||||
|
|
||||
|
/** PRECISION */ |
||||
|
define('PRECISION', 8.88E-016); |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Calculation_Functions |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Calculation_Functions { |
||||
|
|
||||
|
/** constants */ |
||||
|
const COMPATIBILITY_EXCEL = 'Excel'; |
||||
|
const COMPATIBILITY_GNUMERIC = 'Gnumeric'; |
||||
|
const COMPATIBILITY_OPENOFFICE = 'OpenOfficeCalc'; |
||||
|
|
||||
|
const RETURNDATE_PHP_NUMERIC = 'P'; |
||||
|
const RETURNDATE_PHP_OBJECT = 'O'; |
||||
|
const RETURNDATE_EXCEL = 'E'; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Compatibility mode to use for error checking and responses |
||||
|
* |
||||
|
* @access private |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected static $compatibilityMode = self::COMPATIBILITY_EXCEL; |
||||
|
|
||||
|
/** |
||||
|
* Data Type to use when returning date values |
||||
|
* |
||||
|
* @access private |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected static $ReturnDateType = self::RETURNDATE_EXCEL; |
||||
|
|
||||
|
/** |
||||
|
* List of error codes |
||||
|
* |
||||
|
* @access private |
||||
|
* @var array |
||||
|
*/ |
||||
|
protected static $_errorCodes = array( 'null' => '#NULL!', |
||||
|
'divisionbyzero' => '#DIV/0!', |
||||
|
'value' => '#VALUE!', |
||||
|
'reference' => '#REF!', |
||||
|
'name' => '#NAME?', |
||||
|
'num' => '#NUM!', |
||||
|
'na' => '#N/A', |
||||
|
'gettingdata' => '#GETTING_DATA' |
||||
|
); |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Set the Compatibility Mode |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Function Configuration |
||||
|
* @param string $compatibilityMode Compatibility Mode |
||||
|
* Permitted values are: |
||||
|
* PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL 'Excel' |
||||
|
* PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC 'Gnumeric' |
||||
|
* PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc' |
||||
|
* @return boolean (Success or Failure) |
||||
|
*/ |
||||
|
public static function setCompatibilityMode($compatibilityMode) { |
||||
|
if (($compatibilityMode == self::COMPATIBILITY_EXCEL) || |
||||
|
($compatibilityMode == self::COMPATIBILITY_GNUMERIC) || |
||||
|
($compatibilityMode == self::COMPATIBILITY_OPENOFFICE)) { |
||||
|
self::$compatibilityMode = $compatibilityMode; |
||||
|
return True; |
||||
|
} |
||||
|
return False; |
||||
|
} // function setCompatibilityMode() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Return the current Compatibility Mode |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Function Configuration |
||||
|
* @return string Compatibility Mode |
||||
|
* Possible Return values are: |
||||
|
* PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL 'Excel' |
||||
|
* PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC 'Gnumeric' |
||||
|
* PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc' |
||||
|
*/ |
||||
|
public static function getCompatibilityMode() { |
||||
|
return self::$compatibilityMode; |
||||
|
} // function getCompatibilityMode() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Set the Return Date Format used by functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Function Configuration |
||||
|
* @param string $returnDateType Return Date Format |
||||
|
* Permitted values are: |
||||
|
* PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC 'P' |
||||
|
* PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT 'O' |
||||
|
* PHPExcel_Calculation_Functions::RETURNDATE_EXCEL 'E' |
||||
|
* @return boolean Success or failure |
||||
|
*/ |
||||
|
public static function setReturnDateType($returnDateType) { |
||||
|
if (($returnDateType == self::RETURNDATE_PHP_NUMERIC) || |
||||
|
($returnDateType == self::RETURNDATE_PHP_OBJECT) || |
||||
|
($returnDateType == self::RETURNDATE_EXCEL)) { |
||||
|
self::$ReturnDateType = $returnDateType; |
||||
|
return True; |
||||
|
} |
||||
|
return False; |
||||
|
} // function setReturnDateType() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Return the current Return Date Format for functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Function Configuration |
||||
|
* @return string Return Date Format |
||||
|
* Possible Return values are: |
||||
|
* PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC 'P' |
||||
|
* PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT 'O' |
||||
|
* PHPExcel_Calculation_Functions::RETURNDATE_EXCEL 'E' |
||||
|
*/ |
||||
|
public static function getReturnDateType() { |
||||
|
return self::$ReturnDateType; |
||||
|
} // function getReturnDateType() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DUMMY |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Error Returns |
||||
|
* @return string #Not Yet Implemented |
||||
|
*/ |
||||
|
public static function DUMMY() { |
||||
|
return '#Not Yet Implemented'; |
||||
|
} // function DUMMY() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DIV0 |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Error Returns |
||||
|
* @return string #Not Yet Implemented |
||||
|
*/ |
||||
|
public static function DIV0() { |
||||
|
return self::$_errorCodes['divisionbyzero']; |
||||
|
} // function DIV0() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* NA |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =NA() |
||||
|
* |
||||
|
* Returns the error value #N/A |
||||
|
* #N/A is the error value that means "no value is available." |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Logical Functions |
||||
|
* @return string #N/A! |
||||
|
*/ |
||||
|
public static function NA() { |
||||
|
return self::$_errorCodes['na']; |
||||
|
} // function NA() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* NaN |
||||
|
* |
||||
|
* Returns the error value #NUM! |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Error Returns |
||||
|
* @return string #NUM! |
||||
|
*/ |
||||
|
public static function NaN() { |
||||
|
return self::$_errorCodes['num']; |
||||
|
} // function NaN() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* NAME |
||||
|
* |
||||
|
* Returns the error value #NAME? |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Error Returns |
||||
|
* @return string #NAME? |
||||
|
*/ |
||||
|
public static function NAME() { |
||||
|
return self::$_errorCodes['name']; |
||||
|
} // function NAME() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* REF |
||||
|
* |
||||
|
* Returns the error value #REF! |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Error Returns |
||||
|
* @return string #REF! |
||||
|
*/ |
||||
|
public static function REF() { |
||||
|
return self::$_errorCodes['reference']; |
||||
|
} // function REF() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* NULL |
||||
|
* |
||||
|
* Returns the error value #NULL! |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Error Returns |
||||
|
* @return string #REF! |
||||
|
*/ |
||||
|
public static function NULL() { |
||||
|
return self::$_errorCodes['null']; |
||||
|
} // function NULL() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* VALUE |
||||
|
* |
||||
|
* Returns the error value #VALUE! |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Error Returns |
||||
|
* @return string #VALUE! |
||||
|
*/ |
||||
|
public static function VALUE() { |
||||
|
return self::$_errorCodes['value']; |
||||
|
} // function VALUE() |
||||
|
|
||||
|
|
||||
|
public static function isMatrixValue($idx) { |
||||
|
return ((substr_count($idx,'.') <= 1) || (preg_match('/\.[A-Z]/',$idx) > 0)); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public static function isValue($idx) { |
||||
|
return (substr_count($idx,'.') == 0); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public static function isCellValue($idx) { |
||||
|
return (substr_count($idx,'.') > 1); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public static function _ifCondition($condition) { |
||||
|
$condition = PHPExcel_Calculation_Functions::flattenSingleValue($condition); |
||||
|
if (!isset($condition{0})) |
||||
|
$condition = '=""'; |
||||
|
if (!in_array($condition{0},array('>', '<', '='))) { |
||||
|
if (!is_numeric($condition)) { $condition = PHPExcel_Calculation::_wrapResult(strtoupper($condition)); } |
||||
|
return '='.$condition; |
||||
|
} else { |
||||
|
preg_match('/([<>=]+)(.*)/',$condition,$matches); |
||||
|
list(,$operator,$operand) = $matches; |
||||
|
if (!is_numeric($operand)) { $operand = PHPExcel_Calculation::_wrapResult(strtoupper($operand)); } |
||||
|
return $operator.$operand; |
||||
|
} |
||||
|
} // function _ifCondition() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* ERROR_TYPE |
||||
|
* |
||||
|
* @param mixed $value Value to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function ERROR_TYPE($value = '') { |
||||
|
$value = self::flattenSingleValue($value); |
||||
|
|
||||
|
$i = 1; |
||||
|
foreach(self::$_errorCodes as $errorCode) { |
||||
|
if ($value === $errorCode) { |
||||
|
return $i; |
||||
|
} |
||||
|
++$i; |
||||
|
} |
||||
|
return self::NA(); |
||||
|
} // function ERROR_TYPE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* IS_BLANK |
||||
|
* |
||||
|
* @param mixed $value Value to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function IS_BLANK($value = NULL) { |
||||
|
if (!is_null($value)) { |
||||
|
$value = self::flattenSingleValue($value); |
||||
|
} |
||||
|
|
||||
|
return is_null($value); |
||||
|
} // function IS_BLANK() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* IS_ERR |
||||
|
* |
||||
|
* @param mixed $value Value to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function IS_ERR($value = '') { |
||||
|
$value = self::flattenSingleValue($value); |
||||
|
|
||||
|
return self::IS_ERROR($value) && (!self::IS_NA($value)); |
||||
|
} // function IS_ERR() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* IS_ERROR |
||||
|
* |
||||
|
* @param mixed $value Value to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function IS_ERROR($value = '') { |
||||
|
$value = self::flattenSingleValue($value); |
||||
|
|
||||
|
if (!is_string($value)) |
||||
|
return false; |
||||
|
return in_array($value, array_values(self::$_errorCodes)); |
||||
|
} // function IS_ERROR() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* IS_NA |
||||
|
* |
||||
|
* @param mixed $value Value to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function IS_NA($value = '') { |
||||
|
$value = self::flattenSingleValue($value); |
||||
|
|
||||
|
return ($value === self::NA()); |
||||
|
} // function IS_NA() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* IS_EVEN |
||||
|
* |
||||
|
* @param mixed $value Value to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function IS_EVEN($value = NULL) { |
||||
|
$value = self::flattenSingleValue($value); |
||||
|
|
||||
|
if ($value === NULL) |
||||
|
return self::NAME(); |
||||
|
if ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) |
||||
|
return self::VALUE(); |
||||
|
return ($value % 2 == 0); |
||||
|
} // function IS_EVEN() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* IS_ODD |
||||
|
* |
||||
|
* @param mixed $value Value to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function IS_ODD($value = NULL) { |
||||
|
$value = self::flattenSingleValue($value); |
||||
|
|
||||
|
if ($value === NULL) |
||||
|
return self::NAME(); |
||||
|
if ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) |
||||
|
return self::VALUE(); |
||||
|
return (abs($value) % 2 == 1); |
||||
|
} // function IS_ODD() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* IS_NUMBER |
||||
|
* |
||||
|
* @param mixed $value Value to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function IS_NUMBER($value = NULL) { |
||||
|
$value = self::flattenSingleValue($value); |
||||
|
|
||||
|
if (is_string($value)) { |
||||
|
return False; |
||||
|
} |
||||
|
return is_numeric($value); |
||||
|
} // function IS_NUMBER() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* IS_LOGICAL |
||||
|
* |
||||
|
* @param mixed $value Value to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function IS_LOGICAL($value = NULL) { |
||||
|
$value = self::flattenSingleValue($value); |
||||
|
|
||||
|
return is_bool($value); |
||||
|
} // function IS_LOGICAL() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* IS_TEXT |
||||
|
* |
||||
|
* @param mixed $value Value to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function IS_TEXT($value = NULL) { |
||||
|
$value = self::flattenSingleValue($value); |
||||
|
|
||||
|
return (is_string($value) && !self::IS_ERROR($value)); |
||||
|
} // function IS_TEXT() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* IS_NONTEXT |
||||
|
* |
||||
|
* @param mixed $value Value to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function IS_NONTEXT($value = NULL) { |
||||
|
return !self::IS_TEXT($value); |
||||
|
} // function IS_NONTEXT() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* VERSION |
||||
|
* |
||||
|
* @return string Version information |
||||
|
*/ |
||||
|
public static function VERSION() { |
||||
|
return 'PHPExcel 1.7.9, 2013-06-02'; |
||||
|
} // function VERSION() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* N |
||||
|
* |
||||
|
* Returns a value converted to a number |
||||
|
* |
||||
|
* @param value The value you want converted |
||||
|
* @return number N converts values listed in the following table |
||||
|
* If value is or refers to N returns |
||||
|
* A number That number |
||||
|
* A date The serial number of that date |
||||
|
* TRUE 1 |
||||
|
* FALSE 0 |
||||
|
* An error value The error value |
||||
|
* Anything else 0 |
||||
|
*/ |
||||
|
public static function N($value = NULL) { |
||||
|
while (is_array($value)) { |
||||
|
$value = array_shift($value); |
||||
|
} |
||||
|
|
||||
|
switch (gettype($value)) { |
||||
|
case 'double' : |
||||
|
case 'float' : |
||||
|
case 'integer' : |
||||
|
return $value; |
||||
|
break; |
||||
|
case 'boolean' : |
||||
|
return (integer) $value; |
||||
|
break; |
||||
|
case 'string' : |
||||
|
// Errors |
||||
|
if ((strlen($value) > 0) && ($value{0} == '#')) { |
||||
|
return $value; |
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
return 0; |
||||
|
} // function N() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* TYPE |
||||
|
* |
||||
|
* Returns a number that identifies the type of a value |
||||
|
* |
||||
|
* @param value The value you want tested |
||||
|
* @return number N converts values listed in the following table |
||||
|
* If value is or refers to N returns |
||||
|
* A number 1 |
||||
|
* Text 2 |
||||
|
* Logical Value 4 |
||||
|
* An error value 16 |
||||
|
* Array or Matrix 64 |
||||
|
*/ |
||||
|
public static function TYPE($value = NULL) { |
||||
|
$value = self::flattenArrayIndexed($value); |
||||
|
if (is_array($value) && (count($value) > 1)) { |
||||
|
$a = array_keys($value); |
||||
|
$a = array_pop($a); |
||||
|
// Range of cells is an error |
||||
|
if (self::isCellValue($a)) { |
||||
|
return 16; |
||||
|
// Test for Matrix |
||||
|
} elseif (self::isMatrixValue($a)) { |
||||
|
return 64; |
||||
|
} |
||||
|
} elseif(empty($value)) { |
||||
|
// Empty Cell |
||||
|
return 1; |
||||
|
} |
||||
|
$value = self::flattenSingleValue($value); |
||||
|
|
||||
|
if (($value === NULL) || (is_float($value)) || (is_int($value))) { |
||||
|
return 1; |
||||
|
} elseif(is_bool($value)) { |
||||
|
return 4; |
||||
|
} elseif(is_array($value)) { |
||||
|
return 64; |
||||
|
} elseif(is_string($value)) { |
||||
|
// Errors |
||||
|
if ((strlen($value) > 0) && ($value{0} == '#')) { |
||||
|
return 16; |
||||
|
} |
||||
|
return 2; |
||||
|
} |
||||
|
return 0; |
||||
|
} // function TYPE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Convert a multi-dimensional array to a simple 1-dimensional array |
||||
|
* |
||||
|
* @param array $array Array to be flattened |
||||
|
* @return array Flattened array |
||||
|
*/ |
||||
|
public static function flattenArray($array) { |
||||
|
if (!is_array($array)) { |
||||
|
return (array) $array; |
||||
|
} |
||||
|
|
||||
|
$arrayValues = array(); |
||||
|
foreach ($array as $value) { |
||||
|
if (is_array($value)) { |
||||
|
foreach ($value as $val) { |
||||
|
if (is_array($val)) { |
||||
|
foreach ($val as $v) { |
||||
|
$arrayValues[] = $v; |
||||
|
} |
||||
|
} else { |
||||
|
$arrayValues[] = $val; |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
$arrayValues[] = $value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $arrayValues; |
||||
|
} // function flattenArray() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Convert a multi-dimensional array to a simple 1-dimensional array, but retain an element of indexing |
||||
|
* |
||||
|
* @param array $array Array to be flattened |
||||
|
* @return array Flattened array |
||||
|
*/ |
||||
|
public static function flattenArrayIndexed($array) { |
||||
|
if (!is_array($array)) { |
||||
|
return (array) $array; |
||||
|
} |
||||
|
|
||||
|
$arrayValues = array(); |
||||
|
foreach ($array as $k1 => $value) { |
||||
|
if (is_array($value)) { |
||||
|
foreach ($value as $k2 => $val) { |
||||
|
if (is_array($val)) { |
||||
|
foreach ($val as $k3 => $v) { |
||||
|
$arrayValues[$k1.'.'.$k2.'.'.$k3] = $v; |
||||
|
} |
||||
|
} else { |
||||
|
$arrayValues[$k1.'.'.$k2] = $val; |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
$arrayValues[$k1] = $value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $arrayValues; |
||||
|
} // function flattenArrayIndexed() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Convert an array to a single scalar value by extracting the first element |
||||
|
* |
||||
|
* @param mixed $value Array or scalar value |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public static function flattenSingleValue($value = '') { |
||||
|
while (is_array($value)) { |
||||
|
$value = array_pop($value); |
||||
|
} |
||||
|
|
||||
|
return $value; |
||||
|
} // function flattenSingleValue() |
||||
|
|
||||
|
} // class PHPExcel_Calculation_Functions |
||||
|
|
||||
|
|
||||
|
// |
||||
|
// There are a few mathematical functions that aren't available on all versions of PHP for all platforms |
||||
|
// These functions aren't available in Windows implementations of PHP prior to version 5.3.0 |
||||
|
// So we test if they do exist for this version of PHP/operating platform; and if not we create them |
||||
|
// |
||||
|
if (!function_exists('acosh')) { |
||||
|
function acosh($x) { |
||||
|
return 2 * log(sqrt(($x + 1) / 2) + sqrt(($x - 1) / 2)); |
||||
|
} // function acosh() |
||||
|
} |
||||
|
|
||||
|
if (!function_exists('asinh')) { |
||||
|
function asinh($x) { |
||||
|
return log($x + sqrt(1 + $x * $x)); |
||||
|
} // function asinh() |
||||
|
} |
||||
|
|
||||
|
if (!function_exists('atanh')) { |
||||
|
function atanh($x) { |
||||
|
return (log(1 + $x) - log(1 - $x)) / 2; |
||||
|
} // function atanh() |
||||
|
} |
||||
|
|
||||
|
if (!function_exists('money_format')) { |
||||
|
function money_format($format, $number) { |
||||
|
$regex = array( '/%((?:[\^!\-]|\+|\(|\=.)*)([0-9]+)?(?:#([0-9]+))?', |
||||
|
'(?:\.([0-9]+))?([in%])/' |
||||
|
); |
||||
|
$regex = implode('', $regex); |
||||
|
if (setlocale(LC_MONETARY, null) == '') { |
||||
|
setlocale(LC_MONETARY, ''); |
||||
|
} |
||||
|
$locale = localeconv(); |
||||
|
$number = floatval($number); |
||||
|
if (!preg_match($regex, $format, $fmatch)) { |
||||
|
trigger_error("No format specified or invalid format", E_USER_WARNING); |
||||
|
return $number; |
||||
|
} |
||||
|
$flags = array( 'fillchar' => preg_match('/\=(.)/', $fmatch[1], $match) ? $match[1] : ' ', |
||||
|
'nogroup' => preg_match('/\^/', $fmatch[1]) > 0, |
||||
|
'usesignal' => preg_match('/\+|\(/', $fmatch[1], $match) ? $match[0] : '+', |
||||
|
'nosimbol' => preg_match('/\!/', $fmatch[1]) > 0, |
||||
|
'isleft' => preg_match('/\-/', $fmatch[1]) > 0 |
||||
|
); |
||||
|
$width = trim($fmatch[2]) ? (int)$fmatch[2] : 0; |
||||
|
$left = trim($fmatch[3]) ? (int)$fmatch[3] : 0; |
||||
|
$right = trim($fmatch[4]) ? (int)$fmatch[4] : $locale['int_frac_digits']; |
||||
|
$conversion = $fmatch[5]; |
||||
|
$positive = true; |
||||
|
if ($number < 0) { |
||||
|
$positive = false; |
||||
|
$number *= -1; |
||||
|
} |
||||
|
$letter = $positive ? 'p' : 'n'; |
||||
|
$prefix = $suffix = $cprefix = $csuffix = $signal = ''; |
||||
|
if (!$positive) { |
||||
|
$signal = $locale['negative_sign']; |
||||
|
switch (true) { |
||||
|
case $locale['n_sign_posn'] == 0 || $flags['usesignal'] == '(': |
||||
|
$prefix = '('; |
||||
|
$suffix = ')'; |
||||
|
break; |
||||
|
case $locale['n_sign_posn'] == 1: |
||||
|
$prefix = $signal; |
||||
|
break; |
||||
|
case $locale['n_sign_posn'] == 2: |
||||
|
$suffix = $signal; |
||||
|
break; |
||||
|
case $locale['n_sign_posn'] == 3: |
||||
|
$cprefix = $signal; |
||||
|
break; |
||||
|
case $locale['n_sign_posn'] == 4: |
||||
|
$csuffix = $signal; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
if (!$flags['nosimbol']) { |
||||
|
$currency = $cprefix; |
||||
|
$currency .= ($conversion == 'i' ? $locale['int_curr_symbol'] : $locale['currency_symbol']); |
||||
|
$currency .= $csuffix; |
||||
|
$currency = iconv('ISO-8859-1','UTF-8',$currency); |
||||
|
} else { |
||||
|
$currency = ''; |
||||
|
} |
||||
|
$space = $locale["{$letter}_sep_by_space"] ? ' ' : ''; |
||||
|
|
||||
|
if (!isset($locale['mon_decimal_point']) || empty($locale['mon_decimal_point'])) { |
||||
|
$locale['mon_decimal_point'] = (!isset($locale['decimal_point']) || empty($locale['decimal_point'])) ? |
||||
|
$locale['decimal_point'] : |
||||
|
'.'; |
||||
|
} |
||||
|
|
||||
|
$number = number_format($number, $right, $locale['mon_decimal_point'], $flags['nogroup'] ? '' : $locale['mon_thousands_sep'] ); |
||||
|
$number = explode($locale['mon_decimal_point'], $number); |
||||
|
|
||||
|
$n = strlen($prefix) + strlen($currency); |
||||
|
if ($left > 0 && $left > $n) { |
||||
|
if ($flags['isleft']) { |
||||
|
$number[0] .= str_repeat($flags['fillchar'], $left - $n); |
||||
|
} else { |
||||
|
$number[0] = str_repeat($flags['fillchar'], $left - $n) . $number[0]; |
||||
|
} |
||||
|
} |
||||
|
$number = implode($locale['mon_decimal_point'], $number); |
||||
|
if ($locale["{$letter}_cs_precedes"]) { |
||||
|
$number = $prefix . $currency . $space . $number . $suffix; |
||||
|
} else { |
||||
|
$number = $prefix . $number . $space . $currency . $suffix; |
||||
|
} |
||||
|
if ($width > 0) { |
||||
|
$number = str_pad($number, $width, $flags['fillchar'], $flags['isleft'] ? STR_PAD_RIGHT : STR_PAD_LEFT); |
||||
|
} |
||||
|
$format = str_replace($fmatch[0], $number, $format); |
||||
|
return $format; |
||||
|
} // function money_format() |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// |
||||
|
// Strangely, PHP doesn't have a mb_str_replace multibyte function |
||||
|
// As we'll only ever use this function with UTF-8 characters, we can simply "hard-code" the character set |
||||
|
// |
||||
|
if ((!function_exists('mb_str_replace')) && |
||||
|
(function_exists('mb_substr')) && (function_exists('mb_strlen')) && (function_exists('mb_strpos'))) { |
||||
|
function mb_str_replace($search, $replace, $subject) { |
||||
|
if(is_array($subject)) { |
||||
|
$ret = array(); |
||||
|
foreach($subject as $key => $val) { |
||||
|
$ret[$key] = mb_str_replace($search, $replace, $val); |
||||
|
} |
||||
|
return $ret; |
||||
|
} |
||||
|
|
||||
|
foreach((array) $search as $key => $s) { |
||||
|
if($s == '') { |
||||
|
continue; |
||||
|
} |
||||
|
$r = !is_array($replace) ? $replace : (array_key_exists($key, $replace) ? $replace[$key] : ''); |
||||
|
$pos = mb_strpos($subject, $s, 0, 'UTF-8'); |
||||
|
while($pos !== false) { |
||||
|
$subject = mb_substr($subject, 0, $pos, 'UTF-8') . $r . mb_substr($subject, $pos + mb_strlen($s, 'UTF-8'), 65535, 'UTF-8'); |
||||
|
$pos = mb_strpos($subject, $s, $pos + mb_strlen($r, 'UTF-8'), 'UTF-8'); |
||||
|
} |
||||
|
} |
||||
|
return $subject; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,288 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** PHPExcel root directory */ |
||||
|
if (!defined('PHPEXCEL_ROOT')) { |
||||
|
/** |
||||
|
* @ignore |
||||
|
*/ |
||||
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
||||
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Calculation_Logical |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Calculation_Logical { |
||||
|
|
||||
|
/** |
||||
|
* TRUE |
||||
|
* |
||||
|
* Returns the boolean TRUE. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =TRUE() |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Logical Functions |
||||
|
* @return boolean True |
||||
|
*/ |
||||
|
public static function TRUE() { |
||||
|
return TRUE; |
||||
|
} // function TRUE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* FALSE |
||||
|
* |
||||
|
* Returns the boolean FALSE. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =FALSE() |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Logical Functions |
||||
|
* @return boolean False |
||||
|
*/ |
||||
|
public static function FALSE() { |
||||
|
return FALSE; |
||||
|
} // function FALSE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* LOGICAL_AND |
||||
|
* |
||||
|
* Returns boolean TRUE if all its arguments are TRUE; returns FALSE if one or more argument is FALSE. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =AND(logical1[,logical2[, ...]]) |
||||
|
* |
||||
|
* The arguments must evaluate to logical values such as TRUE or FALSE, or the arguments must be arrays |
||||
|
* or references that contain logical values. |
||||
|
* |
||||
|
* Boolean arguments are treated as True or False as appropriate |
||||
|
* Integer or floating point arguments are treated as True, except for 0 or 0.0 which are False |
||||
|
* If any argument value is a string, or a Null, the function returns a #VALUE! error, unless the string holds |
||||
|
* the value TRUE or FALSE, in which case it is evaluated as the corresponding boolean value |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Logical Functions |
||||
|
* @param mixed $arg,... Data values |
||||
|
* @return boolean The logical AND of the arguments. |
||||
|
*/ |
||||
|
public static function LOGICAL_AND() { |
||||
|
// Return value |
||||
|
$returnValue = TRUE; |
||||
|
|
||||
|
// Loop through the arguments |
||||
|
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); |
||||
|
$argCount = -1; |
||||
|
foreach ($aArgs as $argCount => $arg) { |
||||
|
// Is it a boolean value? |
||||
|
if (is_bool($arg)) { |
||||
|
$returnValue = $returnValue && $arg; |
||||
|
} elseif ((is_numeric($arg)) && (!is_string($arg))) { |
||||
|
$returnValue = $returnValue && ($arg != 0); |
||||
|
} elseif (is_string($arg)) { |
||||
|
$arg = strtoupper($arg); |
||||
|
if (($arg == 'TRUE') || ($arg == PHPExcel_Calculation::getTRUE())) { |
||||
|
$arg = TRUE; |
||||
|
} elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) { |
||||
|
$arg = FALSE; |
||||
|
} else { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
$returnValue = $returnValue && ($arg != 0); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
if ($argCount < 0) { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
return $returnValue; |
||||
|
} // function LOGICAL_AND() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* LOGICAL_OR |
||||
|
* |
||||
|
* Returns boolean TRUE if any argument is TRUE; returns FALSE if all arguments are FALSE. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =OR(logical1[,logical2[, ...]]) |
||||
|
* |
||||
|
* The arguments must evaluate to logical values such as TRUE or FALSE, or the arguments must be arrays |
||||
|
* or references that contain logical values. |
||||
|
* |
||||
|
* Boolean arguments are treated as True or False as appropriate |
||||
|
* Integer or floating point arguments are treated as True, except for 0 or 0.0 which are False |
||||
|
* If any argument value is a string, or a Null, the function returns a #VALUE! error, unless the string holds |
||||
|
* the value TRUE or FALSE, in which case it is evaluated as the corresponding boolean value |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Logical Functions |
||||
|
* @param mixed $arg,... Data values |
||||
|
* @return boolean The logical OR of the arguments. |
||||
|
*/ |
||||
|
public static function LOGICAL_OR() { |
||||
|
// Return value |
||||
|
$returnValue = FALSE; |
||||
|
|
||||
|
// Loop through the arguments |
||||
|
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); |
||||
|
$argCount = -1; |
||||
|
foreach ($aArgs as $argCount => $arg) { |
||||
|
// Is it a boolean value? |
||||
|
if (is_bool($arg)) { |
||||
|
$returnValue = $returnValue || $arg; |
||||
|
} elseif ((is_numeric($arg)) && (!is_string($arg))) { |
||||
|
$returnValue = $returnValue || ($arg != 0); |
||||
|
} elseif (is_string($arg)) { |
||||
|
$arg = strtoupper($arg); |
||||
|
if (($arg == 'TRUE') || ($arg == PHPExcel_Calculation::getTRUE())) { |
||||
|
$arg = TRUE; |
||||
|
} elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) { |
||||
|
$arg = FALSE; |
||||
|
} else { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
$returnValue = $returnValue || ($arg != 0); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
if ($argCount < 0) { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
return $returnValue; |
||||
|
} // function LOGICAL_OR() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* NOT |
||||
|
* |
||||
|
* Returns the boolean inverse of the argument. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =NOT(logical) |
||||
|
* |
||||
|
* The argument must evaluate to a logical value such as TRUE or FALSE |
||||
|
* |
||||
|
* Boolean arguments are treated as True or False as appropriate |
||||
|
* Integer or floating point arguments are treated as True, except for 0 or 0.0 which are False |
||||
|
* If any argument value is a string, or a Null, the function returns a #VALUE! error, unless the string holds |
||||
|
* the value TRUE or FALSE, in which case it is evaluated as the corresponding boolean value |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Logical Functions |
||||
|
* @param mixed $logical A value or expression that can be evaluated to TRUE or FALSE |
||||
|
* @return boolean The boolean inverse of the argument. |
||||
|
*/ |
||||
|
public static function NOT($logical=FALSE) { |
||||
|
$logical = PHPExcel_Calculation_Functions::flattenSingleValue($logical); |
||||
|
if (is_string($logical)) { |
||||
|
$logical = strtoupper($logical); |
||||
|
if (($logical == 'TRUE') || ($logical == PHPExcel_Calculation::getTRUE())) { |
||||
|
return FALSE; |
||||
|
} elseif (($logical == 'FALSE') || ($logical == PHPExcel_Calculation::getFALSE())) { |
||||
|
return TRUE; |
||||
|
} else { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return !$logical; |
||||
|
} // function NOT() |
||||
|
|
||||
|
/** |
||||
|
* STATEMENT_IF |
||||
|
* |
||||
|
* Returns one value if a condition you specify evaluates to TRUE and another value if it evaluates to FALSE. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =IF(condition[,returnIfTrue[,returnIfFalse]]) |
||||
|
* |
||||
|
* Condition is any value or expression that can be evaluated to TRUE or FALSE. |
||||
|
* For example, A10=100 is a logical expression; if the value in cell A10 is equal to 100, |
||||
|
* the expression evaluates to TRUE. Otherwise, the expression evaluates to FALSE. |
||||
|
* This argument can use any comparison calculation operator. |
||||
|
* ReturnIfTrue is the value that is returned if condition evaluates to TRUE. |
||||
|
* For example, if this argument is the text string "Within budget" and the condition argument evaluates to TRUE, |
||||
|
* then the IF function returns the text "Within budget" |
||||
|
* If condition is TRUE and ReturnIfTrue is blank, this argument returns 0 (zero). To display the word TRUE, use |
||||
|
* the logical value TRUE for this argument. |
||||
|
* ReturnIfTrue can be another formula. |
||||
|
* ReturnIfFalse is the value that is returned if condition evaluates to FALSE. |
||||
|
* For example, if this argument is the text string "Over budget" and the condition argument evaluates to FALSE, |
||||
|
* then the IF function returns the text "Over budget". |
||||
|
* If condition is FALSE and ReturnIfFalse is omitted, then the logical value FALSE is returned. |
||||
|
* If condition is FALSE and ReturnIfFalse is blank, then the value 0 (zero) is returned. |
||||
|
* ReturnIfFalse can be another formula. |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Logical Functions |
||||
|
* @param mixed $condition Condition to evaluate |
||||
|
* @param mixed $returnIfTrue Value to return when condition is true |
||||
|
* @param mixed $returnIfFalse Optional value to return when condition is false |
||||
|
* @return mixed The value of returnIfTrue or returnIfFalse determined by condition |
||||
|
*/ |
||||
|
public static function STATEMENT_IF($condition = TRUE, $returnIfTrue = 0, $returnIfFalse = FALSE) { |
||||
|
$condition = (is_null($condition)) ? TRUE : (boolean) PHPExcel_Calculation_Functions::flattenSingleValue($condition); |
||||
|
$returnIfTrue = (is_null($returnIfTrue)) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($returnIfTrue); |
||||
|
$returnIfFalse = (is_null($returnIfFalse)) ? FALSE : PHPExcel_Calculation_Functions::flattenSingleValue($returnIfFalse); |
||||
|
|
||||
|
return ($condition) ? $returnIfTrue : $returnIfFalse; |
||||
|
} // function STATEMENT_IF() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* IFERROR |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =IFERROR(testValue,errorpart) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Logical Functions |
||||
|
* @param mixed $testValue Value to check, is also the value returned when no error |
||||
|
* @param mixed $errorpart Value to return when testValue is an error condition |
||||
|
* @return mixed The value of errorpart or testValue determined by error condition |
||||
|
*/ |
||||
|
public static function IFERROR($testValue = '', $errorpart = '') { |
||||
|
$testValue = (is_null($testValue)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($testValue); |
||||
|
$errorpart = (is_null($errorpart)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($errorpart); |
||||
|
|
||||
|
return self::STATEMENT_IF(PHPExcel_Calculation_Functions::IS_ERROR($testValue), $errorpart, $testValue); |
||||
|
} // function IFERROR() |
||||
|
|
||||
|
} // class PHPExcel_Calculation_Logical |
||||
@ -0,0 +1,812 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** PHPExcel root directory */ |
||||
|
if (!defined('PHPEXCEL_ROOT')) { |
||||
|
/** |
||||
|
* @ignore |
||||
|
*/ |
||||
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
||||
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Calculation_LookupRef |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Calculation_LookupRef { |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* CELL_ADDRESS |
||||
|
* |
||||
|
* Creates a cell address as text, given specified row and column numbers. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =ADDRESS(row, column, [relativity], [referenceStyle], [sheetText]) |
||||
|
* |
||||
|
* @param row Row number to use in the cell reference |
||||
|
* @param column Column number to use in the cell reference |
||||
|
* @param relativity Flag indicating the type of reference to return |
||||
|
* 1 or omitted Absolute |
||||
|
* 2 Absolute row; relative column |
||||
|
* 3 Relative row; absolute column |
||||
|
* 4 Relative |
||||
|
* @param referenceStyle A logical value that specifies the A1 or R1C1 reference style. |
||||
|
* TRUE or omitted CELL_ADDRESS returns an A1-style reference |
||||
|
* FALSE CELL_ADDRESS returns an R1C1-style reference |
||||
|
* @param sheetText Optional Name of worksheet to use |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function CELL_ADDRESS($row, $column, $relativity=1, $referenceStyle=True, $sheetText='') { |
||||
|
$row = PHPExcel_Calculation_Functions::flattenSingleValue($row); |
||||
|
$column = PHPExcel_Calculation_Functions::flattenSingleValue($column); |
||||
|
$relativity = PHPExcel_Calculation_Functions::flattenSingleValue($relativity); |
||||
|
$sheetText = PHPExcel_Calculation_Functions::flattenSingleValue($sheetText); |
||||
|
|
||||
|
if (($row < 1) || ($column < 1)) { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
|
||||
|
if ($sheetText > '') { |
||||
|
if (strpos($sheetText,' ') !== False) { $sheetText = "'".$sheetText."'"; } |
||||
|
$sheetText .='!'; |
||||
|
} |
||||
|
if ((!is_bool($referenceStyle)) || $referenceStyle) { |
||||
|
$rowRelative = $columnRelative = '$'; |
||||
|
$column = PHPExcel_Cell::stringFromColumnIndex($column-1); |
||||
|
if (($relativity == 2) || ($relativity == 4)) { $columnRelative = ''; } |
||||
|
if (($relativity == 3) || ($relativity == 4)) { $rowRelative = ''; } |
||||
|
return $sheetText.$columnRelative.$column.$rowRelative.$row; |
||||
|
} else { |
||||
|
if (($relativity == 2) || ($relativity == 4)) { $column = '['.$column.']'; } |
||||
|
if (($relativity == 3) || ($relativity == 4)) { $row = '['.$row.']'; } |
||||
|
return $sheetText.'R'.$row.'C'.$column; |
||||
|
} |
||||
|
} // function CELL_ADDRESS() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* COLUMN |
||||
|
* |
||||
|
* Returns the column number of the given cell reference |
||||
|
* If the cell reference is a range of cells, COLUMN returns the column numbers of each column in the reference as a horizontal array. |
||||
|
* If cell reference is omitted, and the function is being called through the calculation engine, then it is assumed to be the |
||||
|
* reference of the cell in which the COLUMN function appears; otherwise this function returns 0. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =COLUMN([cellAddress]) |
||||
|
* |
||||
|
* @param cellAddress A reference to a range of cells for which you want the column numbers |
||||
|
* @return integer or array of integer |
||||
|
*/ |
||||
|
public static function COLUMN($cellAddress=Null) { |
||||
|
if (is_null($cellAddress) || trim($cellAddress) === '') { return 0; } |
||||
|
|
||||
|
if (is_array($cellAddress)) { |
||||
|
foreach($cellAddress as $columnKey => $value) { |
||||
|
$columnKey = preg_replace('/[^a-z]/i','',$columnKey); |
||||
|
return (integer) PHPExcel_Cell::columnIndexFromString($columnKey); |
||||
|
} |
||||
|
} else { |
||||
|
if (strpos($cellAddress,'!') !== false) { |
||||
|
list($sheet,$cellAddress) = explode('!',$cellAddress); |
||||
|
} |
||||
|
if (strpos($cellAddress,':') !== false) { |
||||
|
list($startAddress,$endAddress) = explode(':',$cellAddress); |
||||
|
$startAddress = preg_replace('/[^a-z]/i','',$startAddress); |
||||
|
$endAddress = preg_replace('/[^a-z]/i','',$endAddress); |
||||
|
$returnValue = array(); |
||||
|
do { |
||||
|
$returnValue[] = (integer) PHPExcel_Cell::columnIndexFromString($startAddress); |
||||
|
} while ($startAddress++ != $endAddress); |
||||
|
return $returnValue; |
||||
|
} else { |
||||
|
$cellAddress = preg_replace('/[^a-z]/i','',$cellAddress); |
||||
|
return (integer) PHPExcel_Cell::columnIndexFromString($cellAddress); |
||||
|
} |
||||
|
} |
||||
|
} // function COLUMN() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* COLUMNS |
||||
|
* |
||||
|
* Returns the number of columns in an array or reference. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =COLUMNS(cellAddress) |
||||
|
* |
||||
|
* @param cellAddress An array or array formula, or a reference to a range of cells for which you want the number of columns |
||||
|
* @return integer The number of columns in cellAddress |
||||
|
*/ |
||||
|
public static function COLUMNS($cellAddress=Null) { |
||||
|
if (is_null($cellAddress) || $cellAddress === '') { |
||||
|
return 1; |
||||
|
} elseif (!is_array($cellAddress)) { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
|
||||
|
$x = array_keys($cellAddress); |
||||
|
$x = array_shift($x); |
||||
|
$isMatrix = (is_numeric($x)); |
||||
|
list($columns,$rows) = PHPExcel_Calculation::_getMatrixDimensions($cellAddress); |
||||
|
|
||||
|
if ($isMatrix) { |
||||
|
return $rows; |
||||
|
} else { |
||||
|
return $columns; |
||||
|
} |
||||
|
} // function COLUMNS() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* ROW |
||||
|
* |
||||
|
* Returns the row number of the given cell reference |
||||
|
* If the cell reference is a range of cells, ROW returns the row numbers of each row in the reference as a vertical array. |
||||
|
* If cell reference is omitted, and the function is being called through the calculation engine, then it is assumed to be the |
||||
|
* reference of the cell in which the ROW function appears; otherwise this function returns 0. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =ROW([cellAddress]) |
||||
|
* |
||||
|
* @param cellAddress A reference to a range of cells for which you want the row numbers |
||||
|
* @return integer or array of integer |
||||
|
*/ |
||||
|
public static function ROW($cellAddress=Null) { |
||||
|
if (is_null($cellAddress) || trim($cellAddress) === '') { return 0; } |
||||
|
|
||||
|
if (is_array($cellAddress)) { |
||||
|
foreach($cellAddress as $columnKey => $rowValue) { |
||||
|
foreach($rowValue as $rowKey => $cellValue) { |
||||
|
return (integer) preg_replace('/[^0-9]/i','',$rowKey); |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
if (strpos($cellAddress,'!') !== false) { |
||||
|
list($sheet,$cellAddress) = explode('!',$cellAddress); |
||||
|
} |
||||
|
if (strpos($cellAddress,':') !== false) { |
||||
|
list($startAddress,$endAddress) = explode(':',$cellAddress); |
||||
|
$startAddress = preg_replace('/[^0-9]/','',$startAddress); |
||||
|
$endAddress = preg_replace('/[^0-9]/','',$endAddress); |
||||
|
$returnValue = array(); |
||||
|
do { |
||||
|
$returnValue[][] = (integer) $startAddress; |
||||
|
} while ($startAddress++ != $endAddress); |
||||
|
return $returnValue; |
||||
|
} else { |
||||
|
list($cellAddress) = explode(':',$cellAddress); |
||||
|
return (integer) preg_replace('/[^0-9]/','',$cellAddress); |
||||
|
} |
||||
|
} |
||||
|
} // function ROW() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* ROWS |
||||
|
* |
||||
|
* Returns the number of rows in an array or reference. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =ROWS(cellAddress) |
||||
|
* |
||||
|
* @param cellAddress An array or array formula, or a reference to a range of cells for which you want the number of rows |
||||
|
* @return integer The number of rows in cellAddress |
||||
|
*/ |
||||
|
public static function ROWS($cellAddress=Null) { |
||||
|
if (is_null($cellAddress) || $cellAddress === '') { |
||||
|
return 1; |
||||
|
} elseif (!is_array($cellAddress)) { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
|
||||
|
$i = array_keys($cellAddress); |
||||
|
$isMatrix = (is_numeric(array_shift($i))); |
||||
|
list($columns,$rows) = PHPExcel_Calculation::_getMatrixDimensions($cellAddress); |
||||
|
|
||||
|
if ($isMatrix) { |
||||
|
return $columns; |
||||
|
} else { |
||||
|
return $rows; |
||||
|
} |
||||
|
} // function ROWS() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* HYPERLINK |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =HYPERLINK(linkURL,displayName) |
||||
|
* |
||||
|
* @access public |
||||
|
* @category Logical Functions |
||||
|
* @param string $linkURL Value to check, is also the value returned when no error |
||||
|
* @param string $displayName Value to return when testValue is an error condition |
||||
|
* @param PHPExcel_Cell $pCell The cell to set the hyperlink in |
||||
|
* @return mixed The value of $displayName (or $linkURL if $displayName was blank) |
||||
|
*/ |
||||
|
public static function HYPERLINK($linkURL = '', $displayName = null, PHPExcel_Cell $pCell = null) { |
||||
|
$args = func_get_args(); |
||||
|
$pCell = array_pop($args); |
||||
|
|
||||
|
$linkURL = (is_null($linkURL)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($linkURL); |
||||
|
$displayName = (is_null($displayName)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($displayName); |
||||
|
|
||||
|
if ((!is_object($pCell)) || (trim($linkURL) == '')) { |
||||
|
return PHPExcel_Calculation_Functions::REF(); |
||||
|
} |
||||
|
|
||||
|
if ((is_object($displayName)) || trim($displayName) == '') { |
||||
|
$displayName = $linkURL; |
||||
|
} |
||||
|
|
||||
|
$pCell->getHyperlink()->setUrl($linkURL); |
||||
|
|
||||
|
return $displayName; |
||||
|
} // function HYPERLINK() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* INDIRECT |
||||
|
* |
||||
|
* Returns the reference specified by a text string. |
||||
|
* References are immediately evaluated to display their contents. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =INDIRECT(cellAddress) |
||||
|
* |
||||
|
* NOTE - INDIRECT() does not yet support the optional a1 parameter introduced in Excel 2010 |
||||
|
* |
||||
|
* @param cellAddress $cellAddress The cell address of the current cell (containing this formula) |
||||
|
* @param PHPExcel_Cell $pCell The current cell (containing this formula) |
||||
|
* @return mixed The cells referenced by cellAddress |
||||
|
* |
||||
|
* @todo Support for the optional a1 parameter introduced in Excel 2010 |
||||
|
* |
||||
|
*/ |
||||
|
public static function INDIRECT($cellAddress = NULL, PHPExcel_Cell $pCell = NULL) { |
||||
|
$cellAddress = PHPExcel_Calculation_Functions::flattenSingleValue($cellAddress); |
||||
|
if (is_null($cellAddress) || $cellAddress === '') { |
||||
|
return PHPExcel_Calculation_Functions::REF(); |
||||
|
} |
||||
|
|
||||
|
$cellAddress1 = $cellAddress; |
||||
|
$cellAddress2 = NULL; |
||||
|
if (strpos($cellAddress,':') !== false) { |
||||
|
list($cellAddress1,$cellAddress2) = explode(':',$cellAddress); |
||||
|
} |
||||
|
|
||||
|
if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $cellAddress1, $matches)) || |
||||
|
((!is_null($cellAddress2)) && (!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $cellAddress2, $matches)))) { |
||||
|
if (!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $cellAddress1, $matches)) { |
||||
|
return PHPExcel_Calculation_Functions::REF(); |
||||
|
} |
||||
|
|
||||
|
if (strpos($cellAddress,'!') !== FALSE) { |
||||
|
list($sheetName, $cellAddress) = explode('!',$cellAddress); |
||||
|
$sheetName = trim($sheetName, "'"); |
||||
|
$pSheet = $pCell->getParent()->getParent()->getSheetByName($sheetName); |
||||
|
} else { |
||||
|
$pSheet = $pCell->getParent(); |
||||
|
} |
||||
|
|
||||
|
return PHPExcel_Calculation::getInstance()->extractNamedRange($cellAddress, $pSheet, FALSE); |
||||
|
} |
||||
|
|
||||
|
if (strpos($cellAddress,'!') !== FALSE) { |
||||
|
list($sheetName,$cellAddress) = explode('!',$cellAddress); |
||||
|
$sheetName = trim($sheetName, "'"); |
||||
|
$pSheet = $pCell->getParent()->getParent()->getSheetByName($sheetName); |
||||
|
} else { |
||||
|
$pSheet = $pCell->getParent(); |
||||
|
} |
||||
|
|
||||
|
return PHPExcel_Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, FALSE); |
||||
|
} // function INDIRECT() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* OFFSET |
||||
|
* |
||||
|
* Returns a reference to a range that is a specified number of rows and columns from a cell or range of cells. |
||||
|
* The reference that is returned can be a single cell or a range of cells. You can specify the number of rows and |
||||
|
* the number of columns to be returned. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =OFFSET(cellAddress, rows, cols, [height], [width]) |
||||
|
* |
||||
|
* @param cellAddress The reference from which you want to base the offset. Reference must refer to a cell or |
||||
|
* range of adjacent cells; otherwise, OFFSET returns the #VALUE! error value. |
||||
|
* @param rows The number of rows, up or down, that you want the upper-left cell to refer to. |
||||
|
* Using 5 as the rows argument specifies that the upper-left cell in the reference is |
||||
|
* five rows below reference. Rows can be positive (which means below the starting reference) |
||||
|
* or negative (which means above the starting reference). |
||||
|
* @param cols The number of columns, to the left or right, that you want the upper-left cell of the result |
||||
|
* to refer to. Using 5 as the cols argument specifies that the upper-left cell in the |
||||
|
* reference is five columns to the right of reference. Cols can be positive (which means |
||||
|
* to the right of the starting reference) or negative (which means to the left of the |
||||
|
* starting reference). |
||||
|
* @param height The height, in number of rows, that you want the returned reference to be. Height must be a positive number. |
||||
|
* @param width The width, in number of columns, that you want the returned reference to be. Width must be a positive number. |
||||
|
* @return string A reference to a cell or range of cells |
||||
|
*/ |
||||
|
public static function OFFSET($cellAddress=Null,$rows=0,$columns=0,$height=null,$width=null) { |
||||
|
$rows = PHPExcel_Calculation_Functions::flattenSingleValue($rows); |
||||
|
$columns = PHPExcel_Calculation_Functions::flattenSingleValue($columns); |
||||
|
$height = PHPExcel_Calculation_Functions::flattenSingleValue($height); |
||||
|
$width = PHPExcel_Calculation_Functions::flattenSingleValue($width); |
||||
|
if ($cellAddress == Null) { |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
$args = func_get_args(); |
||||
|
$pCell = array_pop($args); |
||||
|
if (!is_object($pCell)) { |
||||
|
return PHPExcel_Calculation_Functions::REF(); |
||||
|
} |
||||
|
|
||||
|
$sheetName = NULL; |
||||
|
if (strpos($cellAddress,"!")) { |
||||
|
list($sheetName,$cellAddress) = explode("!",$cellAddress); |
||||
|
$sheetName = trim($sheetName, "'"); |
||||
|
} |
||||
|
if (strpos($cellAddress,":")) { |
||||
|
list($startCell,$endCell) = explode(":",$cellAddress); |
||||
|
} else { |
||||
|
$startCell = $endCell = $cellAddress; |
||||
|
} |
||||
|
list($startCellColumn,$startCellRow) = PHPExcel_Cell::coordinateFromString($startCell); |
||||
|
list($endCellColumn,$endCellRow) = PHPExcel_Cell::coordinateFromString($endCell); |
||||
|
|
||||
|
$startCellRow += $rows; |
||||
|
$startCellColumn = PHPExcel_Cell::columnIndexFromString($startCellColumn) - 1; |
||||
|
$startCellColumn += $columns; |
||||
|
|
||||
|
if (($startCellRow <= 0) || ($startCellColumn < 0)) { |
||||
|
return PHPExcel_Calculation_Functions::REF(); |
||||
|
} |
||||
|
$endCellColumn = PHPExcel_Cell::columnIndexFromString($endCellColumn) - 1; |
||||
|
if (($width != null) && (!is_object($width))) { |
||||
|
$endCellColumn = $startCellColumn + $width - 1; |
||||
|
} else { |
||||
|
$endCellColumn += $columns; |
||||
|
} |
||||
|
$startCellColumn = PHPExcel_Cell::stringFromColumnIndex($startCellColumn); |
||||
|
|
||||
|
if (($height != null) && (!is_object($height))) { |
||||
|
$endCellRow = $startCellRow + $height - 1; |
||||
|
} else { |
||||
|
$endCellRow += $rows; |
||||
|
} |
||||
|
|
||||
|
if (($endCellRow <= 0) || ($endCellColumn < 0)) { |
||||
|
return PHPExcel_Calculation_Functions::REF(); |
||||
|
} |
||||
|
$endCellColumn = PHPExcel_Cell::stringFromColumnIndex($endCellColumn); |
||||
|
|
||||
|
$cellAddress = $startCellColumn.$startCellRow; |
||||
|
if (($startCellColumn != $endCellColumn) || ($startCellRow != $endCellRow)) { |
||||
|
$cellAddress .= ':'.$endCellColumn.$endCellRow; |
||||
|
} |
||||
|
|
||||
|
if ($sheetName !== NULL) { |
||||
|
$pSheet = $pCell->getParent()->getParent()->getSheetByName($sheetName); |
||||
|
} else { |
||||
|
$pSheet = $pCell->getParent(); |
||||
|
} |
||||
|
|
||||
|
return PHPExcel_Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, False); |
||||
|
} // function OFFSET() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* CHOOSE |
||||
|
* |
||||
|
* Uses lookup_value to return a value from the list of value arguments. |
||||
|
* Use CHOOSE to select one of up to 254 values based on the lookup_value. |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =CHOOSE(index_num, value1, [value2], ...) |
||||
|
* |
||||
|
* @param index_num Specifies which value argument is selected. |
||||
|
* Index_num must be a number between 1 and 254, or a formula or reference to a cell containing a number |
||||
|
* between 1 and 254. |
||||
|
* @param value1... Value1 is required, subsequent values are optional. |
||||
|
* Between 1 to 254 value arguments from which CHOOSE selects a value or an action to perform based on |
||||
|
* index_num. The arguments can be numbers, cell references, defined names, formulas, functions, or |
||||
|
* text. |
||||
|
* @return mixed The selected value |
||||
|
*/ |
||||
|
public static function CHOOSE() { |
||||
|
$chooseArgs = func_get_args(); |
||||
|
$chosenEntry = PHPExcel_Calculation_Functions::flattenArray(array_shift($chooseArgs)); |
||||
|
$entryCount = count($chooseArgs) - 1; |
||||
|
|
||||
|
if(is_array($chosenEntry)) { |
||||
|
$chosenEntry = array_shift($chosenEntry); |
||||
|
} |
||||
|
if ((is_numeric($chosenEntry)) && (!is_bool($chosenEntry))) { |
||||
|
--$chosenEntry; |
||||
|
} else { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
$chosenEntry = floor($chosenEntry); |
||||
|
if (($chosenEntry <= 0) || ($chosenEntry > $entryCount)) { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
|
||||
|
if (is_array($chooseArgs[$chosenEntry])) { |
||||
|
return PHPExcel_Calculation_Functions::flattenArray($chooseArgs[$chosenEntry]); |
||||
|
} else { |
||||
|
return $chooseArgs[$chosenEntry]; |
||||
|
} |
||||
|
} // function CHOOSE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* MATCH |
||||
|
* |
||||
|
* The MATCH function searches for a specified item in a range of cells |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =MATCH(lookup_value, lookup_array, [match_type]) |
||||
|
* |
||||
|
* @param lookup_value The value that you want to match in lookup_array |
||||
|
* @param lookup_array The range of cells being searched |
||||
|
* @param match_type The number -1, 0, or 1. -1 means above, 0 means exact match, 1 means below. If match_type is 1 or -1, the list has to be ordered. |
||||
|
* @return integer The relative position of the found item |
||||
|
*/ |
||||
|
public static function MATCH($lookup_value, $lookup_array, $match_type=1) { |
||||
|
$lookup_array = PHPExcel_Calculation_Functions::flattenArray($lookup_array); |
||||
|
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value); |
||||
|
$match_type = (is_null($match_type)) ? 1 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($match_type); |
||||
|
// MATCH is not case sensitive |
||||
|
$lookup_value = strtolower($lookup_value); |
||||
|
|
||||
|
// lookup_value type has to be number, text, or logical values |
||||
|
if ((!is_numeric($lookup_value)) && (!is_string($lookup_value)) && (!is_bool($lookup_value))) { |
||||
|
return PHPExcel_Calculation_Functions::NA(); |
||||
|
} |
||||
|
|
||||
|
// match_type is 0, 1 or -1 |
||||
|
if (($match_type !== 0) && ($match_type !== -1) && ($match_type !== 1)) { |
||||
|
return PHPExcel_Calculation_Functions::NA(); |
||||
|
} |
||||
|
|
||||
|
// lookup_array should not be empty |
||||
|
$lookupArraySize = count($lookup_array); |
||||
|
if ($lookupArraySize <= 0) { |
||||
|
return PHPExcel_Calculation_Functions::NA(); |
||||
|
} |
||||
|
|
||||
|
// lookup_array should contain only number, text, or logical values, or empty (null) cells |
||||
|
foreach($lookup_array as $i => $lookupArrayValue) { |
||||
|
// check the type of the value |
||||
|
if ((!is_numeric($lookupArrayValue)) && (!is_string($lookupArrayValue)) && |
||||
|
(!is_bool($lookupArrayValue)) && (!is_null($lookupArrayValue))) { |
||||
|
return PHPExcel_Calculation_Functions::NA(); |
||||
|
} |
||||
|
// convert strings to lowercase for case-insensitive testing |
||||
|
if (is_string($lookupArrayValue)) { |
||||
|
$lookup_array[$i] = strtolower($lookupArrayValue); |
||||
|
} |
||||
|
if ((is_null($lookupArrayValue)) && (($match_type == 1) || ($match_type == -1))) { |
||||
|
$lookup_array = array_slice($lookup_array,0,$i-1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// if match_type is 1 or -1, the list has to be ordered |
||||
|
if ($match_type == 1) { |
||||
|
asort($lookup_array); |
||||
|
$keySet = array_keys($lookup_array); |
||||
|
} elseif($match_type == -1) { |
||||
|
arsort($lookup_array); |
||||
|
$keySet = array_keys($lookup_array); |
||||
|
} |
||||
|
|
||||
|
// ** |
||||
|
// find the match |
||||
|
// ** |
||||
|
// loop on the cells |
||||
|
// var_dump($lookup_array); |
||||
|
// echo '<br />'; |
||||
|
foreach($lookup_array as $i => $lookupArrayValue) { |
||||
|
if (($match_type == 0) && ($lookupArrayValue == $lookup_value)) { |
||||
|
// exact match |
||||
|
return ++$i; |
||||
|
} elseif (($match_type == -1) && ($lookupArrayValue <= $lookup_value)) { |
||||
|
// echo '$i = '.$i.' => '; |
||||
|
// var_dump($lookupArrayValue); |
||||
|
// echo '<br />'; |
||||
|
// echo 'Keyset = '; |
||||
|
// var_dump($keySet); |
||||
|
// echo '<br />'; |
||||
|
$i = array_search($i,$keySet); |
||||
|
// echo '$i='.$i.'<br />'; |
||||
|
// if match_type is -1 <=> find the smallest value that is greater than or equal to lookup_value |
||||
|
if ($i < 1){ |
||||
|
// 1st cell was allready smaller than the lookup_value |
||||
|
break; |
||||
|
} else { |
||||
|
// the previous cell was the match |
||||
|
return $keySet[$i-1]+1; |
||||
|
} |
||||
|
} elseif (($match_type == 1) && ($lookupArrayValue >= $lookup_value)) { |
||||
|
// echo '$i = '.$i.' => '; |
||||
|
// var_dump($lookupArrayValue); |
||||
|
// echo '<br />'; |
||||
|
// echo 'Keyset = '; |
||||
|
// var_dump($keySet); |
||||
|
// echo '<br />'; |
||||
|
$i = array_search($i,$keySet); |
||||
|
// echo '$i='.$i.'<br />'; |
||||
|
// if match_type is 1 <=> find the largest value that is less than or equal to lookup_value |
||||
|
if ($i < 1){ |
||||
|
// 1st cell was allready bigger than the lookup_value |
||||
|
break; |
||||
|
} else { |
||||
|
// the previous cell was the match |
||||
|
return $keySet[$i-1]+1; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// unsuccessful in finding a match, return #N/A error value |
||||
|
return PHPExcel_Calculation_Functions::NA(); |
||||
|
} // function MATCH() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* INDEX |
||||
|
* |
||||
|
* Uses an index to choose a value from a reference or array |
||||
|
* |
||||
|
* Excel Function: |
||||
|
* =INDEX(range_array, row_num, [column_num]) |
||||
|
* |
||||
|
* @param range_array A range of cells or an array constant |
||||
|
* @param row_num The row in array from which to return a value. If row_num is omitted, column_num is required. |
||||
|
* @param column_num The column in array from which to return a value. If column_num is omitted, row_num is required. |
||||
|
* @return mixed the value of a specified cell or array of cells |
||||
|
*/ |
||||
|
public static function INDEX($arrayValues,$rowNum = 0,$columnNum = 0) { |
||||
|
|
||||
|
if (($rowNum < 0) || ($columnNum < 0)) { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
|
||||
|
if (!is_array($arrayValues)) { |
||||
|
return PHPExcel_Calculation_Functions::REF(); |
||||
|
} |
||||
|
|
||||
|
$rowKeys = array_keys($arrayValues); |
||||
|
$columnKeys = @array_keys($arrayValues[$rowKeys[0]]); |
||||
|
|
||||
|
if ($columnNum > count($columnKeys)) { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} elseif ($columnNum == 0) { |
||||
|
if ($rowNum == 0) { |
||||
|
return $arrayValues; |
||||
|
} |
||||
|
$rowNum = $rowKeys[--$rowNum]; |
||||
|
$returnArray = array(); |
||||
|
foreach($arrayValues as $arrayColumn) { |
||||
|
if (is_array($arrayColumn)) { |
||||
|
if (isset($arrayColumn[$rowNum])) { |
||||
|
$returnArray[] = $arrayColumn[$rowNum]; |
||||
|
} else { |
||||
|
return $arrayValues[$rowNum]; |
||||
|
} |
||||
|
} else { |
||||
|
return $arrayValues[$rowNum]; |
||||
|
} |
||||
|
} |
||||
|
return $returnArray; |
||||
|
} |
||||
|
$columnNum = $columnKeys[--$columnNum]; |
||||
|
if ($rowNum > count($rowKeys)) { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} elseif ($rowNum == 0) { |
||||
|
return $arrayValues[$columnNum]; |
||||
|
} |
||||
|
$rowNum = $rowKeys[--$rowNum]; |
||||
|
|
||||
|
return $arrayValues[$rowNum][$columnNum]; |
||||
|
} // function INDEX() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* TRANSPOSE |
||||
|
* |
||||
|
* @param array $matrixData A matrix of values |
||||
|
* @return array |
||||
|
* |
||||
|
* Unlike the Excel TRANSPOSE function, which will only work on a single row or column, this function will transpose a full matrix. |
||||
|
*/ |
||||
|
public static function TRANSPOSE($matrixData) { |
||||
|
$returnMatrix = array(); |
||||
|
if (!is_array($matrixData)) { $matrixData = array(array($matrixData)); } |
||||
|
|
||||
|
$column = 0; |
||||
|
foreach($matrixData as $matrixRow) { |
||||
|
$row = 0; |
||||
|
foreach($matrixRow as $matrixCell) { |
||||
|
$returnMatrix[$row][$column] = $matrixCell; |
||||
|
++$row; |
||||
|
} |
||||
|
++$column; |
||||
|
} |
||||
|
return $returnMatrix; |
||||
|
} // function TRANSPOSE() |
||||
|
|
||||
|
|
||||
|
private static function _vlookupSort($a,$b) { |
||||
|
$f = array_keys($a); |
||||
|
$firstColumn = array_shift($f); |
||||
|
if (strtolower($a[$firstColumn]) == strtolower($b[$firstColumn])) { |
||||
|
return 0; |
||||
|
} |
||||
|
return (strtolower($a[$firstColumn]) < strtolower($b[$firstColumn])) ? -1 : 1; |
||||
|
} // function _vlookupSort() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* VLOOKUP |
||||
|
* The VLOOKUP function searches for value in the left-most column of lookup_array and returns the value in the same row based on the index_number. |
||||
|
* @param lookup_value The value that you want to match in lookup_array |
||||
|
* @param lookup_array The range of cells being searched |
||||
|
* @param index_number The column number in table_array from which the matching value must be returned. The first column is 1. |
||||
|
* @param not_exact_match Determines if you are looking for an exact match based on lookup_value. |
||||
|
* @return mixed The value of the found cell |
||||
|
*/ |
||||
|
public static function VLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match=true) { |
||||
|
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value); |
||||
|
$index_number = PHPExcel_Calculation_Functions::flattenSingleValue($index_number); |
||||
|
$not_exact_match = PHPExcel_Calculation_Functions::flattenSingleValue($not_exact_match); |
||||
|
|
||||
|
// index_number must be greater than or equal to 1 |
||||
|
if ($index_number < 1) { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
|
||||
|
// index_number must be less than or equal to the number of columns in lookup_array |
||||
|
if ((!is_array($lookup_array)) || (empty($lookup_array))) { |
||||
|
return PHPExcel_Calculation_Functions::REF(); |
||||
|
} else { |
||||
|
$f = array_keys($lookup_array); |
||||
|
$firstRow = array_pop($f); |
||||
|
if ((!is_array($lookup_array[$firstRow])) || ($index_number > count($lookup_array[$firstRow]))) { |
||||
|
return PHPExcel_Calculation_Functions::REF(); |
||||
|
} else { |
||||
|
$columnKeys = array_keys($lookup_array[$firstRow]); |
||||
|
$returnColumn = $columnKeys[--$index_number]; |
||||
|
$firstColumn = array_shift($columnKeys); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!$not_exact_match) { |
||||
|
uasort($lookup_array,array('self','_vlookupSort')); |
||||
|
} |
||||
|
|
||||
|
$rowNumber = $rowValue = False; |
||||
|
foreach($lookup_array as $rowKey => $rowData) { |
||||
|
if (strtolower($rowData[$firstColumn]) > strtolower($lookup_value)) { |
||||
|
break; |
||||
|
} |
||||
|
$rowNumber = $rowKey; |
||||
|
$rowValue = $rowData[$firstColumn]; |
||||
|
} |
||||
|
|
||||
|
if ($rowNumber !== false) { |
||||
|
if ((!$not_exact_match) && ($rowValue != $lookup_value)) { |
||||
|
// if an exact match is required, we have what we need to return an appropriate response |
||||
|
return PHPExcel_Calculation_Functions::NA(); |
||||
|
} else { |
||||
|
// otherwise return the appropriate value |
||||
|
return $lookup_array[$rowNumber][$returnColumn]; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return PHPExcel_Calculation_Functions::NA(); |
||||
|
} // function VLOOKUP() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* LOOKUP |
||||
|
* The LOOKUP function searches for value either from a one-row or one-column range or from an array. |
||||
|
* @param lookup_value The value that you want to match in lookup_array |
||||
|
* @param lookup_vector The range of cells being searched |
||||
|
* @param result_vector The column from which the matching value must be returned |
||||
|
* @return mixed The value of the found cell |
||||
|
*/ |
||||
|
public static function LOOKUP($lookup_value, $lookup_vector, $result_vector=null) { |
||||
|
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value); |
||||
|
|
||||
|
if (!is_array($lookup_vector)) { |
||||
|
return PHPExcel_Calculation_Functions::NA(); |
||||
|
} |
||||
|
$lookupRows = count($lookup_vector); |
||||
|
$l = array_keys($lookup_vector); |
||||
|
$l = array_shift($l); |
||||
|
$lookupColumns = count($lookup_vector[$l]); |
||||
|
if ((($lookupRows == 1) && ($lookupColumns > 1)) || (($lookupRows == 2) && ($lookupColumns != 2))) { |
||||
|
$lookup_vector = self::TRANSPOSE($lookup_vector); |
||||
|
$lookupRows = count($lookup_vector); |
||||
|
$l = array_keys($lookup_vector); |
||||
|
$lookupColumns = count($lookup_vector[array_shift($l)]); |
||||
|
} |
||||
|
|
||||
|
if (is_null($result_vector)) { |
||||
|
$result_vector = $lookup_vector; |
||||
|
} |
||||
|
$resultRows = count($result_vector); |
||||
|
$l = array_keys($result_vector); |
||||
|
$l = array_shift($l); |
||||
|
$resultColumns = count($result_vector[$l]); |
||||
|
if ((($resultRows == 1) && ($resultColumns > 1)) || (($resultRows == 2) && ($resultColumns != 2))) { |
||||
|
$result_vector = self::TRANSPOSE($result_vector); |
||||
|
$resultRows = count($result_vector); |
||||
|
$r = array_keys($result_vector); |
||||
|
$resultColumns = count($result_vector[array_shift($r)]); |
||||
|
} |
||||
|
|
||||
|
if ($lookupRows == 2) { |
||||
|
$result_vector = array_pop($lookup_vector); |
||||
|
$lookup_vector = array_shift($lookup_vector); |
||||
|
} |
||||
|
if ($lookupColumns != 2) { |
||||
|
foreach($lookup_vector as &$value) { |
||||
|
if (is_array($value)) { |
||||
|
$k = array_keys($value); |
||||
|
$key1 = $key2 = array_shift($k); |
||||
|
$key2++; |
||||
|
$dataValue1 = $value[$key1]; |
||||
|
} else { |
||||
|
$key1 = 0; |
||||
|
$key2 = 1; |
||||
|
$dataValue1 = $value; |
||||
|
} |
||||
|
$dataValue2 = array_shift($result_vector); |
||||
|
if (is_array($dataValue2)) { |
||||
|
$dataValue2 = array_shift($dataValue2); |
||||
|
} |
||||
|
$value = array($key1 => $dataValue1, $key2 => $dataValue2); |
||||
|
} |
||||
|
unset($value); |
||||
|
} |
||||
|
|
||||
|
return self::VLOOKUP($lookup_value,$lookup_vector,2); |
||||
|
} // function LOOKUP() |
||||
|
|
||||
|
} // class PHPExcel_Calculation_LookupRef |
||||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,589 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** PHPExcel root directory */ |
||||
|
if (!defined('PHPEXCEL_ROOT')) { |
||||
|
/** |
||||
|
* @ignore |
||||
|
*/ |
||||
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
||||
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Calculation_TextData |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Calculation_TextData { |
||||
|
|
||||
|
private static $_invalidChars = Null; |
||||
|
|
||||
|
private static function _uniord($c) { |
||||
|
if (ord($c{0}) >=0 && ord($c{0}) <= 127) |
||||
|
return ord($c{0}); |
||||
|
if (ord($c{0}) >= 192 && ord($c{0}) <= 223) |
||||
|
return (ord($c{0})-192)*64 + (ord($c{1})-128); |
||||
|
if (ord($c{0}) >= 224 && ord($c{0}) <= 239) |
||||
|
return (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128); |
||||
|
if (ord($c{0}) >= 240 && ord($c{0}) <= 247) |
||||
|
return (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128); |
||||
|
if (ord($c{0}) >= 248 && ord($c{0}) <= 251) |
||||
|
return (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128); |
||||
|
if (ord($c{0}) >= 252 && ord($c{0}) <= 253) |
||||
|
return (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128); |
||||
|
if (ord($c{0}) >= 254 && ord($c{0}) <= 255) //error |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
return 0; |
||||
|
} // function _uniord() |
||||
|
|
||||
|
/** |
||||
|
* CHARACTER |
||||
|
* |
||||
|
* @param string $character Value |
||||
|
* @return int |
||||
|
*/ |
||||
|
public static function CHARACTER($character) { |
||||
|
$character = PHPExcel_Calculation_Functions::flattenSingleValue($character); |
||||
|
|
||||
|
if ((!is_numeric($character)) || ($character < 0)) { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
|
||||
|
if (function_exists('mb_convert_encoding')) { |
||||
|
return mb_convert_encoding('&#'.intval($character).';', 'UTF-8', 'HTML-ENTITIES'); |
||||
|
} else { |
||||
|
return chr(intval($character)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* TRIMNONPRINTABLE |
||||
|
* |
||||
|
* @param mixed $stringValue Value to check |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function TRIMNONPRINTABLE($stringValue = '') { |
||||
|
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue); |
||||
|
|
||||
|
if (is_bool($stringValue)) { |
||||
|
return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); |
||||
|
} |
||||
|
|
||||
|
if (self::$_invalidChars == Null) { |
||||
|
self::$_invalidChars = range(chr(0),chr(31)); |
||||
|
} |
||||
|
|
||||
|
if (is_string($stringValue) || is_numeric($stringValue)) { |
||||
|
return str_replace(self::$_invalidChars,'',trim($stringValue,"\x00..\x1F")); |
||||
|
} |
||||
|
return NULL; |
||||
|
} // function TRIMNONPRINTABLE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* TRIMSPACES |
||||
|
* |
||||
|
* @param mixed $stringValue Value to check |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function TRIMSPACES($stringValue = '') { |
||||
|
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue); |
||||
|
|
||||
|
if (is_bool($stringValue)) { |
||||
|
return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); |
||||
|
} |
||||
|
|
||||
|
if (is_string($stringValue) || is_numeric($stringValue)) { |
||||
|
return trim(preg_replace('/ +/',' ',trim($stringValue,' '))); |
||||
|
} |
||||
|
return NULL; |
||||
|
} // function TRIMSPACES() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* ASCIICODE |
||||
|
* |
||||
|
* @param string $characters Value |
||||
|
* @return int |
||||
|
*/ |
||||
|
public static function ASCIICODE($characters) { |
||||
|
if (($characters === NULL) || ($characters === '')) |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
$characters = PHPExcel_Calculation_Functions::flattenSingleValue($characters); |
||||
|
if (is_bool($characters)) { |
||||
|
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { |
||||
|
$characters = (int) $characters; |
||||
|
} else { |
||||
|
$characters = ($characters) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$character = $characters; |
||||
|
if ((function_exists('mb_strlen')) && (function_exists('mb_substr'))) { |
||||
|
if (mb_strlen($characters, 'UTF-8') > 1) { $character = mb_substr($characters, 0, 1, 'UTF-8'); } |
||||
|
return self::_uniord($character); |
||||
|
} else { |
||||
|
if (strlen($characters) > 0) { $character = substr($characters, 0, 1); } |
||||
|
return ord($character); |
||||
|
} |
||||
|
} // function ASCIICODE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* CONCATENATE |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function CONCATENATE() { |
||||
|
// Return value |
||||
|
$returnValue = ''; |
||||
|
|
||||
|
// Loop through arguments |
||||
|
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); |
||||
|
foreach ($aArgs as $arg) { |
||||
|
if (is_bool($arg)) { |
||||
|
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { |
||||
|
$arg = (int) $arg; |
||||
|
} else { |
||||
|
$arg = ($arg) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); |
||||
|
} |
||||
|
} |
||||
|
$returnValue .= $arg; |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
return $returnValue; |
||||
|
} // function CONCATENATE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* DOLLAR |
||||
|
* |
||||
|
* This function converts a number to text using currency format, with the decimals rounded to the specified place. |
||||
|
* The format used is $#,##0.00_);($#,##0.00).. |
||||
|
* |
||||
|
* @param float $value The value to format |
||||
|
* @param int $decimals The number of digits to display to the right of the decimal point. |
||||
|
* If decimals is negative, number is rounded to the left of the decimal point. |
||||
|
* If you omit decimals, it is assumed to be 2 |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function DOLLAR($value = 0, $decimals = 2) { |
||||
|
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); |
||||
|
$decimals = is_null($decimals) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($decimals); |
||||
|
|
||||
|
// Validate parameters |
||||
|
if (!is_numeric($value) || !is_numeric($decimals)) { |
||||
|
return PHPExcel_Calculation_Functions::NaN(); |
||||
|
} |
||||
|
$decimals = floor($decimals); |
||||
|
|
||||
|
if ($decimals > 0) { |
||||
|
return money_format('%.'.$decimals.'n',$value); |
||||
|
} else { |
||||
|
$round = pow(10,abs($decimals)); |
||||
|
if ($value < 0) { $round = 0-$round; } |
||||
|
$value = PHPExcel_Calculation_MathTrig::MROUND($value,$round); |
||||
|
// The implementation of money_format used if the standard PHP function is not available can't handle decimal places of 0, |
||||
|
// so we display to 1 dp and chop off that character and the decimal separator using substr |
||||
|
return substr(money_format('%.1n',$value),0,-2); |
||||
|
} |
||||
|
} // function DOLLAR() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* SEARCHSENSITIVE |
||||
|
* |
||||
|
* @param string $needle The string to look for |
||||
|
* @param string $haystack The string in which to look |
||||
|
* @param int $offset Offset within $haystack |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function SEARCHSENSITIVE($needle,$haystack,$offset=1) { |
||||
|
$needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle); |
||||
|
$haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack); |
||||
|
$offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset); |
||||
|
|
||||
|
if (!is_bool($needle)) { |
||||
|
if (is_bool($haystack)) { |
||||
|
$haystack = ($haystack) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); |
||||
|
} |
||||
|
|
||||
|
if (($offset > 0) && (PHPExcel_Shared_String::CountCharacters($haystack) > $offset)) { |
||||
|
if (PHPExcel_Shared_String::CountCharacters($needle) == 0) { |
||||
|
return $offset; |
||||
|
} |
||||
|
if (function_exists('mb_strpos')) { |
||||
|
$pos = mb_strpos($haystack, $needle, --$offset, 'UTF-8'); |
||||
|
} else { |
||||
|
$pos = strpos($haystack, $needle, --$offset); |
||||
|
} |
||||
|
if ($pos !== false) { |
||||
|
return ++$pos; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} // function SEARCHSENSITIVE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* SEARCHINSENSITIVE |
||||
|
* |
||||
|
* @param string $needle The string to look for |
||||
|
* @param string $haystack The string in which to look |
||||
|
* @param int $offset Offset within $haystack |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function SEARCHINSENSITIVE($needle,$haystack,$offset=1) { |
||||
|
$needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle); |
||||
|
$haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack); |
||||
|
$offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset); |
||||
|
|
||||
|
if (!is_bool($needle)) { |
||||
|
if (is_bool($haystack)) { |
||||
|
$haystack = ($haystack) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); |
||||
|
} |
||||
|
|
||||
|
if (($offset > 0) && (PHPExcel_Shared_String::CountCharacters($haystack) > $offset)) { |
||||
|
if (PHPExcel_Shared_String::CountCharacters($needle) == 0) { |
||||
|
return $offset; |
||||
|
} |
||||
|
if (function_exists('mb_stripos')) { |
||||
|
$pos = mb_stripos($haystack, $needle, --$offset,'UTF-8'); |
||||
|
} else { |
||||
|
$pos = stripos($haystack, $needle, --$offset); |
||||
|
} |
||||
|
if ($pos !== false) { |
||||
|
return ++$pos; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} // function SEARCHINSENSITIVE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* FIXEDFORMAT |
||||
|
* |
||||
|
* @param mixed $value Value to check |
||||
|
* @param integer $decimals |
||||
|
* @param boolean $no_commas |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function FIXEDFORMAT($value, $decimals = 2, $no_commas = FALSE) { |
||||
|
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); |
||||
|
$decimals = PHPExcel_Calculation_Functions::flattenSingleValue($decimals); |
||||
|
$no_commas = PHPExcel_Calculation_Functions::flattenSingleValue($no_commas); |
||||
|
|
||||
|
// Validate parameters |
||||
|
if (!is_numeric($value) || !is_numeric($decimals)) { |
||||
|
return PHPExcel_Calculation_Functions::NaN(); |
||||
|
} |
||||
|
$decimals = floor($decimals); |
||||
|
|
||||
|
$valueResult = round($value,$decimals); |
||||
|
if ($decimals < 0) { $decimals = 0; } |
||||
|
if (!$no_commas) { |
||||
|
$valueResult = number_format($valueResult,$decimals); |
||||
|
} |
||||
|
|
||||
|
return (string) $valueResult; |
||||
|
} // function FIXEDFORMAT() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* LEFT |
||||
|
* |
||||
|
* @param string $value Value |
||||
|
* @param int $chars Number of characters |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function LEFT($value = '', $chars = 1) { |
||||
|
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); |
||||
|
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); |
||||
|
|
||||
|
if ($chars < 0) { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
|
||||
|
if (is_bool($value)) { |
||||
|
$value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); |
||||
|
} |
||||
|
|
||||
|
if (function_exists('mb_substr')) { |
||||
|
return mb_substr($value, 0, $chars, 'UTF-8'); |
||||
|
} else { |
||||
|
return substr($value, 0, $chars); |
||||
|
} |
||||
|
} // function LEFT() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* MID |
||||
|
* |
||||
|
* @param string $value Value |
||||
|
* @param int $start Start character |
||||
|
* @param int $chars Number of characters |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function MID($value = '', $start = 1, $chars = null) { |
||||
|
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); |
||||
|
$start = PHPExcel_Calculation_Functions::flattenSingleValue($start); |
||||
|
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); |
||||
|
|
||||
|
if (($start < 1) || ($chars < 0)) { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
|
||||
|
if (is_bool($value)) { |
||||
|
$value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); |
||||
|
} |
||||
|
|
||||
|
if (function_exists('mb_substr')) { |
||||
|
return mb_substr($value, --$start, $chars, 'UTF-8'); |
||||
|
} else { |
||||
|
return substr($value, --$start, $chars); |
||||
|
} |
||||
|
} // function MID() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* RIGHT |
||||
|
* |
||||
|
* @param string $value Value |
||||
|
* @param int $chars Number of characters |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function RIGHT($value = '', $chars = 1) { |
||||
|
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); |
||||
|
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); |
||||
|
|
||||
|
if ($chars < 0) { |
||||
|
return PHPExcel_Calculation_Functions::VALUE(); |
||||
|
} |
||||
|
|
||||
|
if (is_bool($value)) { |
||||
|
$value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); |
||||
|
} |
||||
|
|
||||
|
if ((function_exists('mb_substr')) && (function_exists('mb_strlen'))) { |
||||
|
return mb_substr($value, mb_strlen($value, 'UTF-8') - $chars, $chars, 'UTF-8'); |
||||
|
} else { |
||||
|
return substr($value, strlen($value) - $chars); |
||||
|
} |
||||
|
} // function RIGHT() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* STRINGLENGTH |
||||
|
* |
||||
|
* @param string $value Value |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function STRINGLENGTH($value = '') { |
||||
|
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); |
||||
|
|
||||
|
if (is_bool($value)) { |
||||
|
$value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); |
||||
|
} |
||||
|
|
||||
|
if (function_exists('mb_strlen')) { |
||||
|
return mb_strlen($value, 'UTF-8'); |
||||
|
} else { |
||||
|
return strlen($value); |
||||
|
} |
||||
|
} // function STRINGLENGTH() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* LOWERCASE |
||||
|
* |
||||
|
* Converts a string value to upper case. |
||||
|
* |
||||
|
* @param string $mixedCaseString |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function LOWERCASE($mixedCaseString) { |
||||
|
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); |
||||
|
|
||||
|
if (is_bool($mixedCaseString)) { |
||||
|
$mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); |
||||
|
} |
||||
|
|
||||
|
return PHPExcel_Shared_String::StrToLower($mixedCaseString); |
||||
|
} // function LOWERCASE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* UPPERCASE |
||||
|
* |
||||
|
* Converts a string value to upper case. |
||||
|
* |
||||
|
* @param string $mixedCaseString |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function UPPERCASE($mixedCaseString) { |
||||
|
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); |
||||
|
|
||||
|
if (is_bool($mixedCaseString)) { |
||||
|
$mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); |
||||
|
} |
||||
|
|
||||
|
return PHPExcel_Shared_String::StrToUpper($mixedCaseString); |
||||
|
} // function UPPERCASE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PROPERCASE |
||||
|
* |
||||
|
* Converts a string value to upper case. |
||||
|
* |
||||
|
* @param string $mixedCaseString |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function PROPERCASE($mixedCaseString) { |
||||
|
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); |
||||
|
|
||||
|
if (is_bool($mixedCaseString)) { |
||||
|
$mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); |
||||
|
} |
||||
|
|
||||
|
return PHPExcel_Shared_String::StrToTitle($mixedCaseString); |
||||
|
} // function PROPERCASE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* REPLACE |
||||
|
* |
||||
|
* @param string $oldText String to modify |
||||
|
* @param int $start Start character |
||||
|
* @param int $chars Number of characters |
||||
|
* @param string $newText String to replace in defined position |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function REPLACE($oldText = '', $start = 1, $chars = null, $newText) { |
||||
|
$oldText = PHPExcel_Calculation_Functions::flattenSingleValue($oldText); |
||||
|
$start = PHPExcel_Calculation_Functions::flattenSingleValue($start); |
||||
|
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); |
||||
|
$newText = PHPExcel_Calculation_Functions::flattenSingleValue($newText); |
||||
|
|
||||
|
$left = self::LEFT($oldText,$start-1); |
||||
|
$right = self::RIGHT($oldText,self::STRINGLENGTH($oldText)-($start+$chars)+1); |
||||
|
|
||||
|
return $left.$newText.$right; |
||||
|
} // function REPLACE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* SUBSTITUTE |
||||
|
* |
||||
|
* @param string $text Value |
||||
|
* @param string $fromText From Value |
||||
|
* @param string $toText To Value |
||||
|
* @param integer $instance Instance Number |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function SUBSTITUTE($text = '', $fromText = '', $toText = '', $instance = 0) { |
||||
|
$text = PHPExcel_Calculation_Functions::flattenSingleValue($text); |
||||
|
$fromText = PHPExcel_Calculation_Functions::flattenSingleValue($fromText); |
||||
|
$toText = PHPExcel_Calculation_Functions::flattenSingleValue($toText); |
||||
|
$instance = floor(PHPExcel_Calculation_Functions::flattenSingleValue($instance)); |
||||
|
|
||||
|
if ($instance == 0) { |
||||
|
if(function_exists('mb_str_replace')) { |
||||
|
return mb_str_replace($fromText,$toText,$text); |
||||
|
} else { |
||||
|
return str_replace($fromText,$toText,$text); |
||||
|
} |
||||
|
} else { |
||||
|
$pos = -1; |
||||
|
while($instance > 0) { |
||||
|
if (function_exists('mb_strpos')) { |
||||
|
$pos = mb_strpos($text, $fromText, $pos+1, 'UTF-8'); |
||||
|
} else { |
||||
|
$pos = strpos($text, $fromText, $pos+1); |
||||
|
} |
||||
|
if ($pos === false) { |
||||
|
break; |
||||
|
} |
||||
|
--$instance; |
||||
|
} |
||||
|
if ($pos !== false) { |
||||
|
if (function_exists('mb_strlen')) { |
||||
|
return self::REPLACE($text,++$pos,mb_strlen($fromText, 'UTF-8'),$toText); |
||||
|
} else { |
||||
|
return self::REPLACE($text,++$pos,strlen($fromText),$toText); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $text; |
||||
|
} // function SUBSTITUTE() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* RETURNSTRING |
||||
|
* |
||||
|
* @param mixed $testValue Value to check |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function RETURNSTRING($testValue = '') { |
||||
|
$testValue = PHPExcel_Calculation_Functions::flattenSingleValue($testValue); |
||||
|
|
||||
|
if (is_string($testValue)) { |
||||
|
return $testValue; |
||||
|
} |
||||
|
return Null; |
||||
|
} // function RETURNSTRING() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* TEXTFORMAT |
||||
|
* |
||||
|
* @param mixed $value Value to check |
||||
|
* @param string $format Format mask to use |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function TEXTFORMAT($value,$format) { |
||||
|
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); |
||||
|
$format = PHPExcel_Calculation_Functions::flattenSingleValue($format); |
||||
|
|
||||
|
if ((is_string($value)) && (!is_numeric($value)) && PHPExcel_Shared_Date::isDateTimeFormatCode($format)) { |
||||
|
$value = PHPExcel_Calculation_DateTime::DATEVALUE($value); |
||||
|
} |
||||
|
|
||||
|
return (string) PHPExcel_Style_NumberFormat::toFormattedString($value,$format); |
||||
|
} // function TEXTFORMAT() |
||||
|
|
||||
|
} // class PHPExcel_Calculation_TextData |
||||
@ -0,0 +1,115 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Calculation_Token_Stack |
||||
|
* |
||||
|
* @category PHPExcel_Calculation_Token_Stack |
||||
|
* @package PHPExcel_Calculation |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Calculation_Token_Stack { |
||||
|
|
||||
|
/** |
||||
|
* The parser stack for formulae |
||||
|
* |
||||
|
* @var mixed[] |
||||
|
*/ |
||||
|
private $_stack = array(); |
||||
|
|
||||
|
/** |
||||
|
* Count of entries in the parser stack |
||||
|
* |
||||
|
* @var integer |
||||
|
*/ |
||||
|
private $_count = 0; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Return the number of entries on the stack |
||||
|
* |
||||
|
* @return integer |
||||
|
*/ |
||||
|
public function count() { |
||||
|
return $this->_count; |
||||
|
} // function count() |
||||
|
|
||||
|
/** |
||||
|
* Push a new entry onto the stack |
||||
|
* |
||||
|
* @param mixed $type |
||||
|
* @param mixed $value |
||||
|
* @param mixed $reference |
||||
|
*/ |
||||
|
public function push($type, $value, $reference = NULL) { |
||||
|
$this->_stack[$this->_count++] = array('type' => $type, |
||||
|
'value' => $value, |
||||
|
'reference' => $reference |
||||
|
); |
||||
|
if ($type == 'Function') { |
||||
|
$localeFunction = PHPExcel_Calculation::_localeFunc($value); |
||||
|
if ($localeFunction != $value) { |
||||
|
$this->_stack[($this->_count - 1)]['localeValue'] = $localeFunction; |
||||
|
} |
||||
|
} |
||||
|
} // function push() |
||||
|
|
||||
|
/** |
||||
|
* Pop the last entry from the stack |
||||
|
* |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function pop() { |
||||
|
if ($this->_count > 0) { |
||||
|
return $this->_stack[--$this->_count]; |
||||
|
} |
||||
|
return NULL; |
||||
|
} // function pop() |
||||
|
|
||||
|
/** |
||||
|
* Return an entry from the stack without removing it |
||||
|
* |
||||
|
* @param integer $n number indicating how far back in the stack we want to look |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function last($n = 1) { |
||||
|
if ($this->_count - $n < 0) { |
||||
|
return NULL; |
||||
|
} |
||||
|
return $this->_stack[$this->_count - $n]; |
||||
|
} // function last() |
||||
|
|
||||
|
/** |
||||
|
* Clear the stack |
||||
|
*/ |
||||
|
function clear() { |
||||
|
$this->_stack = array(); |
||||
|
$this->_count = 0; |
||||
|
} |
||||
|
|
||||
|
} // class PHPExcel_Calculation_Token_Stack |
||||
File diff suppressed because it is too large
@ -0,0 +1,351 @@ |
|||||
|
ABS |
||||
|
ACCRINT |
||||
|
ACCRINTM |
||||
|
ACOS |
||||
|
ACOSH |
||||
|
ADDRESS |
||||
|
AMORDEGRC |
||||
|
AMORLINC |
||||
|
AND |
||||
|
AREAS |
||||
|
ASC |
||||
|
ASIN |
||||
|
ASINH |
||||
|
ATAN |
||||
|
ATAN2 |
||||
|
ATANH |
||||
|
AVEDEV |
||||
|
AVERAGE |
||||
|
AVERAGEA |
||||
|
AVERAGEIF |
||||
|
AVERAGEIFS |
||||
|
BAHTTEXT |
||||
|
BESSELI |
||||
|
BESSELJ |
||||
|
BESSELK |
||||
|
BESSELY |
||||
|
BETADIST |
||||
|
BETAINV |
||||
|
BIN2DEC |
||||
|
BIN2HEX |
||||
|
BIN2OCT |
||||
|
BINOMDIST |
||||
|
CEILING |
||||
|
CELL |
||||
|
CHAR |
||||
|
CHIDIST |
||||
|
CHIINV |
||||
|
CHITEST |
||||
|
CHOOSE |
||||
|
CLEAN |
||||
|
CODE |
||||
|
COLUMN |
||||
|
COLUMNS |
||||
|
COMBIN |
||||
|
COMPLEX |
||||
|
CONCATENATE |
||||
|
CONFIDENCE |
||||
|
CONVERT |
||||
|
CORREL |
||||
|
COS |
||||
|
COSH |
||||
|
COUNT |
||||
|
COUNTA |
||||
|
COUNTBLANK |
||||
|
COUNTIF |
||||
|
COUNTIFS |
||||
|
COUPDAYBS |
||||
|
COUPDAYBS |
||||
|
COUPDAYSNC |
||||
|
COUPNCD |
||||
|
COUPNUM |
||||
|
COUPPCD |
||||
|
COVAR |
||||
|
CRITBINOM |
||||
|
CUBEKPIMEMBER |
||||
|
CUBEMEMBER |
||||
|
CUBEMEMBERPROPERTY |
||||
|
CUBERANKEDMEMBER |
||||
|
CUBESET |
||||
|
CUBESETCOUNT |
||||
|
CUBEVALUE |
||||
|
CUMIPMT |
||||
|
CUMPRINC |
||||
|
DATE |
||||
|
DATEDIF |
||||
|
DATEVALUE |
||||
|
DAVERAGE |
||||
|
DAY |
||||
|
DAYS360 |
||||
|
DB |
||||
|
DCOUNT |
||||
|
DCOUNTA |
||||
|
DDB |
||||
|
DEC2BIN |
||||
|
DEC2HEX |
||||
|
DEC2OCT |
||||
|
DEGREES |
||||
|
DELTA |
||||
|
DEVSQ |
||||
|
DGET |
||||
|
DISC |
||||
|
DMAX |
||||
|
DMIN |
||||
|
DOLLAR |
||||
|
DOLLARDE |
||||
|
DOLLARFR |
||||
|
DPRODUCT |
||||
|
DSTDEV |
||||
|
DSTDEVP |
||||
|
DSUM |
||||
|
DURATION |
||||
|
DVAR |
||||
|
DVARP |
||||
|
EDATE |
||||
|
EFFECT |
||||
|
EOMONTH |
||||
|
ERF |
||||
|
ERFC |
||||
|
ERROR.TYPE |
||||
|
EVEN |
||||
|
EXACT |
||||
|
EXP |
||||
|
EXPONDIST |
||||
|
FACT |
||||
|
FACTDOUBLE |
||||
|
FALSE |
||||
|
FDIST |
||||
|
FIND |
||||
|
FINDB |
||||
|
FINV |
||||
|
FISHER |
||||
|
FISHERINV |
||||
|
FIXED |
||||
|
FLOOR |
||||
|
FORECAST |
||||
|
FREQUENCY |
||||
|
FTEST |
||||
|
FV |
||||
|
FVSCHEDULE |
||||
|
GAMAMDIST |
||||
|
GAMMAINV |
||||
|
GAMMALN |
||||
|
GCD |
||||
|
GEOMEAN |
||||
|
GESTEP |
||||
|
GETPIVOTDATA |
||||
|
GROWTH |
||||
|
HARMEAN |
||||
|
HEX2BIN |
||||
|
HEX2OCT |
||||
|
HLOOKUP |
||||
|
HOUR |
||||
|
HYPERLINK |
||||
|
HYPGEOMDIST |
||||
|
IF |
||||
|
IFERROR |
||||
|
IMABS |
||||
|
IMAGINARY |
||||
|
IMARGUMENT |
||||
|
IMCONJUGATE |
||||
|
IMCOS |
||||
|
IMEXP |
||||
|
IMLN |
||||
|
IMLOG10 |
||||
|
IMLOG2 |
||||
|
IMPOWER |
||||
|
IMPRODUCT |
||||
|
IMREAL |
||||
|
IMSIN |
||||
|
IMSQRT |
||||
|
IMSUB |
||||
|
IMSUM |
||||
|
INDEX |
||||
|
INDIRECT |
||||
|
INFO |
||||
|
INT |
||||
|
INTERCEPT |
||||
|
INTRATE |
||||
|
IPMT |
||||
|
IRR |
||||
|
ISBLANK |
||||
|
ISERR |
||||
|
ISERROR |
||||
|
ISEVEN |
||||
|
ISLOGICAL |
||||
|
ISNA |
||||
|
ISNONTEXT |
||||
|
ISNUMBER |
||||
|
ISODD |
||||
|
ISPMT |
||||
|
ISREF |
||||
|
ISTEXT |
||||
|
JIS |
||||
|
KURT |
||||
|
LARGE |
||||
|
LCM |
||||
|
LEFT |
||||
|
LEFTB |
||||
|
LEN |
||||
|
LENB |
||||
|
LINEST |
||||
|
LN |
||||
|
LOG |
||||
|
LOG10 |
||||
|
LOGEST |
||||
|
LOGINV |
||||
|
LOGNORMDIST |
||||
|
LOOKUP |
||||
|
LOWER |
||||
|
MATCH |
||||
|
MAX |
||||
|
MAXA |
||||
|
MDETERM |
||||
|
MDURATION |
||||
|
MEDIAN |
||||
|
MID |
||||
|
MIDB |
||||
|
MIN |
||||
|
MINA |
||||
|
MINUTE |
||||
|
MINVERSE |
||||
|
MIRR |
||||
|
MMULT |
||||
|
MOD |
||||
|
MODE |
||||
|
MONTH |
||||
|
MROUND |
||||
|
MULTINOMIAL |
||||
|
N |
||||
|
NA |
||||
|
NEGBINOMDIST |
||||
|
NETWORKDAYS |
||||
|
NOMINAL |
||||
|
NORMDIST |
||||
|
NORMINV |
||||
|
NORMSDIST |
||||
|
NORMSINV |
||||
|
NOT |
||||
|
NOW |
||||
|
NPER |
||||
|
NPV |
||||
|
OCT2BIN |
||||
|
OCT2DEC |
||||
|
OCT2HEX |
||||
|
ODD |
||||
|
ODDFPRICE |
||||
|
ODDFYIELD |
||||
|
ODDLPRICE |
||||
|
ODDLYIELD |
||||
|
OFFSET |
||||
|
OR |
||||
|
PEARSON |
||||
|
PERCENTILE |
||||
|
PERCENTRANK |
||||
|
PERMUT |
||||
|
PHONETIC |
||||
|
PI |
||||
|
PMT |
||||
|
POISSON |
||||
|
POWER |
||||
|
PPMT |
||||
|
PRICE |
||||
|
PRICEDISC |
||||
|
PRICEMAT |
||||
|
PROB |
||||
|
PRODUCT |
||||
|
PROPER |
||||
|
PV |
||||
|
QUARTILE |
||||
|
QUOTIENT |
||||
|
RADIANS |
||||
|
RAND |
||||
|
RANDBETWEEN |
||||
|
RANK |
||||
|
RATE |
||||
|
RECEIVED |
||||
|
REPLACE |
||||
|
REPLACEB |
||||
|
REPT |
||||
|
RIGHT |
||||
|
RIGHTB |
||||
|
ROMAN |
||||
|
ROUND |
||||
|
ROUNDDOWN |
||||
|
ROUNDUP |
||||
|
ROW |
||||
|
ROWS |
||||
|
RSQ |
||||
|
RTD |
||||
|
SEARCH |
||||
|
SEARCHB |
||||
|
SECOND |
||||
|
SERIESSUM |
||||
|
SIGN |
||||
|
SIN |
||||
|
SINH |
||||
|
SKEW |
||||
|
SLN |
||||
|
SLOPE |
||||
|
SMALL |
||||
|
SQRT |
||||
|
SQRTPI |
||||
|
STANDARDIZE |
||||
|
STDEV |
||||
|
STDEVA |
||||
|
STDEVP |
||||
|
STDEVPA |
||||
|
STEYX |
||||
|
SUBSTITUTE |
||||
|
SUBTOTAL |
||||
|
SUM |
||||
|
SUMIF |
||||
|
SUMIFS |
||||
|
SUMPRODUCT |
||||
|
SUMSQ |
||||
|
SUMX2MY2 |
||||
|
SUMX2PY2 |
||||
|
SUMXMY2 |
||||
|
SYD |
||||
|
T |
||||
|
TAN |
||||
|
TANH |
||||
|
TBILLEQ |
||||
|
TBILLPRICE |
||||
|
TBILLYIELD |
||||
|
TDIST |
||||
|
TEXT |
||||
|
TIME |
||||
|
TIMEVALUE |
||||
|
TINV |
||||
|
TODAY |
||||
|
TRANSPOSE |
||||
|
TREND |
||||
|
TRIM |
||||
|
TRIMMEAN |
||||
|
TRUE |
||||
|
TRUNC |
||||
|
TTEST |
||||
|
TYPE |
||||
|
UPPER |
||||
|
USDOLLAR |
||||
|
VALUE |
||||
|
VAR |
||||
|
VARA |
||||
|
VARP |
||||
|
VARPA |
||||
|
VDB |
||||
|
VERSION |
||||
|
VLOOKUP |
||||
|
WEEKDAY |
||||
|
WEEKNUM |
||||
|
WEIBULL |
||||
|
WORKDAY |
||||
|
XIRR |
||||
|
XNPV |
||||
|
YEAR |
||||
|
YEARFRAC |
||||
|
YIELD |
||||
|
YIELDDISC |
||||
|
YIELDMAT |
||||
|
ZTEST |
||||
@ -0,0 +1,192 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Cell |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** PHPExcel root directory */ |
||||
|
if (!defined('PHPEXCEL_ROOT')) { |
||||
|
/** |
||||
|
* @ignore |
||||
|
*/ |
||||
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
||||
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Cell_AdvancedValueBinder |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Cell |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder |
||||
|
{ |
||||
|
/** |
||||
|
* Bind value to a cell |
||||
|
* |
||||
|
* @param PHPExcel_Cell $cell Cell to bind value to |
||||
|
* @param mixed $value Value to bind in cell |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function bindValue(PHPExcel_Cell $cell, $value = null) |
||||
|
{ |
||||
|
// sanitize UTF-8 strings |
||||
|
if (is_string($value)) { |
||||
|
$value = PHPExcel_Shared_String::SanitizeUTF8($value); |
||||
|
} |
||||
|
|
||||
|
// Find out data type |
||||
|
$dataType = parent::dataTypeForValue($value); |
||||
|
|
||||
|
// Style logic - strings |
||||
|
if ($dataType === PHPExcel_Cell_DataType::TYPE_STRING && !$value instanceof PHPExcel_RichText) { |
||||
|
// Test for booleans using locale-setting |
||||
|
if ($value == PHPExcel_Calculation::getTRUE()) { |
||||
|
$cell->setValueExplicit( TRUE, PHPExcel_Cell_DataType::TYPE_BOOL); |
||||
|
return true; |
||||
|
} elseif($value == PHPExcel_Calculation::getFALSE()) { |
||||
|
$cell->setValueExplicit( FALSE, PHPExcel_Cell_DataType::TYPE_BOOL); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// Check for number in scientific format |
||||
|
if (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NUMBER.'$/', $value)) { |
||||
|
$cell->setValueExplicit( (float) $value, PHPExcel_Cell_DataType::TYPE_NUMERIC); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// Check for fraction |
||||
|
if (preg_match('/^([+-]?) *([0-9]*)\s?\/\s*([0-9]*)$/', $value, $matches)) { |
||||
|
// Convert value to number |
||||
|
$value = $matches[2] / $matches[3]; |
||||
|
if ($matches[1] == '-') $value = 0 - $value; |
||||
|
$cell->setValueExplicit( (float) $value, PHPExcel_Cell_DataType::TYPE_NUMERIC); |
||||
|
// Set style |
||||
|
$cell->getWorksheet()->getStyle( $cell->getCoordinate() ) |
||||
|
->getNumberFormat()->setFormatCode( '??/??' ); |
||||
|
return true; |
||||
|
} elseif (preg_match('/^([+-]?)([0-9]*) +([0-9]*)\s?\/\s*([0-9]*)$/', $value, $matches)) { |
||||
|
// Convert value to number |
||||
|
$value = $matches[2] + ($matches[3] / $matches[4]); |
||||
|
if ($matches[1] == '-') $value = 0 - $value; |
||||
|
$cell->setValueExplicit( (float) $value, PHPExcel_Cell_DataType::TYPE_NUMERIC); |
||||
|
// Set style |
||||
|
$cell->getWorksheet()->getStyle( $cell->getCoordinate() ) |
||||
|
->getNumberFormat()->setFormatCode( '# ??/??' ); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// Check for percentage |
||||
|
if (preg_match('/^\-?[0-9]*\.?[0-9]*\s?\%$/', $value)) { |
||||
|
// Convert value to number |
||||
|
$value = (float) str_replace('%', '', $value) / 100; |
||||
|
$cell->setValueExplicit( $value, PHPExcel_Cell_DataType::TYPE_NUMERIC); |
||||
|
// Set style |
||||
|
$cell->getWorksheet()->getStyle( $cell->getCoordinate() ) |
||||
|
->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00 ); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// Check for currency |
||||
|
$currencyCode = PHPExcel_Shared_String::getCurrencyCode(); |
||||
|
$decimalSeparator = PHPExcel_Shared_String::getDecimalSeparator(); |
||||
|
$thousandsSeparator = PHPExcel_Shared_String::getThousandsSeparator(); |
||||
|
if (preg_match('/^'.preg_quote($currencyCode).' *(\d{1,3}('.preg_quote($thousandsSeparator).'\d{3})*|(\d+))('.preg_quote($decimalSeparator).'\d{2})?$/', $value)) { |
||||
|
// Convert value to number |
||||
|
$value = (float) trim(str_replace(array($currencyCode, $thousandsSeparator, $decimalSeparator), array('', '', '.'), $value)); |
||||
|
$cell->setValueExplicit( $value, PHPExcel_Cell_DataType::TYPE_NUMERIC); |
||||
|
// Set style |
||||
|
$cell->getWorksheet()->getStyle( $cell->getCoordinate() ) |
||||
|
->getNumberFormat()->setFormatCode( |
||||
|
str_replace('$', $currencyCode, PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE ) |
||||
|
); |
||||
|
return true; |
||||
|
} elseif (preg_match('/^\$ *(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/', $value)) { |
||||
|
// Convert value to number |
||||
|
$value = (float) trim(str_replace(array('$',','), '', $value)); |
||||
|
$cell->setValueExplicit( $value, PHPExcel_Cell_DataType::TYPE_NUMERIC); |
||||
|
// Set style |
||||
|
$cell->getWorksheet()->getStyle( $cell->getCoordinate() ) |
||||
|
->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE ); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// Check for time without seconds e.g. '9:45', '09:45' |
||||
|
if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d$/', $value)) { |
||||
|
// Convert value to number |
||||
|
list($h, $m) = explode(':', $value); |
||||
|
$days = $h / 24 + $m / 1440; |
||||
|
$cell->setValueExplicit($days, PHPExcel_Cell_DataType::TYPE_NUMERIC); |
||||
|
// Set style |
||||
|
$cell->getWorksheet()->getStyle( $cell->getCoordinate() ) |
||||
|
->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3 ); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// Check for time with seconds '9:45:59', '09:45:59' |
||||
|
if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d:[0-5]\d$/', $value)) { |
||||
|
// Convert value to number |
||||
|
list($h, $m, $s) = explode(':', $value); |
||||
|
$days = $h / 24 + $m / 1440 + $s / 86400; |
||||
|
// Convert value to number |
||||
|
$cell->setValueExplicit($days, PHPExcel_Cell_DataType::TYPE_NUMERIC); |
||||
|
// Set style |
||||
|
$cell->getWorksheet()->getStyle( $cell->getCoordinate() ) |
||||
|
->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4 ); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// Check for datetime, e.g. '2008-12-31', '2008-12-31 15:59', '2008-12-31 15:59:10' |
||||
|
if (($d = PHPExcel_Shared_Date::stringToExcel($value)) !== false) { |
||||
|
// Convert value to number |
||||
|
$cell->setValueExplicit($d, PHPExcel_Cell_DataType::TYPE_NUMERIC); |
||||
|
// Determine style. Either there is a time part or not. Look for ':' |
||||
|
if (strpos($value, ':') !== false) { |
||||
|
$formatCode = 'yyyy-mm-dd h:mm'; |
||||
|
} else { |
||||
|
$formatCode = 'yyyy-mm-dd'; |
||||
|
} |
||||
|
$cell->getWorksheet()->getStyle( $cell->getCoordinate() ) |
||||
|
->getNumberFormat()->setFormatCode($formatCode); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// Check for newline character "\n" |
||||
|
if (strpos($value, "\n") !== FALSE) { |
||||
|
$value = PHPExcel_Shared_String::SanitizeUTF8($value); |
||||
|
$cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING); |
||||
|
// Set style |
||||
|
$cell->getWorksheet()->getStyle( $cell->getCoordinate() ) |
||||
|
->getAlignment()->setWrapText(TRUE); |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Not bound yet? Use parent... |
||||
|
return parent::bindValue($cell, $value); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,122 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Cell |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Cell_DataType |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Cell |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Cell_DataType |
||||
|
{ |
||||
|
/* Data types */ |
||||
|
const TYPE_STRING2 = 'str'; |
||||
|
const TYPE_STRING = 's'; |
||||
|
const TYPE_FORMULA = 'f'; |
||||
|
const TYPE_NUMERIC = 'n'; |
||||
|
const TYPE_BOOL = 'b'; |
||||
|
const TYPE_NULL = 'null'; |
||||
|
const TYPE_INLINE = 'inlineStr'; |
||||
|
const TYPE_ERROR = 'e'; |
||||
|
|
||||
|
/** |
||||
|
* List of error codes |
||||
|
* |
||||
|
* @var array |
||||
|
*/ |
||||
|
private static $_errorCodes = array( |
||||
|
'#NULL!' => 0, |
||||
|
'#DIV/0!' => 1, |
||||
|
'#VALUE!' => 2, |
||||
|
'#REF!' => 3, |
||||
|
'#NAME?' => 4, |
||||
|
'#NUM!' => 5, |
||||
|
'#N/A' => 6 |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Get list of error codes |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public static function getErrorCodes() { |
||||
|
return self::$_errorCodes; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* DataType for value |
||||
|
* |
||||
|
* @deprecated Replaced by PHPExcel_Cell_IValueBinder infrastructure, will be removed in version 1.8.0 |
||||
|
* @param mixed $pValue |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function dataTypeForValue($pValue = null) { |
||||
|
return PHPExcel_Cell_DefaultValueBinder::dataTypeForValue($pValue); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Check a string that it satisfies Excel requirements |
||||
|
* |
||||
|
* @param mixed Value to sanitize to an Excel string |
||||
|
* @return mixed Sanitized value |
||||
|
*/ |
||||
|
public static function checkString($pValue = null) |
||||
|
{ |
||||
|
if ($pValue instanceof PHPExcel_RichText) { |
||||
|
// TODO: Sanitize Rich-Text string (max. character count is 32,767) |
||||
|
return $pValue; |
||||
|
} |
||||
|
|
||||
|
// string must never be longer than 32,767 characters, truncate if necessary |
||||
|
$pValue = PHPExcel_Shared_String::Substring($pValue, 0, 32767); |
||||
|
|
||||
|
// we require that newline is represented as "\n" in core, not as "\r\n" or "\r" |
||||
|
$pValue = str_replace(array("\r\n", "\r"), "\n", $pValue); |
||||
|
|
||||
|
return $pValue; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Check a value that it is a valid error code |
||||
|
* |
||||
|
* @param mixed Value to sanitize to an Excel error code |
||||
|
* @return string Sanitized value |
||||
|
*/ |
||||
|
public static function checkErrorCode($pValue = null) |
||||
|
{ |
||||
|
$pValue = (string) $pValue; |
||||
|
|
||||
|
if ( !array_key_exists($pValue, self::$_errorCodes) ) { |
||||
|
$pValue = '#NULL!'; |
||||
|
} |
||||
|
|
||||
|
return $pValue; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,472 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Cell |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Cell_DataValidation |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Cell |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Cell_DataValidation |
||||
|
{ |
||||
|
/* Data validation types */ |
||||
|
const TYPE_NONE = 'none'; |
||||
|
const TYPE_CUSTOM = 'custom'; |
||||
|
const TYPE_DATE = 'date'; |
||||
|
const TYPE_DECIMAL = 'decimal'; |
||||
|
const TYPE_LIST = 'list'; |
||||
|
const TYPE_TEXTLENGTH = 'textLength'; |
||||
|
const TYPE_TIME = 'time'; |
||||
|
const TYPE_WHOLE = 'whole'; |
||||
|
|
||||
|
/* Data validation error styles */ |
||||
|
const STYLE_STOP = 'stop'; |
||||
|
const STYLE_WARNING = 'warning'; |
||||
|
const STYLE_INFORMATION = 'information'; |
||||
|
|
||||
|
/* Data validation operators */ |
||||
|
const OPERATOR_BETWEEN = 'between'; |
||||
|
const OPERATOR_EQUAL = 'equal'; |
||||
|
const OPERATOR_GREATERTHAN = 'greaterThan'; |
||||
|
const OPERATOR_GREATERTHANOREQUAL = 'greaterThanOrEqual'; |
||||
|
const OPERATOR_LESSTHAN = 'lessThan'; |
||||
|
const OPERATOR_LESSTHANOREQUAL = 'lessThanOrEqual'; |
||||
|
const OPERATOR_NOTBETWEEN = 'notBetween'; |
||||
|
const OPERATOR_NOTEQUAL = 'notEqual'; |
||||
|
|
||||
|
/** |
||||
|
* Formula 1 |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_formula1; |
||||
|
|
||||
|
/** |
||||
|
* Formula 2 |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_formula2; |
||||
|
|
||||
|
/** |
||||
|
* Type |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_type = PHPExcel_Cell_DataValidation::TYPE_NONE; |
||||
|
|
||||
|
/** |
||||
|
* Error style |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_errorStyle = PHPExcel_Cell_DataValidation::STYLE_STOP; |
||||
|
|
||||
|
/** |
||||
|
* Operator |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_operator; |
||||
|
|
||||
|
/** |
||||
|
* Allow Blank |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_allowBlank; |
||||
|
|
||||
|
/** |
||||
|
* Show DropDown |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_showDropDown; |
||||
|
|
||||
|
/** |
||||
|
* Show InputMessage |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_showInputMessage; |
||||
|
|
||||
|
/** |
||||
|
* Show ErrorMessage |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_showErrorMessage; |
||||
|
|
||||
|
/** |
||||
|
* Error title |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_errorTitle; |
||||
|
|
||||
|
/** |
||||
|
* Error |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_error; |
||||
|
|
||||
|
/** |
||||
|
* Prompt title |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_promptTitle; |
||||
|
|
||||
|
/** |
||||
|
* Prompt |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_prompt; |
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Cell_DataValidation |
||||
|
*/ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
// Initialise member variables |
||||
|
$this->_formula1 = ''; |
||||
|
$this->_formula2 = ''; |
||||
|
$this->_type = PHPExcel_Cell_DataValidation::TYPE_NONE; |
||||
|
$this->_errorStyle = PHPExcel_Cell_DataValidation::STYLE_STOP; |
||||
|
$this->_operator = ''; |
||||
|
$this->_allowBlank = FALSE; |
||||
|
$this->_showDropDown = FALSE; |
||||
|
$this->_showInputMessage = FALSE; |
||||
|
$this->_showErrorMessage = FALSE; |
||||
|
$this->_errorTitle = ''; |
||||
|
$this->_error = ''; |
||||
|
$this->_promptTitle = ''; |
||||
|
$this->_prompt = ''; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Formula 1 |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getFormula1() { |
||||
|
return $this->_formula1; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Formula 1 |
||||
|
* |
||||
|
* @param string $value |
||||
|
* @return PHPExcel_Cell_DataValidation |
||||
|
*/ |
||||
|
public function setFormula1($value = '') { |
||||
|
$this->_formula1 = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Formula 2 |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getFormula2() { |
||||
|
return $this->_formula2; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Formula 2 |
||||
|
* |
||||
|
* @param string $value |
||||
|
* @return PHPExcel_Cell_DataValidation |
||||
|
*/ |
||||
|
public function setFormula2($value = '') { |
||||
|
$this->_formula2 = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Type |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getType() { |
||||
|
return $this->_type; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Type |
||||
|
* |
||||
|
* @param string $value |
||||
|
* @return PHPExcel_Cell_DataValidation |
||||
|
*/ |
||||
|
public function setType($value = PHPExcel_Cell_DataValidation::TYPE_NONE) { |
||||
|
$this->_type = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Error style |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getErrorStyle() { |
||||
|
return $this->_errorStyle; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Error style |
||||
|
* |
||||
|
* @param string $value |
||||
|
* @return PHPExcel_Cell_DataValidation |
||||
|
*/ |
||||
|
public function setErrorStyle($value = PHPExcel_Cell_DataValidation::STYLE_STOP) { |
||||
|
$this->_errorStyle = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Operator |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getOperator() { |
||||
|
return $this->_operator; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Operator |
||||
|
* |
||||
|
* @param string $value |
||||
|
* @return PHPExcel_Cell_DataValidation |
||||
|
*/ |
||||
|
public function setOperator($value = '') { |
||||
|
$this->_operator = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Allow Blank |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getAllowBlank() { |
||||
|
return $this->_allowBlank; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Allow Blank |
||||
|
* |
||||
|
* @param boolean $value |
||||
|
* @return PHPExcel_Cell_DataValidation |
||||
|
*/ |
||||
|
public function setAllowBlank($value = false) { |
||||
|
$this->_allowBlank = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Show DropDown |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getShowDropDown() { |
||||
|
return $this->_showDropDown; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Show DropDown |
||||
|
* |
||||
|
* @param boolean $value |
||||
|
* @return PHPExcel_Cell_DataValidation |
||||
|
*/ |
||||
|
public function setShowDropDown($value = false) { |
||||
|
$this->_showDropDown = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Show InputMessage |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getShowInputMessage() { |
||||
|
return $this->_showInputMessage; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Show InputMessage |
||||
|
* |
||||
|
* @param boolean $value |
||||
|
* @return PHPExcel_Cell_DataValidation |
||||
|
*/ |
||||
|
public function setShowInputMessage($value = false) { |
||||
|
$this->_showInputMessage = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Show ErrorMessage |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getShowErrorMessage() { |
||||
|
return $this->_showErrorMessage; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Show ErrorMessage |
||||
|
* |
||||
|
* @param boolean $value |
||||
|
* @return PHPExcel_Cell_DataValidation |
||||
|
*/ |
||||
|
public function setShowErrorMessage($value = false) { |
||||
|
$this->_showErrorMessage = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Error title |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getErrorTitle() { |
||||
|
return $this->_errorTitle; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Error title |
||||
|
* |
||||
|
* @param string $value |
||||
|
* @return PHPExcel_Cell_DataValidation |
||||
|
*/ |
||||
|
public function setErrorTitle($value = '') { |
||||
|
$this->_errorTitle = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Error |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getError() { |
||||
|
return $this->_error; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Error |
||||
|
* |
||||
|
* @param string $value |
||||
|
* @return PHPExcel_Cell_DataValidation |
||||
|
*/ |
||||
|
public function setError($value = '') { |
||||
|
$this->_error = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Prompt title |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getPromptTitle() { |
||||
|
return $this->_promptTitle; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Prompt title |
||||
|
* |
||||
|
* @param string $value |
||||
|
* @return PHPExcel_Cell_DataValidation |
||||
|
*/ |
||||
|
public function setPromptTitle($value = '') { |
||||
|
$this->_promptTitle = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Prompt |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getPrompt() { |
||||
|
return $this->_prompt; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Prompt |
||||
|
* |
||||
|
* @param string $value |
||||
|
* @return PHPExcel_Cell_DataValidation |
||||
|
*/ |
||||
|
public function setPrompt($value = '') { |
||||
|
$this->_prompt = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get hash code |
||||
|
* |
||||
|
* @return string Hash code |
||||
|
*/ |
||||
|
public function getHashCode() { |
||||
|
return md5( |
||||
|
$this->_formula1 |
||||
|
. $this->_formula2 |
||||
|
. $this->_type = PHPExcel_Cell_DataValidation::TYPE_NONE |
||||
|
. $this->_errorStyle = PHPExcel_Cell_DataValidation::STYLE_STOP |
||||
|
. $this->_operator |
||||
|
. ($this->_allowBlank ? 't' : 'f') |
||||
|
. ($this->_showDropDown ? 't' : 'f') |
||||
|
. ($this->_showInputMessage ? 't' : 'f') |
||||
|
. ($this->_showErrorMessage ? 't' : 'f') |
||||
|
. $this->_errorTitle |
||||
|
. $this->_error |
||||
|
. $this->_promptTitle |
||||
|
. $this->_prompt |
||||
|
. __CLASS__ |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
||||
|
*/ |
||||
|
public function __clone() { |
||||
|
$vars = get_object_vars($this); |
||||
|
foreach ($vars as $key => $value) { |
||||
|
if (is_object($value)) { |
||||
|
$this->$key = clone $value; |
||||
|
} else { |
||||
|
$this->$key = $value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,106 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Cell |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** PHPExcel root directory */ |
||||
|
if (!defined('PHPEXCEL_ROOT')) { |
||||
|
/** |
||||
|
* @ignore |
||||
|
*/ |
||||
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
||||
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Cell_DefaultValueBinder |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Cell |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder |
||||
|
{ |
||||
|
/** |
||||
|
* Bind value to a cell |
||||
|
* |
||||
|
* @param PHPExcel_Cell $cell Cell to bind value to |
||||
|
* @param mixed $value Value to bind in cell |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function bindValue(PHPExcel_Cell $cell, $value = null) |
||||
|
{ |
||||
|
// sanitize UTF-8 strings |
||||
|
if (is_string($value)) { |
||||
|
$value = PHPExcel_Shared_String::SanitizeUTF8($value); |
||||
|
} |
||||
|
|
||||
|
// Set value explicit |
||||
|
$cell->setValueExplicit( $value, self::dataTypeForValue($value) ); |
||||
|
|
||||
|
// Done! |
||||
|
return TRUE; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* DataType for value |
||||
|
* |
||||
|
* @param mixed $pValue |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function dataTypeForValue($pValue = null) { |
||||
|
// Match the value against a few data types |
||||
|
if (is_null($pValue)) { |
||||
|
return PHPExcel_Cell_DataType::TYPE_NULL; |
||||
|
|
||||
|
} elseif ($pValue === '') { |
||||
|
return PHPExcel_Cell_DataType::TYPE_STRING; |
||||
|
|
||||
|
} elseif ($pValue instanceof PHPExcel_RichText) { |
||||
|
return PHPExcel_Cell_DataType::TYPE_INLINE; |
||||
|
|
||||
|
} elseif ($pValue{0} === '=' && strlen($pValue) > 1) { |
||||
|
return PHPExcel_Cell_DataType::TYPE_FORMULA; |
||||
|
|
||||
|
} elseif (is_bool($pValue)) { |
||||
|
return PHPExcel_Cell_DataType::TYPE_BOOL; |
||||
|
|
||||
|
} elseif (is_float($pValue) || is_int($pValue)) { |
||||
|
return PHPExcel_Cell_DataType::TYPE_NUMERIC; |
||||
|
|
||||
|
} elseif (preg_match('/^\-?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)$/', $pValue)) { |
||||
|
return PHPExcel_Cell_DataType::TYPE_NUMERIC; |
||||
|
|
||||
|
} elseif (is_string($pValue) && array_key_exists($pValue, PHPExcel_Cell_DataType::getErrorCodes())) { |
||||
|
return PHPExcel_Cell_DataType::TYPE_ERROR; |
||||
|
|
||||
|
} else { |
||||
|
return PHPExcel_Cell_DataType::TYPE_STRING; |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,126 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Cell |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Cell_Hyperlink |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Cell |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Cell_Hyperlink |
||||
|
{ |
||||
|
/** |
||||
|
* URL to link the cell to |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_url; |
||||
|
|
||||
|
/** |
||||
|
* Tooltip to display on the hyperlink |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_tooltip; |
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Cell_Hyperlink |
||||
|
* |
||||
|
* @param string $pUrl Url to link the cell to |
||||
|
* @param string $pTooltip Tooltip to display on the hyperlink |
||||
|
*/ |
||||
|
public function __construct($pUrl = '', $pTooltip = '') |
||||
|
{ |
||||
|
// Initialise member variables |
||||
|
$this->_url = $pUrl; |
||||
|
$this->_tooltip = $pTooltip; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get URL |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getUrl() { |
||||
|
return $this->_url; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set URL |
||||
|
* |
||||
|
* @param string $value |
||||
|
* @return PHPExcel_Cell_Hyperlink |
||||
|
*/ |
||||
|
public function setUrl($value = '') { |
||||
|
$this->_url = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get tooltip |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getTooltip() { |
||||
|
return $this->_tooltip; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set tooltip |
||||
|
* |
||||
|
* @param string $value |
||||
|
* @return PHPExcel_Cell_Hyperlink |
||||
|
*/ |
||||
|
public function setTooltip($value = '') { |
||||
|
$this->_tooltip = $value; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Is this hyperlink internal? (to another worksheet) |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function isInternal() { |
||||
|
return strpos($this->_url, 'sheet://') !== false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get hash code |
||||
|
* |
||||
|
* @return string Hash code |
||||
|
*/ |
||||
|
public function getHashCode() { |
||||
|
return md5( |
||||
|
$this->_url |
||||
|
. $this->_tooltip |
||||
|
. __CLASS__ |
||||
|
); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,46 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Cell |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Cell_IValueBinder |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Cell |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
interface PHPExcel_Cell_IValueBinder |
||||
|
{ |
||||
|
/** |
||||
|
* Bind value to a cell |
||||
|
* |
||||
|
* @param PHPExcel_Cell $cell Cell to bind value to |
||||
|
* @param mixed $value Value to bind in cell |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function bindValue(PHPExcel_Cell $cell, $value = NULL); |
||||
|
} |
||||
@ -0,0 +1,561 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/** |
||||
|
* Created by PhpStorm. |
||||
|
* User: Wiktor Trzonkowski |
||||
|
* Date: 6/17/14 |
||||
|
* Time: 12:11 PM |
||||
|
*/ |
||||
|
|
||||
|
class PHPExcel_Chart_Axis extends PHPExcel_Chart_Properties |
||||
|
{ |
||||
|
/** |
||||
|
* Axis Number |
||||
|
* |
||||
|
* @var array of mixed |
||||
|
*/ |
||||
|
private $axisNumber = array( |
||||
|
'format' => self::FORMAT_CODE_GENERAL, |
||||
|
'source_linked' => 1 |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Axis Options |
||||
|
* |
||||
|
* @var array of mixed |
||||
|
*/ |
||||
|
private $axisOptions = array( |
||||
|
'minimum' => null, |
||||
|
'maximum' => null, |
||||
|
'major_unit' => null, |
||||
|
'minor_unit' => null, |
||||
|
'orientation' => self::ORIENTATION_NORMAL, |
||||
|
'minor_tick_mark' => self::TICK_MARK_NONE, |
||||
|
'major_tick_mark' => self::TICK_MARK_NONE, |
||||
|
'axis_labels' => self::AXIS_LABELS_NEXT_TO, |
||||
|
'horizontal_crosses' => self::HORIZONTAL_CROSSES_AUTOZERO, |
||||
|
'horizontal_crosses_value' => null |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Fill Properties |
||||
|
* |
||||
|
* @var array of mixed |
||||
|
*/ |
||||
|
private $fillProperties = array( |
||||
|
'type' => self::EXCEL_COLOR_TYPE_ARGB, |
||||
|
'value' => null, |
||||
|
'alpha' => 0 |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Line Properties |
||||
|
* |
||||
|
* @var array of mixed |
||||
|
*/ |
||||
|
private $lineProperties = array( |
||||
|
'type' => self::EXCEL_COLOR_TYPE_ARGB, |
||||
|
'value' => null, |
||||
|
'alpha' => 0 |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Line Style Properties |
||||
|
* |
||||
|
* @var array of mixed |
||||
|
*/ |
||||
|
private $lineStyleProperties = array( |
||||
|
'width' => '9525', |
||||
|
'compound' => self::LINE_STYLE_COMPOUND_SIMPLE, |
||||
|
'dash' => self::LINE_STYLE_DASH_SOLID, |
||||
|
'cap' => self::LINE_STYLE_CAP_FLAT, |
||||
|
'join' => self::LINE_STYLE_JOIN_BEVEL, |
||||
|
'arrow' => array( |
||||
|
'head' => array( |
||||
|
'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW, |
||||
|
'size' => self::LINE_STYLE_ARROW_SIZE_5 |
||||
|
), |
||||
|
'end' => array( |
||||
|
'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW, |
||||
|
'size' => self::LINE_STYLE_ARROW_SIZE_8 |
||||
|
), |
||||
|
) |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Shadow Properties |
||||
|
* |
||||
|
* @var array of mixed |
||||
|
*/ |
||||
|
private $shadowProperties = array( |
||||
|
'presets' => self::SHADOW_PRESETS_NOSHADOW, |
||||
|
'effect' => null, |
||||
|
'color' => array( |
||||
|
'type' => self::EXCEL_COLOR_TYPE_STANDARD, |
||||
|
'value' => 'black', |
||||
|
'alpha' => 40, |
||||
|
), |
||||
|
'size' => array( |
||||
|
'sx' => null, |
||||
|
'sy' => null, |
||||
|
'kx' => null |
||||
|
), |
||||
|
'blur' => null, |
||||
|
'direction' => null, |
||||
|
'distance' => null, |
||||
|
'algn' => null, |
||||
|
'rotWithShape' => null |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Glow Properties |
||||
|
* |
||||
|
* @var array of mixed |
||||
|
*/ |
||||
|
private $glowProperties = array( |
||||
|
'size' => null, |
||||
|
'color' => array( |
||||
|
'type' => self::EXCEL_COLOR_TYPE_STANDARD, |
||||
|
'value' => 'black', |
||||
|
'alpha' => 40 |
||||
|
) |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Soft Edge Properties |
||||
|
* |
||||
|
* @var array of mixed |
||||
|
*/ |
||||
|
private $softEdges = array( |
||||
|
'size' => null |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Get Series Data Type |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function setAxisNumberProperties($format_code) |
||||
|
{ |
||||
|
$this->axisNumber['format'] = (string) $format_code; |
||||
|
$this->axisNumber['source_linked'] = 0; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Axis Number Format Data Type |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getAxisNumberFormat() |
||||
|
{ |
||||
|
return $this->axisNumber['format']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Axis Number Source Linked |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getAxisNumberSourceLinked() |
||||
|
{ |
||||
|
return (string) $this->axisNumber['source_linked']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Axis Options Properties |
||||
|
* |
||||
|
* @param string $axis_labels |
||||
|
* @param string $horizontal_crosses_value |
||||
|
* @param string $horizontal_crosses |
||||
|
* @param string $axis_orientation |
||||
|
* @param string $major_tmt |
||||
|
* @param string $minor_tmt |
||||
|
* @param string $minimum |
||||
|
* @param string $maximum |
||||
|
* @param string $major_unit |
||||
|
* @param string $minor_unit |
||||
|
* |
||||
|
*/ |
||||
|
public function setAxisOptionsProperties($axis_labels, $horizontal_crosses_value = null, $horizontal_crosses = null, $axis_orientation = null, $major_tmt = null, $minor_tmt = null, $minimum = null, $maximum = null, $major_unit = null, $minor_unit = null) |
||||
|
{ |
||||
|
$this->axisOptions['axis_labels'] = (string) $axis_labels; |
||||
|
($horizontal_crosses_value !== null) ? $this->axisOptions['horizontal_crosses_value'] = (string) $horizontal_crosses_value : null; |
||||
|
($horizontal_crosses !== null) ? $this->axisOptions['horizontal_crosses'] = (string) $horizontal_crosses : null; |
||||
|
($axis_orientation !== null) ? $this->axisOptions['orientation'] = (string) $axis_orientation : null; |
||||
|
($major_tmt !== null) ? $this->axisOptions['major_tick_mark'] = (string) $major_tmt : null; |
||||
|
($minor_tmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minor_tmt : null; |
||||
|
($minor_tmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minor_tmt : null; |
||||
|
($minimum !== null) ? $this->axisOptions['minimum'] = (string) $minimum : null; |
||||
|
($maximum !== null) ? $this->axisOptions['maximum'] = (string) $maximum : null; |
||||
|
($major_unit !== null) ? $this->axisOptions['major_unit'] = (string) $major_unit : null; |
||||
|
($minor_unit !== null) ? $this->axisOptions['minor_unit'] = (string) $minor_unit : null; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Axis Options Property |
||||
|
* |
||||
|
* @param string $property |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getAxisOptionsProperty($property) |
||||
|
{ |
||||
|
return $this->axisOptions[$property]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Axis Orientation Property |
||||
|
* |
||||
|
* @param string $orientation |
||||
|
* |
||||
|
*/ |
||||
|
public function setAxisOrientation($orientation) |
||||
|
{ |
||||
|
$this->orientation = (string) $orientation; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Fill Property |
||||
|
* |
||||
|
* @param string $color |
||||
|
* @param int $alpha |
||||
|
* @param string $type |
||||
|
* |
||||
|
*/ |
||||
|
public function setFillParameters($color, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_ARGB) |
||||
|
{ |
||||
|
$this->fillProperties = $this->setColorProperties($color, $alpha, $type); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Line Property |
||||
|
* |
||||
|
* @param string $color |
||||
|
* @param int $alpha |
||||
|
* @param string $type |
||||
|
* |
||||
|
*/ |
||||
|
public function setLineParameters($color, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_ARGB) |
||||
|
{ |
||||
|
$this->lineProperties = $this->setColorProperties($color, $alpha, $type); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Fill Property |
||||
|
* |
||||
|
* @param string $property |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getFillProperty($property) |
||||
|
{ |
||||
|
return $this->fillProperties[$property]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Line Property |
||||
|
* |
||||
|
* @param string $property |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getLineProperty($property) |
||||
|
{ |
||||
|
return $this->lineProperties[$property]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Line Style Properties |
||||
|
* |
||||
|
* @param float $line_width |
||||
|
* @param string $compound_type |
||||
|
* @param string $dash_type |
||||
|
* @param string $cap_type |
||||
|
* @param string $join_type |
||||
|
* @param string $head_arrow_type |
||||
|
* @param string $head_arrow_size |
||||
|
* @param string $end_arrow_type |
||||
|
* @param string $end_arrow_size |
||||
|
* |
||||
|
*/ |
||||
|
public function setLineStyleProperties($line_width = null, $compound_type = null, $dash_type = null, $cap_type = null, $join_type = null, $head_arrow_type = null, $head_arrow_size = null, $end_arrow_type = null, $end_arrow_size = null) |
||||
|
{ |
||||
|
(!is_null($line_width)) ? $this->lineStyleProperties['width'] = $this->getExcelPointsWidth((float) $line_width) : null; |
||||
|
(!is_null($compound_type)) ? $this->lineStyleProperties['compound'] = (string) $compound_type : null; |
||||
|
(!is_null($dash_type)) ? $this->lineStyleProperties['dash'] = (string) $dash_type : null; |
||||
|
(!is_null($cap_type)) ? $this->lineStyleProperties['cap'] = (string) $cap_type : null; |
||||
|
(!is_null($join_type)) ? $this->lineStyleProperties['join'] = (string) $join_type : null; |
||||
|
(!is_null($head_arrow_type)) ? $this->lineStyleProperties['arrow']['head']['type'] = (string) $head_arrow_type : null; |
||||
|
(!is_null($head_arrow_size)) ? $this->lineStyleProperties['arrow']['head']['size'] = (string) $head_arrow_size : null; |
||||
|
(!is_null($end_arrow_type)) ? $this->lineStyleProperties['arrow']['end']['type'] = (string) $end_arrow_type : null; |
||||
|
(!is_null($end_arrow_size)) ? $this->lineStyleProperties['arrow']['end']['size'] = (string) $end_arrow_size : null; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Line Style Property |
||||
|
* |
||||
|
* @param array|string $elements |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getLineStyleProperty($elements) |
||||
|
{ |
||||
|
return $this->getArrayElementsValue($this->lineStyleProperties, $elements); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Line Style Arrow Excel Width |
||||
|
* |
||||
|
* @param string $arrow |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getLineStyleArrowWidth($arrow) |
||||
|
{ |
||||
|
return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrow]['size'], 'w'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Line Style Arrow Excel Length |
||||
|
* |
||||
|
* @param string $arrow |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getLineStyleArrowLength($arrow) |
||||
|
{ |
||||
|
return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrow]['size'], 'len'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Shadow Properties |
||||
|
* |
||||
|
* @param int $shadow_presets |
||||
|
* @param string $sh_color_value |
||||
|
* @param string $sh_color_type |
||||
|
* @param string $sh_color_alpha |
||||
|
* @param float $sh_blur |
||||
|
* @param int $sh_angle |
||||
|
* @param float $sh_distance |
||||
|
* |
||||
|
*/ |
||||
|
public function setShadowProperties($sh_presets, $sh_color_value = null, $sh_color_type = null, $sh_color_alpha = null, $sh_blur = null, $sh_angle = null, $sh_distance = null) |
||||
|
{ |
||||
|
$this->setShadowPresetsProperties((int) $sh_presets) |
||||
|
->setShadowColor( |
||||
|
is_null($sh_color_value) ? $this->shadowProperties['color']['value'] : $sh_color_value, |
||||
|
is_null($sh_color_alpha) ? (int) $this->shadowProperties['color']['alpha'] : $sh_color_alpha, |
||||
|
is_null($sh_color_type) ? $this->shadowProperties['color']['type'] : $sh_color_type |
||||
|
) |
||||
|
->setShadowBlur($sh_blur) |
||||
|
->setShadowAngle($sh_angle) |
||||
|
->setShadowDistance($sh_distance); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Shadow Color |
||||
|
* |
||||
|
* @param int $shadow_presets |
||||
|
* |
||||
|
* @return PHPExcel_Chart_Axis |
||||
|
*/ |
||||
|
private function setShadowPresetsProperties($shadow_presets) |
||||
|
{ |
||||
|
$this->shadowProperties['presets'] = $shadow_presets; |
||||
|
$this->setShadowProperiesMapValues($this->getShadowPresetsMap($shadow_presets)); |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Shadow Properties from Maped Values |
||||
|
* |
||||
|
* @param array $properties_map |
||||
|
* @param * $reference |
||||
|
* |
||||
|
* @return PHPExcel_Chart_Axis |
||||
|
*/ |
||||
|
private function setShadowProperiesMapValues(array $properties_map, &$reference = null) |
||||
|
{ |
||||
|
$base_reference = $reference; |
||||
|
foreach ($properties_map as $property_key => $property_val) { |
||||
|
if (is_array($property_val)) { |
||||
|
if ($reference === null) { |
||||
|
$reference = & $this->shadowProperties[$property_key]; |
||||
|
} else { |
||||
|
$reference = & $reference[$property_key]; |
||||
|
} |
||||
|
$this->setShadowProperiesMapValues($property_val, $reference); |
||||
|
} else { |
||||
|
if ($base_reference === null) { |
||||
|
$this->shadowProperties[$property_key] = $property_val; |
||||
|
} else { |
||||
|
$reference[$property_key] = $property_val; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Shadow Color |
||||
|
* |
||||
|
* @param string $color |
||||
|
* @param int $alpha |
||||
|
* @param string $type |
||||
|
* |
||||
|
* @return PHPExcel_Chart_Axis |
||||
|
*/ |
||||
|
private function setShadowColor($color, $alpha, $type) |
||||
|
{ |
||||
|
$this->shadowProperties['color'] = $this->setColorProperties($color, $alpha, $type); |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Shadow Blur |
||||
|
* |
||||
|
* @param float $blur |
||||
|
* |
||||
|
* @return PHPExcel_Chart_Axis |
||||
|
*/ |
||||
|
private function setShadowBlur($blur) |
||||
|
{ |
||||
|
if ($blur !== null) { |
||||
|
$this->shadowProperties['blur'] = (string) $this->getExcelPointsWidth($blur); |
||||
|
} |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Shadow Angle |
||||
|
* |
||||
|
* @param int $angle |
||||
|
* |
||||
|
* @return PHPExcel_Chart_Axis |
||||
|
*/ |
||||
|
private function setShadowAngle($angle) |
||||
|
{ |
||||
|
if ($angle !== null) { |
||||
|
$this->shadowProperties['direction'] = (string) $this->getExcelPointsAngle($angle); |
||||
|
} |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Shadow Distance |
||||
|
* |
||||
|
* @param float $distance |
||||
|
* |
||||
|
* @return PHPExcel_Chart_Axis |
||||
|
*/ |
||||
|
private function setShadowDistance($distance) |
||||
|
{ |
||||
|
if ($distance !== null) { |
||||
|
$this->shadowProperties['distance'] = (string) $this->getExcelPointsWidth($distance); |
||||
|
} |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Glow Property |
||||
|
* |
||||
|
* @param float $size |
||||
|
* @param string $color_value |
||||
|
* @param int $color_alpha |
||||
|
* @param string $color_type |
||||
|
*/ |
||||
|
public function getShadowProperty($elements) |
||||
|
{ |
||||
|
return $this->getArrayElementsValue($this->shadowProperties, $elements); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Glow Properties |
||||
|
* |
||||
|
* @param float $size |
||||
|
* @param string $color_value |
||||
|
* @param int $color_alpha |
||||
|
* @param string $color_type |
||||
|
*/ |
||||
|
public function setGlowProperties($size, $color_value = null, $color_alpha = null, $color_type = null) |
||||
|
{ |
||||
|
$this->setGlowSize($size) |
||||
|
->setGlowColor( |
||||
|
is_null($color_value) ? $this->glowProperties['color']['value'] : $color_value, |
||||
|
is_null($color_alpha) ? (int) $this->glowProperties['color']['alpha'] : $color_alpha, |
||||
|
is_null($color_type) ? $this->glowProperties['color']['type'] : $color_type |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Glow Property |
||||
|
* |
||||
|
* @param array|string $property |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getGlowProperty($property) |
||||
|
{ |
||||
|
return $this->getArrayElementsValue($this->glowProperties, $property); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Glow Color |
||||
|
* |
||||
|
* @param float $size |
||||
|
* |
||||
|
* @return PHPExcel_Chart_Axis |
||||
|
*/ |
||||
|
private function setGlowSize($size) |
||||
|
{ |
||||
|
if (!is_null($size)) { |
||||
|
$this->glowProperties['size'] = $this->getExcelPointsWidth($size); |
||||
|
} |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Glow Color |
||||
|
* |
||||
|
* @param string $color |
||||
|
* @param int $alpha |
||||
|
* @param string $type |
||||
|
* |
||||
|
* @return PHPExcel_Chart_Axis |
||||
|
*/ |
||||
|
private function setGlowColor($color, $alpha, $type) |
||||
|
{ |
||||
|
$this->glowProperties['color'] = $this->setColorProperties($color, $alpha, $type); |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Soft Edges Size |
||||
|
* |
||||
|
* @param float $size |
||||
|
*/ |
||||
|
public function setSoftEdges($size) |
||||
|
{ |
||||
|
if (!is_null($size)) { |
||||
|
$softEdges['size'] = (string) $this->getExcelPointsWidth($size); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Soft Edges Size |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getSoftEdgesSize() |
||||
|
{ |
||||
|
return $this->softEdges['size']; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,354 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Chart_DataSeries |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Chart_DataSeries |
||||
|
{ |
||||
|
|
||||
|
const TYPE_BARCHART = 'barChart'; |
||||
|
const TYPE_BARCHART_3D = 'bar3DChart'; |
||||
|
const TYPE_LINECHART = 'lineChart'; |
||||
|
const TYPE_LINECHART_3D = 'line3DChart'; |
||||
|
const TYPE_AREACHART = 'areaChart'; |
||||
|
const TYPE_AREACHART_3D = 'area3DChart'; |
||||
|
const TYPE_PIECHART = 'pieChart'; |
||||
|
const TYPE_PIECHART_3D = 'pie3DChart'; |
||||
|
const TYPE_DOUGHTNUTCHART = 'doughnutChart'; |
||||
|
const TYPE_DONUTCHART = self::TYPE_DOUGHTNUTCHART; // Synonym |
||||
|
const TYPE_SCATTERCHART = 'scatterChart'; |
||||
|
const TYPE_SURFACECHART = 'surfaceChart'; |
||||
|
const TYPE_SURFACECHART_3D = 'surface3DChart'; |
||||
|
const TYPE_RADARCHART = 'radarChart'; |
||||
|
const TYPE_BUBBLECHART = 'bubbleChart'; |
||||
|
const TYPE_STOCKCHART = 'stockChart'; |
||||
|
|
||||
|
const GROUPING_CLUSTERED = 'clustered'; |
||||
|
const GROUPING_STACKED = 'stacked'; |
||||
|
const GROUPING_PERCENT_STACKED = 'percentStacked'; |
||||
|
const GROUPING_STANDARD = 'standard'; |
||||
|
|
||||
|
const DIRECTION_BAR = 'bar'; |
||||
|
const DIRECTION_HORIZONTAL = self::DIRECTION_BAR; |
||||
|
const DIRECTION_COL = 'col'; |
||||
|
const DIRECTION_COLUMN = self::DIRECTION_COL; |
||||
|
const DIRECTION_VERTICAL = self::DIRECTION_COL; |
||||
|
|
||||
|
const STYLE_LINEMARKER = 'lineMarker'; |
||||
|
const STYLE_SMOOTHMARKER = 'smoothMarker'; |
||||
|
const STYLE_MARKER = 'marker'; |
||||
|
const STYLE_FILLED = 'filled'; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Series Plot Type |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_plotType = null; |
||||
|
|
||||
|
/** |
||||
|
* Plot Grouping Type |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_plotGrouping = null; |
||||
|
|
||||
|
/** |
||||
|
* Plot Direction |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_plotDirection = null; |
||||
|
|
||||
|
/** |
||||
|
* Plot Style |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_plotStyle = null; |
||||
|
|
||||
|
/** |
||||
|
* Order of plots in Series |
||||
|
* |
||||
|
* @var array of integer |
||||
|
*/ |
||||
|
private $_plotOrder = array(); |
||||
|
|
||||
|
/** |
||||
|
* Plot Label |
||||
|
* |
||||
|
* @var array of PHPExcel_Chart_DataSeriesValues |
||||
|
*/ |
||||
|
private $_plotLabel = array(); |
||||
|
|
||||
|
/** |
||||
|
* Plot Category |
||||
|
* |
||||
|
* @var array of PHPExcel_Chart_DataSeriesValues |
||||
|
*/ |
||||
|
private $_plotCategory = array(); |
||||
|
|
||||
|
/** |
||||
|
* Smooth Line |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_smoothLine = null; |
||||
|
|
||||
|
/** |
||||
|
* Plot Values |
||||
|
* |
||||
|
* @var array of PHPExcel_Chart_DataSeriesValues |
||||
|
*/ |
||||
|
private $_plotValues = array(); |
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Chart_DataSeries |
||||
|
*/ |
||||
|
public function __construct($plotType = null, $plotGrouping = null, $plotOrder = array(), $plotLabel = array(), $plotCategory = array(), $plotValues = array(), $smoothLine = null, $plotStyle = null) |
||||
|
{ |
||||
|
$this->_plotType = $plotType; |
||||
|
$this->_plotGrouping = $plotGrouping; |
||||
|
$this->_plotOrder = $plotOrder; |
||||
|
$keys = array_keys($plotValues); |
||||
|
$this->_plotValues = $plotValues; |
||||
|
if ((count($plotLabel) == 0) || (is_null($plotLabel[$keys[0]]))) { |
||||
|
$plotLabel[$keys[0]] = new PHPExcel_Chart_DataSeriesValues(); |
||||
|
} |
||||
|
|
||||
|
$this->_plotLabel = $plotLabel; |
||||
|
if ((count($plotCategory) == 0) || (is_null($plotCategory[$keys[0]]))) { |
||||
|
$plotCategory[$keys[0]] = new PHPExcel_Chart_DataSeriesValues(); |
||||
|
} |
||||
|
$this->_plotCategory = $plotCategory; |
||||
|
$this->_smoothLine = $smoothLine; |
||||
|
$this->_plotStyle = $plotStyle; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Plot Type |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getPlotType() { |
||||
|
return $this->_plotType; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Plot Type |
||||
|
* |
||||
|
* @param string $plotType |
||||
|
*/ |
||||
|
public function setPlotType($plotType = '') { |
||||
|
$this->_plotType = $plotType; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Plot Grouping Type |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getPlotGrouping() { |
||||
|
return $this->_plotGrouping; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Plot Grouping Type |
||||
|
* |
||||
|
* @param string $groupingType |
||||
|
*/ |
||||
|
public function setPlotGrouping($groupingType = null) { |
||||
|
$this->_plotGrouping = $groupingType; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Plot Direction |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getPlotDirection() { |
||||
|
return $this->_plotDirection; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Plot Direction |
||||
|
* |
||||
|
* @param string $plotDirection |
||||
|
*/ |
||||
|
public function setPlotDirection($plotDirection = null) { |
||||
|
$this->_plotDirection = $plotDirection; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Plot Order |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getPlotOrder() { |
||||
|
return $this->_plotOrder; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Plot Labels |
||||
|
* |
||||
|
* @return array of PHPExcel_Chart_DataSeriesValues |
||||
|
*/ |
||||
|
public function getPlotLabels() { |
||||
|
return $this->_plotLabel; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Plot Label by Index |
||||
|
* |
||||
|
* @return PHPExcel_Chart_DataSeriesValues |
||||
|
*/ |
||||
|
public function getPlotLabelByIndex($index) { |
||||
|
$keys = array_keys($this->_plotLabel); |
||||
|
if (in_array($index,$keys)) { |
||||
|
return $this->_plotLabel[$index]; |
||||
|
} elseif(isset($keys[$index])) { |
||||
|
return $this->_plotLabel[$keys[$index]]; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Plot Categories |
||||
|
* |
||||
|
* @return array of PHPExcel_Chart_DataSeriesValues |
||||
|
*/ |
||||
|
public function getPlotCategories() { |
||||
|
return $this->_plotCategory; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Plot Category by Index |
||||
|
* |
||||
|
* @return PHPExcel_Chart_DataSeriesValues |
||||
|
*/ |
||||
|
public function getPlotCategoryByIndex($index) { |
||||
|
$keys = array_keys($this->_plotCategory); |
||||
|
if (in_array($index,$keys)) { |
||||
|
return $this->_plotCategory[$index]; |
||||
|
} elseif(isset($keys[$index])) { |
||||
|
return $this->_plotCategory[$keys[$index]]; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Plot Style |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getPlotStyle() { |
||||
|
return $this->_plotStyle; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Plot Style |
||||
|
* |
||||
|
* @param string $plotStyle |
||||
|
*/ |
||||
|
public function setPlotStyle($plotStyle = null) { |
||||
|
$this->_plotStyle = $plotStyle; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Plot Values |
||||
|
* |
||||
|
* @return array of PHPExcel_Chart_DataSeriesValues |
||||
|
*/ |
||||
|
public function getPlotValues() { |
||||
|
return $this->_plotValues; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Plot Values by Index |
||||
|
* |
||||
|
* @return PHPExcel_Chart_DataSeriesValues |
||||
|
*/ |
||||
|
public function getPlotValuesByIndex($index) { |
||||
|
$keys = array_keys($this->_plotValues); |
||||
|
if (in_array($index,$keys)) { |
||||
|
return $this->_plotValues[$index]; |
||||
|
} elseif(isset($keys[$index])) { |
||||
|
return $this->_plotValues[$keys[$index]]; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Number of Plot Series |
||||
|
* |
||||
|
* @return integer |
||||
|
*/ |
||||
|
public function getPlotSeriesCount() { |
||||
|
return count($this->_plotValues); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Smooth Line |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getSmoothLine() { |
||||
|
return $this->_smoothLine; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Smooth Line |
||||
|
* |
||||
|
* @param boolean $smoothLine |
||||
|
*/ |
||||
|
public function setSmoothLine($smoothLine = TRUE) { |
||||
|
$this->_smoothLine = $smoothLine; |
||||
|
} |
||||
|
|
||||
|
public function refresh(PHPExcel_Worksheet $worksheet) { |
||||
|
foreach($this->_plotValues as $plotValues) { |
||||
|
if ($plotValues !== NULL) |
||||
|
$plotValues->refresh($worksheet, TRUE); |
||||
|
} |
||||
|
foreach($this->_plotLabel as $plotValues) { |
||||
|
if ($plotValues !== NULL) |
||||
|
$plotValues->refresh($worksheet, TRUE); |
||||
|
} |
||||
|
foreach($this->_plotCategory as $plotValues) { |
||||
|
if ($plotValues !== NULL) |
||||
|
$plotValues->refresh($worksheet, FALSE); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,327 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Chart_DataSeriesValues |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Chart_DataSeriesValues |
||||
|
{ |
||||
|
|
||||
|
const DATASERIES_TYPE_STRING = 'String'; |
||||
|
const DATASERIES_TYPE_NUMBER = 'Number'; |
||||
|
|
||||
|
private static $_dataTypeValues = array( |
||||
|
self::DATASERIES_TYPE_STRING, |
||||
|
self::DATASERIES_TYPE_NUMBER, |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Series Data Type |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_dataType = null; |
||||
|
|
||||
|
/** |
||||
|
* Series Data Source |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_dataSource = null; |
||||
|
|
||||
|
/** |
||||
|
* Format Code |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_formatCode = null; |
||||
|
|
||||
|
/** |
||||
|
* Series Point Marker |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_marker = null; |
||||
|
|
||||
|
/** |
||||
|
* Point Count (The number of datapoints in the dataseries) |
||||
|
* |
||||
|
* @var integer |
||||
|
*/ |
||||
|
private $_pointCount = 0; |
||||
|
|
||||
|
/** |
||||
|
* Data Values |
||||
|
* |
||||
|
* @var array of mixed |
||||
|
*/ |
||||
|
private $_dataValues = array(); |
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Chart_DataSeriesValues object |
||||
|
*/ |
||||
|
public function __construct($dataType = self::DATASERIES_TYPE_NUMBER, $dataSource = null, $formatCode = null, $pointCount = 0, $dataValues = array(), $marker = null) |
||||
|
{ |
||||
|
$this->setDataType($dataType); |
||||
|
$this->_dataSource = $dataSource; |
||||
|
$this->_formatCode = $formatCode; |
||||
|
$this->_pointCount = $pointCount; |
||||
|
$this->_dataValues = $dataValues; |
||||
|
$this->_marker = $marker; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Series Data Type |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getDataType() { |
||||
|
return $this->_dataType; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Series Data Type |
||||
|
* |
||||
|
* @param string $dataType Datatype of this data series |
||||
|
* Typical values are: |
||||
|
* PHPExcel_Chart_DataSeriesValues::DATASERIES_TYPE_STRING |
||||
|
* Normally used for axis point values |
||||
|
* PHPExcel_Chart_DataSeriesValues::DATASERIES_TYPE_NUMBER |
||||
|
* Normally used for chart data values |
||||
|
* @return PHPExcel_Chart_DataSeriesValues |
||||
|
*/ |
||||
|
public function setDataType($dataType = self::DATASERIES_TYPE_NUMBER) { |
||||
|
if (!in_array($dataType, self::$_dataTypeValues)) { |
||||
|
throw new PHPExcel_Chart_Exception('Invalid datatype for chart data series values'); |
||||
|
} |
||||
|
$this->_dataType = $dataType; |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Series Data Source (formula) |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getDataSource() { |
||||
|
return $this->_dataSource; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Series Data Source (formula) |
||||
|
* |
||||
|
* @param string $dataSource |
||||
|
* @return PHPExcel_Chart_DataSeriesValues |
||||
|
*/ |
||||
|
public function setDataSource($dataSource = null, $refreshDataValues = true) { |
||||
|
$this->_dataSource = $dataSource; |
||||
|
|
||||
|
if ($refreshDataValues) { |
||||
|
// TO DO |
||||
|
} |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Point Marker |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getPointMarker() { |
||||
|
return $this->_marker; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Point Marker |
||||
|
* |
||||
|
* @param string $marker |
||||
|
* @return PHPExcel_Chart_DataSeriesValues |
||||
|
*/ |
||||
|
public function setPointMarker($marker = null) { |
||||
|
$this->_marker = $marker; |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Series Format Code |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getFormatCode() { |
||||
|
return $this->_formatCode; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Series Format Code |
||||
|
* |
||||
|
* @param string $formatCode |
||||
|
* @return PHPExcel_Chart_DataSeriesValues |
||||
|
*/ |
||||
|
public function setFormatCode($formatCode = null) { |
||||
|
$this->_formatCode = $formatCode; |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Series Point Count |
||||
|
* |
||||
|
* @return integer |
||||
|
*/ |
||||
|
public function getPointCount() { |
||||
|
return $this->_pointCount; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Identify if the Data Series is a multi-level or a simple series |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function isMultiLevelSeries() { |
||||
|
if (count($this->_dataValues) > 0) { |
||||
|
return is_array($this->_dataValues[0]); |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Return the level count of a multi-level Data Series |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function multiLevelCount() { |
||||
|
$levelCount = 0; |
||||
|
foreach($this->_dataValues as $dataValueSet) { |
||||
|
$levelCount = max($levelCount,count($dataValueSet)); |
||||
|
} |
||||
|
return $levelCount; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Series Data Values |
||||
|
* |
||||
|
* @return array of mixed |
||||
|
*/ |
||||
|
public function getDataValues() { |
||||
|
return $this->_dataValues; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the first Series Data value |
||||
|
* |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function getDataValue() { |
||||
|
$count = count($this->_dataValues); |
||||
|
if ($count == 0) { |
||||
|
return null; |
||||
|
} elseif ($count == 1) { |
||||
|
return $this->_dataValues[0]; |
||||
|
} |
||||
|
return $this->_dataValues; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Series Data Values |
||||
|
* |
||||
|
* @param array $dataValues |
||||
|
* @param boolean $refreshDataSource |
||||
|
* TRUE - refresh the value of _dataSource based on the values of $dataValues |
||||
|
* FALSE - don't change the value of _dataSource |
||||
|
* @return PHPExcel_Chart_DataSeriesValues |
||||
|
*/ |
||||
|
public function setDataValues($dataValues = array(), $refreshDataSource = TRUE) { |
||||
|
$this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($dataValues); |
||||
|
$this->_pointCount = count($dataValues); |
||||
|
|
||||
|
if ($refreshDataSource) { |
||||
|
// TO DO |
||||
|
} |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
private function _stripNulls($var) { |
||||
|
return $var !== NULL; |
||||
|
} |
||||
|
|
||||
|
public function refresh(PHPExcel_Worksheet $worksheet, $flatten = TRUE) { |
||||
|
if ($this->_dataSource !== NULL) { |
||||
|
$calcEngine = PHPExcel_Calculation::getInstance($worksheet->getParent()); |
||||
|
$newDataValues = PHPExcel_Calculation::_unwrapResult( |
||||
|
$calcEngine->_calculateFormulaValue( |
||||
|
'='.$this->_dataSource, |
||||
|
NULL, |
||||
|
$worksheet->getCell('A1') |
||||
|
) |
||||
|
); |
||||
|
if ($flatten) { |
||||
|
$this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues); |
||||
|
foreach($this->_dataValues as &$dataValue) { |
||||
|
if ((!empty($dataValue)) && ($dataValue[0] == '#')) { |
||||
|
$dataValue = 0.0; |
||||
|
} |
||||
|
} |
||||
|
unset($dataValue); |
||||
|
} else { |
||||
|
$cellRange = explode('!',$this->_dataSource); |
||||
|
if (count($cellRange) > 1) { |
||||
|
list(,$cellRange) = $cellRange; |
||||
|
} |
||||
|
|
||||
|
$dimensions = PHPExcel_Cell::rangeDimension(str_replace('$','',$cellRange)); |
||||
|
if (($dimensions[0] == 1) || ($dimensions[1] == 1)) { |
||||
|
$this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues); |
||||
|
} else { |
||||
|
$newArray = array_values(array_shift($newDataValues)); |
||||
|
foreach($newArray as $i => $newDataSet) { |
||||
|
$newArray[$i] = array($newDataSet); |
||||
|
} |
||||
|
|
||||
|
foreach($newDataValues as $newDataSet) { |
||||
|
$i = 0; |
||||
|
foreach($newDataSet as $newDataVal) { |
||||
|
array_unshift($newArray[$i++],$newDataVal); |
||||
|
} |
||||
|
} |
||||
|
$this->_dataValues = $newArray; |
||||
|
} |
||||
|
} |
||||
|
$this->_pointCount = count($this->_dataValues); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Chart_Exception |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Chart_Exception extends PHPExcel_Exception { |
||||
|
/** |
||||
|
* Error handler callback |
||||
|
* |
||||
|
* @param mixed $code |
||||
|
* @param mixed $string |
||||
|
* @param mixed $file |
||||
|
* @param mixed $line |
||||
|
* @param mixed $context |
||||
|
*/ |
||||
|
public static function errorHandlerCallback($code, $string, $file, $line, $context) { |
||||
|
$e = new self($string, $code); |
||||
|
$e->line = $line; |
||||
|
$e->file = $file; |
||||
|
throw $e; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,472 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/** |
||||
|
* Created by PhpStorm. |
||||
|
* User: Wiktor Trzonkowski |
||||
|
* Date: 7/2/14 |
||||
|
* Time: 2:36 PM |
||||
|
*/ |
||||
|
|
||||
|
class PHPExcel_Chart_GridLines extends PHPExcel_Chart_Properties |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* Properties of Class: |
||||
|
* Object State (State for Minor Tick Mark) @var bool |
||||
|
* Line Properties @var array of mixed |
||||
|
* Shadow Properties @var array of mixed |
||||
|
* Glow Properties @var array of mixed |
||||
|
* Soft Properties @var array of mixed |
||||
|
* |
||||
|
*/ |
||||
|
|
||||
|
private $objectState = false; |
||||
|
|
||||
|
private $lineProperties = array( |
||||
|
'color' => array( |
||||
|
'type' => self::EXCEL_COLOR_TYPE_STANDARD, |
||||
|
'value' => null, |
||||
|
'alpha' => 0 |
||||
|
), |
||||
|
'style' => array( |
||||
|
'width' => '9525', |
||||
|
'compound' => self::LINE_STYLE_COMPOUND_SIMPLE, |
||||
|
'dash' => self::LINE_STYLE_DASH_SOLID, |
||||
|
'cap' => self::LINE_STYLE_CAP_FLAT, |
||||
|
'join' => self::LINE_STYLE_JOIN_BEVEL, |
||||
|
'arrow' => array( |
||||
|
'head' => array( |
||||
|
'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW, |
||||
|
'size' => self::LINE_STYLE_ARROW_SIZE_5 |
||||
|
), |
||||
|
'end' => array( |
||||
|
'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW, |
||||
|
'size' => self::LINE_STYLE_ARROW_SIZE_8 |
||||
|
), |
||||
|
) |
||||
|
) |
||||
|
); |
||||
|
|
||||
|
private $shadowProperties = array( |
||||
|
'presets' => self::SHADOW_PRESETS_NOSHADOW, |
||||
|
'effect' => null, |
||||
|
'color' => array( |
||||
|
'type' => self::EXCEL_COLOR_TYPE_STANDARD, |
||||
|
'value' => 'black', |
||||
|
'alpha' => 85, |
||||
|
), |
||||
|
'size' => array( |
||||
|
'sx' => null, |
||||
|
'sy' => null, |
||||
|
'kx' => null |
||||
|
), |
||||
|
'blur' => null, |
||||
|
'direction' => null, |
||||
|
'distance' => null, |
||||
|
'algn' => null, |
||||
|
'rotWithShape' => null |
||||
|
); |
||||
|
|
||||
|
private $glowProperties = array( |
||||
|
'size' => null, |
||||
|
'color' => array( |
||||
|
'type' => self::EXCEL_COLOR_TYPE_STANDARD, |
||||
|
'value' => 'black', |
||||
|
'alpha' => 40 |
||||
|
) |
||||
|
); |
||||
|
|
||||
|
private $softEdges = array( |
||||
|
'size' => null |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Get Object State |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
|
||||
|
public function getObjectState() |
||||
|
{ |
||||
|
return $this->objectState; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Change Object State to True |
||||
|
* |
||||
|
* @return PHPExcel_Chart_GridLines |
||||
|
*/ |
||||
|
|
||||
|
private function activateObject() |
||||
|
{ |
||||
|
$this->objectState = true; |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Line Color Properties |
||||
|
* |
||||
|
* @param string $value |
||||
|
* @param int $alpha |
||||
|
* @param string $type |
||||
|
*/ |
||||
|
|
||||
|
public function setLineColorProperties($value, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_STANDARD) |
||||
|
{ |
||||
|
$this->activateObject() |
||||
|
->lineProperties['color'] = $this->setColorProperties( |
||||
|
$value, |
||||
|
$alpha, |
||||
|
$type |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Line Color Properties |
||||
|
* |
||||
|
* @param float $line_width |
||||
|
* @param string $compound_type |
||||
|
* @param string $dash_type |
||||
|
* @param string $cap_type |
||||
|
* @param string $join_type |
||||
|
* @param string $head_arrow_type |
||||
|
* @param string $head_arrow_size |
||||
|
* @param string $end_arrow_type |
||||
|
* @param string $end_arrow_size |
||||
|
*/ |
||||
|
|
||||
|
public function setLineStyleProperties($line_width = null, $compound_type = null, $dash_type = null, $cap_type = null, $join_type = null, $head_arrow_type = null, $head_arrow_size = null, $end_arrow_type = null, $end_arrow_size = null) |
||||
|
{ |
||||
|
$this->activateObject(); |
||||
|
(!is_null($line_width)) |
||||
|
? $this->lineProperties['style']['width'] = $this->getExcelPointsWidth((float) $line_width) |
||||
|
: null; |
||||
|
(!is_null($compound_type)) |
||||
|
? $this->lineProperties['style']['compound'] = (string) $compound_type |
||||
|
: null; |
||||
|
(!is_null($dash_type)) |
||||
|
? $this->lineProperties['style']['dash'] = (string) $dash_type |
||||
|
: null; |
||||
|
(!is_null($cap_type)) |
||||
|
? $this->lineProperties['style']['cap'] = (string) $cap_type |
||||
|
: null; |
||||
|
(!is_null($join_type)) |
||||
|
? $this->lineProperties['style']['join'] = (string) $join_type |
||||
|
: null; |
||||
|
(!is_null($head_arrow_type)) |
||||
|
? $this->lineProperties['style']['arrow']['head']['type'] = (string) $head_arrow_type |
||||
|
: null; |
||||
|
(!is_null($head_arrow_size)) |
||||
|
? $this->lineProperties['style']['arrow']['head']['size'] = (string) $head_arrow_size |
||||
|
: null; |
||||
|
(!is_null($end_arrow_type)) |
||||
|
? $this->lineProperties['style']['arrow']['end']['type'] = (string) $end_arrow_type |
||||
|
: null; |
||||
|
(!is_null($end_arrow_size)) |
||||
|
? $this->lineProperties['style']['arrow']['end']['size'] = (string) $end_arrow_size |
||||
|
: null; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Line Color Property |
||||
|
* |
||||
|
* @param string $parameter |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
|
||||
|
public function getLineColorProperty($parameter) |
||||
|
{ |
||||
|
return $this->lineProperties['color'][$parameter]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Line Style Property |
||||
|
* |
||||
|
* @param array|string $elements |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
|
||||
|
public function getLineStyleProperty($elements) |
||||
|
{ |
||||
|
return $this->getArrayElementsValue($this->lineProperties['style'], $elements); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Glow Properties |
||||
|
* |
||||
|
* @param float $size |
||||
|
* @param string $color_value |
||||
|
* @param int $color_alpha |
||||
|
* @param string $color_type |
||||
|
* |
||||
|
*/ |
||||
|
|
||||
|
public function setGlowProperties($size, $color_value = null, $color_alpha = null, $color_type = null) |
||||
|
{ |
||||
|
$this |
||||
|
->activateObject() |
||||
|
->setGlowSize($size) |
||||
|
->setGlowColor($color_value, $color_alpha, $color_type); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Glow Color Property |
||||
|
* |
||||
|
* @param string $property |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
|
||||
|
public function getGlowColor($property) |
||||
|
{ |
||||
|
return $this->glowProperties['color'][$property]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Glow Size |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
|
||||
|
public function getGlowSize() |
||||
|
{ |
||||
|
return $this->glowProperties['size']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Glow Size |
||||
|
* |
||||
|
* @param float $size |
||||
|
* |
||||
|
* @return PHPExcel_Chart_GridLines |
||||
|
*/ |
||||
|
|
||||
|
private function setGlowSize($size) |
||||
|
{ |
||||
|
$this->glowProperties['size'] = $this->getExcelPointsWidth((float) $size); |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Glow Color |
||||
|
* |
||||
|
* @param string $color |
||||
|
* @param int $alpha |
||||
|
* @param string $type |
||||
|
* |
||||
|
* @return PHPExcel_Chart_GridLines |
||||
|
*/ |
||||
|
|
||||
|
private function setGlowColor($color, $alpha, $type) |
||||
|
{ |
||||
|
if (!is_null($color)) { |
||||
|
$this->glowProperties['color']['value'] = (string) $color; |
||||
|
} |
||||
|
if (!is_null($alpha)) { |
||||
|
$this->glowProperties['color']['alpha'] = $this->getTrueAlpha((int) $alpha); |
||||
|
} |
||||
|
if (!is_null($type)) { |
||||
|
$this->glowProperties['color']['type'] = (string) $type; |
||||
|
} |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Line Style Arrow Parameters |
||||
|
* |
||||
|
* @param string $arrow_selector |
||||
|
* @param string $property_selector |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
|
||||
|
public function getLineStyleArrowParameters($arrow_selector, $property_selector) |
||||
|
{ |
||||
|
return $this->getLineStyleArrowSize($this->lineProperties['style']['arrow'][$arrow_selector]['size'], $property_selector); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Shadow Properties |
||||
|
* |
||||
|
* @param int $sh_presets |
||||
|
* @param string $sh_color_value |
||||
|
* @param string $sh_color_type |
||||
|
* @param int $sh_color_alpha |
||||
|
* @param string $sh_blur |
||||
|
* @param int $sh_angle |
||||
|
* @param float $sh_distance |
||||
|
* |
||||
|
*/ |
||||
|
|
||||
|
public function setShadowProperties($sh_presets, $sh_color_value = null, $sh_color_type = null, $sh_color_alpha = null, $sh_blur = null, $sh_angle = null, $sh_distance = null) |
||||
|
{ |
||||
|
$this->activateObject() |
||||
|
->setShadowPresetsProperties((int) $sh_presets) |
||||
|
->setShadowColor( |
||||
|
is_null($sh_color_value) ? $this->shadowProperties['color']['value'] : $sh_color_value, |
||||
|
is_null($sh_color_alpha) ? (int) $this->shadowProperties['color']['alpha'] : $this->getTrueAlpha($sh_color_alpha), |
||||
|
is_null($sh_color_type) ? $this->shadowProperties['color']['type'] : $sh_color_type |
||||
|
) |
||||
|
->setShadowBlur($sh_blur) |
||||
|
->setShadowAngle($sh_angle) |
||||
|
->setShadowDistance($sh_distance); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Shadow Presets Properties |
||||
|
* |
||||
|
* @param int $shadow_presets |
||||
|
* |
||||
|
* @return PHPExcel_Chart_GridLines |
||||
|
*/ |
||||
|
|
||||
|
private function setShadowPresetsProperties($shadow_presets) |
||||
|
{ |
||||
|
$this->shadowProperties['presets'] = $shadow_presets; |
||||
|
$this->setShadowProperiesMapValues($this->getShadowPresetsMap($shadow_presets)); |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Shadow Properties Values |
||||
|
* |
||||
|
* @param array $properties_map |
||||
|
* @param * $reference |
||||
|
* |
||||
|
* @return PHPExcel_Chart_GridLines |
||||
|
*/ |
||||
|
|
||||
|
private function setShadowProperiesMapValues(array $properties_map, &$reference = null) |
||||
|
{ |
||||
|
$base_reference = $reference; |
||||
|
foreach ($properties_map as $property_key => $property_val) { |
||||
|
if (is_array($property_val)) { |
||||
|
if ($reference === null) { |
||||
|
$reference = & $this->shadowProperties[$property_key]; |
||||
|
} else { |
||||
|
$reference = & $reference[$property_key]; |
||||
|
} |
||||
|
$this->setShadowProperiesMapValues($property_val, $reference); |
||||
|
} else { |
||||
|
if ($base_reference === null) { |
||||
|
$this->shadowProperties[$property_key] = $property_val; |
||||
|
} else { |
||||
|
$reference[$property_key] = $property_val; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Shadow Color |
||||
|
* |
||||
|
* @param string $color |
||||
|
* @param int $alpha |
||||
|
* @param string $type |
||||
|
* @return PHPExcel_Chart_GridLines |
||||
|
*/ |
||||
|
private function setShadowColor($color, $alpha, $type) |
||||
|
{ |
||||
|
if (!is_null($color)) { |
||||
|
$this->shadowProperties['color']['value'] = (string) $color; |
||||
|
} |
||||
|
if (!is_null($alpha)) { |
||||
|
$this->shadowProperties['color']['alpha'] = $this->getTrueAlpha((int) $alpha); |
||||
|
} |
||||
|
if (!is_null($type)) { |
||||
|
$this->shadowProperties['color']['type'] = (string) $type; |
||||
|
} |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Shadow Blur |
||||
|
* |
||||
|
* @param float $blur |
||||
|
* |
||||
|
* @return PHPExcel_Chart_GridLines |
||||
|
*/ |
||||
|
private function setShadowBlur($blur) |
||||
|
{ |
||||
|
if ($blur !== null) { |
||||
|
$this->shadowProperties['blur'] = (string) $this->getExcelPointsWidth($blur); |
||||
|
} |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Shadow Angle |
||||
|
* |
||||
|
* @param int $angle |
||||
|
* @return PHPExcel_Chart_GridLines |
||||
|
*/ |
||||
|
|
||||
|
private function setShadowAngle($angle) |
||||
|
{ |
||||
|
if ($angle !== null) { |
||||
|
$this->shadowProperties['direction'] = (string) $this->getExcelPointsAngle($angle); |
||||
|
} |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Shadow Distance |
||||
|
* |
||||
|
* @param float $distance |
||||
|
* @return PHPExcel_Chart_GridLines |
||||
|
*/ |
||||
|
private function setShadowDistance($distance) |
||||
|
{ |
||||
|
if ($distance !== null) { |
||||
|
$this->shadowProperties['distance'] = (string) $this->getExcelPointsWidth($distance); |
||||
|
} |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Shadow Property |
||||
|
* |
||||
|
* @param string $elements |
||||
|
* @param array $elements |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getShadowProperty($elements) |
||||
|
{ |
||||
|
return $this->getArrayElementsValue($this->shadowProperties, $elements); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Soft Edges Size |
||||
|
* |
||||
|
* @param float $size |
||||
|
*/ |
||||
|
public function setSoftEdgesSize($size) |
||||
|
{ |
||||
|
if (!is_null($size)) { |
||||
|
$this->activateObject(); |
||||
|
$softEdges['size'] = (string) $this->getExcelPointsWidth($size); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Soft Edges Size |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getSoftEdgesSize() |
||||
|
{ |
||||
|
return $this->softEdges['size']; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,417 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Chart_Layout |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Chart_Layout |
||||
|
{ |
||||
|
/** |
||||
|
* layoutTarget |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_layoutTarget = NULL; |
||||
|
|
||||
|
/** |
||||
|
* X Mode |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_xMode = NULL; |
||||
|
|
||||
|
/** |
||||
|
* Y Mode |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_yMode = NULL; |
||||
|
|
||||
|
/** |
||||
|
* X-Position |
||||
|
* |
||||
|
* @var float |
||||
|
*/ |
||||
|
private $_xPos = NULL; |
||||
|
|
||||
|
/** |
||||
|
* Y-Position |
||||
|
* |
||||
|
* @var float |
||||
|
*/ |
||||
|
private $_yPos = NULL; |
||||
|
|
||||
|
/** |
||||
|
* width |
||||
|
* |
||||
|
* @var float |
||||
|
*/ |
||||
|
private $_width = NULL; |
||||
|
|
||||
|
/** |
||||
|
* height |
||||
|
* |
||||
|
* @var float |
||||
|
*/ |
||||
|
private $_height = NULL; |
||||
|
|
||||
|
/** |
||||
|
* show legend key |
||||
|
* Specifies that legend keys should be shown in data labels |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_showLegendKey = NULL; |
||||
|
|
||||
|
/** |
||||
|
* show value |
||||
|
* Specifies that the value should be shown in a data label. |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_showVal = NULL; |
||||
|
|
||||
|
/** |
||||
|
* show category name |
||||
|
* Specifies that the category name should be shown in the data label. |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_showCatName = NULL; |
||||
|
|
||||
|
/** |
||||
|
* show data series name |
||||
|
* Specifies that the series name should be shown in the data label. |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_showSerName = NULL; |
||||
|
|
||||
|
/** |
||||
|
* show percentage |
||||
|
* Specifies that the percentage should be shown in the data label. |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_showPercent = NULL; |
||||
|
|
||||
|
/** |
||||
|
* show bubble size |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_showBubbleSize = NULL; |
||||
|
|
||||
|
/** |
||||
|
* show leader lines |
||||
|
* Specifies that leader lines should be shown for the data label. |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_showLeaderLines = NULL; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Chart_Layout |
||||
|
*/ |
||||
|
public function __construct($layout=array()) |
||||
|
{ |
||||
|
if (isset($layout['layoutTarget'])) { $this->_layoutTarget = $layout['layoutTarget']; } |
||||
|
if (isset($layout['xMode'])) { $this->_xMode = $layout['xMode']; } |
||||
|
if (isset($layout['yMode'])) { $this->_yMode = $layout['yMode']; } |
||||
|
if (isset($layout['x'])) { $this->_xPos = (float) $layout['x']; } |
||||
|
if (isset($layout['y'])) { $this->_yPos = (float) $layout['y']; } |
||||
|
if (isset($layout['w'])) { $this->_width = (float) $layout['w']; } |
||||
|
if (isset($layout['h'])) { $this->_height = (float) $layout['h']; } |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Layout Target |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getLayoutTarget() { |
||||
|
return $this->_layoutTarget; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Layout Target |
||||
|
* |
||||
|
* @param Layout Target $value |
||||
|
*/ |
||||
|
public function setLayoutTarget($value) { |
||||
|
$this->_layoutTarget = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get X-Mode |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getXMode() { |
||||
|
return $this->_xMode; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set X-Mode |
||||
|
* |
||||
|
* @param X-Mode $value |
||||
|
*/ |
||||
|
public function setXMode($value) { |
||||
|
$this->_xMode = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Y-Mode |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getYMode() { |
||||
|
return $this->_xMode; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Y-Mode |
||||
|
* |
||||
|
* @param Y-Mode $value |
||||
|
*/ |
||||
|
public function setYMode($value) { |
||||
|
$this->_xMode = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get X-Position |
||||
|
* |
||||
|
* @return number |
||||
|
*/ |
||||
|
public function getXPosition() { |
||||
|
return $this->_xPos; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set X-Position |
||||
|
* |
||||
|
* @param X-Position $value |
||||
|
*/ |
||||
|
public function setXPosition($value) { |
||||
|
$this->_xPos = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Y-Position |
||||
|
* |
||||
|
* @return number |
||||
|
*/ |
||||
|
public function getYPosition() { |
||||
|
return $this->_yPos; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Y-Position |
||||
|
* |
||||
|
* @param Y-Position $value |
||||
|
*/ |
||||
|
public function setYPosition($value) { |
||||
|
$this->_yPos = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Width |
||||
|
* |
||||
|
* @return number |
||||
|
*/ |
||||
|
public function getWidth() { |
||||
|
return $this->_width; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Width |
||||
|
* |
||||
|
* @param Width $value |
||||
|
*/ |
||||
|
public function setWidth($value) { |
||||
|
$this->_width = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Height |
||||
|
* |
||||
|
* @return number |
||||
|
*/ |
||||
|
public function getHeight() { |
||||
|
return $this->_height; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Height |
||||
|
* |
||||
|
* @param Height $value |
||||
|
*/ |
||||
|
public function setHeight($value) { |
||||
|
$this->_height = $value; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get show legend key |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getShowLegendKey() { |
||||
|
return $this->_showLegendKey; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set show legend key |
||||
|
* Specifies that legend keys should be shown in data labels. |
||||
|
* |
||||
|
* @param boolean $value Show legend key |
||||
|
*/ |
||||
|
public function setShowLegendKey($value) { |
||||
|
$this->_showLegendKey = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get show value |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getShowVal() { |
||||
|
return $this->_showVal; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set show val |
||||
|
* Specifies that the value should be shown in data labels. |
||||
|
* |
||||
|
* @param boolean $value Show val |
||||
|
*/ |
||||
|
public function setShowVal($value) { |
||||
|
$this->_showVal = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get show category name |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getShowCatName() { |
||||
|
return $this->_showCatName; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set show cat name |
||||
|
* Specifies that the category name should be shown in data labels. |
||||
|
* |
||||
|
* @param boolean $value Show cat name |
||||
|
*/ |
||||
|
public function setShowCatName($value) { |
||||
|
$this->_showCatName = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get show data series name |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getShowSerName() { |
||||
|
return $this->_showSerName; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set show ser name |
||||
|
* Specifies that the series name should be shown in data labels. |
||||
|
* |
||||
|
* @param boolean $value Show ser name |
||||
|
*/ |
||||
|
public function setShowSerName($value) { |
||||
|
$this->_showSerName = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get show percentage |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getShowPercent() { |
||||
|
return $this->_showPercent; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set show percentage |
||||
|
* Specifies that the percentage should be shown in data labels. |
||||
|
* |
||||
|
* @param boolean $value Show percentage |
||||
|
*/ |
||||
|
public function setShowPercent($value) { |
||||
|
$this->_showPercent = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get show bubble size |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getShowBubbleSize() { |
||||
|
return $this->_showBubbleSize; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set show bubble size |
||||
|
* Specifies that the bubble size should be shown in data labels. |
||||
|
* |
||||
|
* @param boolean $value Show bubble size |
||||
|
*/ |
||||
|
public function setShowBubbleSize($value) { |
||||
|
$this->_showBubbleSize = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get show leader lines |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getShowLeaderLines() { |
||||
|
return $this->_showLeaderLines; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set show leader lines |
||||
|
* Specifies that leader lines should be shown in data labels. |
||||
|
* |
||||
|
* @param boolean $value Show leader lines |
||||
|
*/ |
||||
|
public function setShowLeaderLines($value) { |
||||
|
$this->_showLeaderLines = $value; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,171 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Chart_Legend |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Chart_Legend |
||||
|
{ |
||||
|
/** Legend positions */ |
||||
|
const xlLegendPositionBottom = -4107; // Below the chart. |
||||
|
const xlLegendPositionCorner = 2; // In the upper right-hand corner of the chart border. |
||||
|
const xlLegendPositionCustom = -4161; // A custom position. |
||||
|
const xlLegendPositionLeft = -4131; // Left of the chart. |
||||
|
const xlLegendPositionRight = -4152; // Right of the chart. |
||||
|
const xlLegendPositionTop = -4160; // Above the chart. |
||||
|
|
||||
|
const POSITION_RIGHT = 'r'; |
||||
|
const POSITION_LEFT = 'l'; |
||||
|
const POSITION_BOTTOM = 'b'; |
||||
|
const POSITION_TOP = 't'; |
||||
|
const POSITION_TOPRIGHT = 'tr'; |
||||
|
|
||||
|
private static $_positionXLref = array( self::xlLegendPositionBottom => self::POSITION_BOTTOM, |
||||
|
self::xlLegendPositionCorner => self::POSITION_TOPRIGHT, |
||||
|
self::xlLegendPositionCustom => '??', |
||||
|
self::xlLegendPositionLeft => self::POSITION_LEFT, |
||||
|
self::xlLegendPositionRight => self::POSITION_RIGHT, |
||||
|
self::xlLegendPositionTop => self::POSITION_TOP |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Legend position |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_position = self::POSITION_RIGHT; |
||||
|
|
||||
|
/** |
||||
|
* Allow overlay of other elements? |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_overlay = TRUE; |
||||
|
|
||||
|
/** |
||||
|
* Legend Layout |
||||
|
* |
||||
|
* @var PHPExcel_Chart_Layout |
||||
|
*/ |
||||
|
private $_layout = NULL; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Chart_Legend |
||||
|
*/ |
||||
|
public function __construct($position = self::POSITION_RIGHT, PHPExcel_Chart_Layout $layout = NULL, $overlay = FALSE) |
||||
|
{ |
||||
|
$this->setPosition($position); |
||||
|
$this->_layout = $layout; |
||||
|
$this->setOverlay($overlay); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get legend position as an excel string value |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getPosition() { |
||||
|
return $this->_position; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get legend position using an excel string value |
||||
|
* |
||||
|
* @param string $position |
||||
|
*/ |
||||
|
public function setPosition($position = self::POSITION_RIGHT) { |
||||
|
if (!in_array($position,self::$_positionXLref)) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
$this->_position = $position; |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get legend position as an Excel internal numeric value |
||||
|
* |
||||
|
* @return number |
||||
|
*/ |
||||
|
public function getPositionXL() { |
||||
|
return array_search($this->_position,self::$_positionXLref); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set legend position using an Excel internal numeric value |
||||
|
* |
||||
|
* @param number $positionXL |
||||
|
*/ |
||||
|
public function setPositionXL($positionXL = self::xlLegendPositionRight) { |
||||
|
if (!array_key_exists($positionXL,self::$_positionXLref)) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
$this->_position = self::$_positionXLref[$positionXL]; |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get allow overlay of other elements? |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getOverlay() { |
||||
|
return $this->_overlay; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set allow overlay of other elements? |
||||
|
* |
||||
|
* @param boolean $overlay |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function setOverlay($overlay = FALSE) { |
||||
|
if (!is_bool($overlay)) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
$this->_overlay = $overlay; |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Layout |
||||
|
* |
||||
|
* @return PHPExcel_Chart_Layout |
||||
|
*/ |
||||
|
public function getLayout() { |
||||
|
return $this->_layout; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,125 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Chart_PlotArea |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Chart_PlotArea |
||||
|
{ |
||||
|
/** |
||||
|
* PlotArea Layout |
||||
|
* |
||||
|
* @var PHPExcel_Chart_Layout |
||||
|
*/ |
||||
|
private $_layout = null; |
||||
|
|
||||
|
/** |
||||
|
* Plot Series |
||||
|
* |
||||
|
* @var array of PHPExcel_Chart_DataSeries |
||||
|
*/ |
||||
|
private $_plotSeries = array(); |
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Chart_PlotArea |
||||
|
*/ |
||||
|
public function __construct(PHPExcel_Chart_Layout $layout = null, $plotSeries = array()) |
||||
|
{ |
||||
|
$this->_layout = $layout; |
||||
|
$this->_plotSeries = $plotSeries; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Layout |
||||
|
* |
||||
|
* @return PHPExcel_Chart_Layout |
||||
|
*/ |
||||
|
public function getLayout() { |
||||
|
return $this->_layout; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Number of Plot Groups |
||||
|
* |
||||
|
* @return array of PHPExcel_Chart_DataSeries |
||||
|
*/ |
||||
|
public function getPlotGroupCount() { |
||||
|
return count($this->_plotSeries); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Number of Plot Series |
||||
|
* |
||||
|
* @return integer |
||||
|
*/ |
||||
|
public function getPlotSeriesCount() { |
||||
|
$seriesCount = 0; |
||||
|
foreach($this->_plotSeries as $plot) { |
||||
|
$seriesCount += $plot->getPlotSeriesCount(); |
||||
|
} |
||||
|
return $seriesCount; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Plot Series |
||||
|
* |
||||
|
* @return array of PHPExcel_Chart_DataSeries |
||||
|
*/ |
||||
|
public function getPlotGroup() { |
||||
|
return $this->_plotSeries; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Plot Series by Index |
||||
|
* |
||||
|
* @return PHPExcel_Chart_DataSeries |
||||
|
*/ |
||||
|
public function getPlotGroupByIndex($index) { |
||||
|
return $this->_plotSeries[$index]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Plot Series |
||||
|
* |
||||
|
* @param [PHPExcel_Chart_DataSeries] |
||||
|
*/ |
||||
|
public function setPlotSeries($plotSeries = array()) { |
||||
|
$this->_plotSeries = $plotSeries; |
||||
|
} |
||||
|
|
||||
|
public function refresh(PHPExcel_Worksheet $worksheet) { |
||||
|
foreach($this->_plotSeries as $plotSeries) { |
||||
|
$plotSeries->refresh($worksheet); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,363 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* Created by PhpStorm. |
||||
|
* User: nhw2h8s |
||||
|
* Date: 7/2/14 |
||||
|
* Time: 5:45 PM |
||||
|
*/ |
||||
|
|
||||
|
abstract class PHPExcel_Chart_Properties |
||||
|
{ |
||||
|
const |
||||
|
EXCEL_COLOR_TYPE_STANDARD = 'prstClr', |
||||
|
EXCEL_COLOR_TYPE_SCHEME = 'schemeClr', |
||||
|
EXCEL_COLOR_TYPE_ARGB = 'srgbClr'; |
||||
|
|
||||
|
const |
||||
|
AXIS_LABELS_LOW = 'low', |
||||
|
AXIS_LABELS_HIGH = 'high', |
||||
|
AXIS_LABELS_NEXT_TO = 'nextTo', |
||||
|
AXIS_LABELS_NONE = 'none'; |
||||
|
|
||||
|
const |
||||
|
TICK_MARK_NONE = 'none', |
||||
|
TICK_MARK_INSIDE = 'in', |
||||
|
TICK_MARK_OUTSIDE = 'out', |
||||
|
TICK_MARK_CROSS = 'cross'; |
||||
|
|
||||
|
const |
||||
|
HORIZONTAL_CROSSES_AUTOZERO = 'autoZero', |
||||
|
HORIZONTAL_CROSSES_MAXIMUM = 'max'; |
||||
|
|
||||
|
const |
||||
|
FORMAT_CODE_GENERAL = 'General', |
||||
|
FORMAT_CODE_NUMBER = '#,##0.00', |
||||
|
FORMAT_CODE_CURRENCY = '$#,##0.00', |
||||
|
FORMAT_CODE_ACCOUNTING = '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)', |
||||
|
FORMAT_CODE_DATE = 'm/d/yyyy', |
||||
|
FORMAT_CODE_TIME = '[$-F400]h:mm:ss AM/PM', |
||||
|
FORMAT_CODE_PERCENTAGE = '0.00%', |
||||
|
FORMAT_CODE_FRACTION = '# ?/?', |
||||
|
FORMAT_CODE_SCIENTIFIC = '0.00E+00', |
||||
|
FORMAT_CODE_TEXT = '@', |
||||
|
FORMAT_CODE_SPECIAL = '00000'; |
||||
|
|
||||
|
const |
||||
|
ORIENTATION_NORMAL = 'minMax', |
||||
|
ORIENTATION_REVERSED = 'maxMin'; |
||||
|
|
||||
|
const |
||||
|
LINE_STYLE_COMPOUND_SIMPLE = 'sng', |
||||
|
LINE_STYLE_COMPOUND_DOUBLE = 'dbl', |
||||
|
LINE_STYLE_COMPOUND_THICKTHIN = 'thickThin', |
||||
|
LINE_STYLE_COMPOUND_THINTHICK = 'thinThick', |
||||
|
LINE_STYLE_COMPOUND_TRIPLE = 'tri', |
||||
|
|
||||
|
LINE_STYLE_DASH_SOLID = 'solid', |
||||
|
LINE_STYLE_DASH_ROUND_DOT = 'sysDot', |
||||
|
LINE_STYLE_DASH_SQUERE_DOT = 'sysDash', |
||||
|
LINE_STYPE_DASH_DASH = 'dash', |
||||
|
LINE_STYLE_DASH_DASH_DOT = 'dashDot', |
||||
|
LINE_STYLE_DASH_LONG_DASH = 'lgDash', |
||||
|
LINE_STYLE_DASH_LONG_DASH_DOT = 'lgDashDot', |
||||
|
LINE_STYLE_DASH_LONG_DASH_DOT_DOT = 'lgDashDotDot', |
||||
|
|
||||
|
LINE_STYLE_CAP_SQUARE = 'sq', |
||||
|
LINE_STYLE_CAP_ROUND = 'rnd', |
||||
|
LINE_STYLE_CAP_FLAT = 'flat', |
||||
|
|
||||
|
LINE_STYLE_JOIN_ROUND = 'bevel', |
||||
|
LINE_STYLE_JOIN_MITER = 'miter', |
||||
|
LINE_STYLE_JOIN_BEVEL = 'bevel', |
||||
|
|
||||
|
LINE_STYLE_ARROW_TYPE_NOARROW = null, |
||||
|
LINE_STYLE_ARROW_TYPE_ARROW = 'triangle', |
||||
|
LINE_STYLE_ARROW_TYPE_OPEN = 'arrow', |
||||
|
LINE_STYLE_ARROW_TYPE_STEALTH = 'stealth', |
||||
|
LINE_STYLE_ARROW_TYPE_DIAMOND = 'diamond', |
||||
|
LINE_STYLE_ARROW_TYPE_OVAL = 'oval', |
||||
|
|
||||
|
LINE_STYLE_ARROW_SIZE_1 = 1, |
||||
|
LINE_STYLE_ARROW_SIZE_2 = 2, |
||||
|
LINE_STYLE_ARROW_SIZE_3 = 3, |
||||
|
LINE_STYLE_ARROW_SIZE_4 = 4, |
||||
|
LINE_STYLE_ARROW_SIZE_5 = 5, |
||||
|
LINE_STYLE_ARROW_SIZE_6 = 6, |
||||
|
LINE_STYLE_ARROW_SIZE_7 = 7, |
||||
|
LINE_STYLE_ARROW_SIZE_8 = 8, |
||||
|
LINE_STYLE_ARROW_SIZE_9 = 9; |
||||
|
|
||||
|
const |
||||
|
SHADOW_PRESETS_NOSHADOW = null, |
||||
|
SHADOW_PRESETS_OUTER_BOTTTOM_RIGHT = 1, |
||||
|
SHADOW_PRESETS_OUTER_BOTTOM = 2, |
||||
|
SHADOW_PRESETS_OUTER_BOTTOM_LEFT = 3, |
||||
|
SHADOW_PRESETS_OUTER_RIGHT = 4, |
||||
|
SHADOW_PRESETS_OUTER_CENTER = 5, |
||||
|
SHADOW_PRESETS_OUTER_LEFT = 6, |
||||
|
SHADOW_PRESETS_OUTER_TOP_RIGHT = 7, |
||||
|
SHADOW_PRESETS_OUTER_TOP = 8, |
||||
|
SHADOW_PRESETS_OUTER_TOP_LEFT = 9, |
||||
|
SHADOW_PRESETS_INNER_BOTTTOM_RIGHT = 10, |
||||
|
SHADOW_PRESETS_INNER_BOTTOM = 11, |
||||
|
SHADOW_PRESETS_INNER_BOTTOM_LEFT = 12, |
||||
|
SHADOW_PRESETS_INNER_RIGHT = 13, |
||||
|
SHADOW_PRESETS_INNER_CENTER = 14, |
||||
|
SHADOW_PRESETS_INNER_LEFT = 15, |
||||
|
SHADOW_PRESETS_INNER_TOP_RIGHT = 16, |
||||
|
SHADOW_PRESETS_INNER_TOP = 17, |
||||
|
SHADOW_PRESETS_INNER_TOP_LEFT = 18, |
||||
|
SHADOW_PRESETS_PERSPECTIVE_BELOW = 19, |
||||
|
SHADOW_PRESETS_PERSPECTIVE_UPPER_RIGHT = 20, |
||||
|
SHADOW_PRESETS_PERSPECTIVE_UPPER_LEFT = 21, |
||||
|
SHADOW_PRESETS_PERSPECTIVE_LOWER_RIGHT = 22, |
||||
|
SHADOW_PRESETS_PERSPECTIVE_LOWER_LEFT = 23; |
||||
|
|
||||
|
protected function getExcelPointsWidth($width) |
||||
|
{ |
||||
|
return $width * 12700; |
||||
|
} |
||||
|
|
||||
|
protected function getExcelPointsAngle($angle) |
||||
|
{ |
||||
|
return $angle * 60000; |
||||
|
} |
||||
|
|
||||
|
protected function getTrueAlpha($alpha) |
||||
|
{ |
||||
|
return (string) 100 - $alpha . '000'; |
||||
|
} |
||||
|
|
||||
|
protected function setColorProperties($color, $alpha, $type) |
||||
|
{ |
||||
|
return array( |
||||
|
'type' => (string) $type, |
||||
|
'value' => (string) $color, |
||||
|
'alpha' => (string) $this->getTrueAlpha($alpha) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
protected function getLineStyleArrowSize($array_selector, $array_kay_selector) |
||||
|
{ |
||||
|
$sizes = array( |
||||
|
1 => array('w' => 'sm', 'len' => 'sm'), |
||||
|
2 => array('w' => 'sm', 'len' => 'med'), |
||||
|
3 => array('w' => 'sm', 'len' => 'lg'), |
||||
|
4 => array('w' => 'med', 'len' => 'sm'), |
||||
|
5 => array('w' => 'med', 'len' => 'med'), |
||||
|
6 => array('w' => 'med', 'len' => 'lg'), |
||||
|
7 => array('w' => 'lg', 'len' => 'sm'), |
||||
|
8 => array('w' => 'lg', 'len' => 'med'), |
||||
|
9 => array('w' => 'lg', 'len' => 'lg') |
||||
|
); |
||||
|
|
||||
|
return $sizes[$array_selector][$array_kay_selector]; |
||||
|
} |
||||
|
|
||||
|
protected function getShadowPresetsMap($shadow_presets_option) |
||||
|
{ |
||||
|
$presets_options = array( |
||||
|
//OUTER |
||||
|
1 => array( |
||||
|
'effect' => 'outerShdw', |
||||
|
'blur' => '50800', |
||||
|
'distance' => '38100', |
||||
|
'direction' => '2700000', |
||||
|
'algn' => 'tl', |
||||
|
'rotWithShape' => '0' |
||||
|
), |
||||
|
2 => array( |
||||
|
'effect' => 'outerShdw', |
||||
|
'blur' => '50800', |
||||
|
'distance' => '38100', |
||||
|
'direction' => '5400000', |
||||
|
'algn' => 't', |
||||
|
'rotWithShape' => '0' |
||||
|
), |
||||
|
3 => array( |
||||
|
'effect' => 'outerShdw', |
||||
|
'blur' => '50800', |
||||
|
'distance' => '38100', |
||||
|
'direction' => '8100000', |
||||
|
'algn' => 'tr', |
||||
|
'rotWithShape' => '0' |
||||
|
), |
||||
|
4 => array( |
||||
|
'effect' => 'outerShdw', |
||||
|
'blur' => '50800', |
||||
|
'distance' => '38100', |
||||
|
'algn' => 'l', |
||||
|
'rotWithShape' => '0' |
||||
|
), |
||||
|
5 => array( |
||||
|
'effect' => 'outerShdw', |
||||
|
'size' => array( |
||||
|
'sx' => '102000', |
||||
|
'sy' => '102000' |
||||
|
) |
||||
|
, |
||||
|
'blur' => '63500', |
||||
|
'distance' => '38100', |
||||
|
'algn' => 'ctr', |
||||
|
'rotWithShape' => '0' |
||||
|
), |
||||
|
6 => array( |
||||
|
'effect' => 'outerShdw', |
||||
|
'blur' => '50800', |
||||
|
'distance' => '38100', |
||||
|
'direction' => '10800000', |
||||
|
'algn' => 'r', |
||||
|
'rotWithShape' => '0' |
||||
|
), |
||||
|
7 => array( |
||||
|
'effect' => 'outerShdw', |
||||
|
'blur' => '50800', |
||||
|
'distance' => '38100', |
||||
|
'direction' => '18900000', |
||||
|
'algn' => 'bl', |
||||
|
'rotWithShape' => '0' |
||||
|
), |
||||
|
8 => array( |
||||
|
'effect' => 'outerShdw', |
||||
|
'blur' => '50800', |
||||
|
'distance' => '38100', |
||||
|
'direction' => '16200000', |
||||
|
'rotWithShape' => '0' |
||||
|
), |
||||
|
9 => array( |
||||
|
'effect' => 'outerShdw', |
||||
|
'blur' => '50800', |
||||
|
'distance' => '38100', |
||||
|
'direction' => '13500000', |
||||
|
'algn' => 'br', |
||||
|
'rotWithShape' => '0' |
||||
|
), |
||||
|
//INNER |
||||
|
10 => array( |
||||
|
'effect' => 'innerShdw', |
||||
|
'blur' => '63500', |
||||
|
'distance' => '50800', |
||||
|
'direction' => '2700000', |
||||
|
), |
||||
|
11 => array( |
||||
|
'effect' => 'innerShdw', |
||||
|
'blur' => '63500', |
||||
|
'distance' => '50800', |
||||
|
'direction' => '5400000', |
||||
|
), |
||||
|
12 => array( |
||||
|
'effect' => 'innerShdw', |
||||
|
'blur' => '63500', |
||||
|
'distance' => '50800', |
||||
|
'direction' => '8100000', |
||||
|
), |
||||
|
13 => array( |
||||
|
'effect' => 'innerShdw', |
||||
|
'blur' => '63500', |
||||
|
'distance' => '50800', |
||||
|
), |
||||
|
14 => array( |
||||
|
'effect' => 'innerShdw', |
||||
|
'blur' => '114300', |
||||
|
), |
||||
|
15 => array( |
||||
|
'effect' => 'innerShdw', |
||||
|
'blur' => '63500', |
||||
|
'distance' => '50800', |
||||
|
'direction' => '10800000', |
||||
|
), |
||||
|
16 => array( |
||||
|
'effect' => 'innerShdw', |
||||
|
'blur' => '63500', |
||||
|
'distance' => '50800', |
||||
|
'direction' => '18900000', |
||||
|
), |
||||
|
17 => array( |
||||
|
'effect' => 'innerShdw', |
||||
|
'blur' => '63500', |
||||
|
'distance' => '50800', |
||||
|
'direction' => '16200000', |
||||
|
), |
||||
|
18 => array( |
||||
|
'effect' => 'innerShdw', |
||||
|
'blur' => '63500', |
||||
|
'distance' => '50800', |
||||
|
'direction' => '13500000', |
||||
|
), |
||||
|
//perspective |
||||
|
19 => array( |
||||
|
'effect' => 'outerShdw', |
||||
|
'blur' => '152400', |
||||
|
'distance' => '317500', |
||||
|
'size' => array( |
||||
|
'sx' => '90000', |
||||
|
'sy' => '-19000', |
||||
|
), |
||||
|
'direction' => '5400000', |
||||
|
'rotWithShape' => '0', |
||||
|
), |
||||
|
20 => array( |
||||
|
'effect' => 'outerShdw', |
||||
|
'blur' => '76200', |
||||
|
'direction' => '18900000', |
||||
|
'size' => array( |
||||
|
'sy' => '23000', |
||||
|
'kx' => '-1200000', |
||||
|
), |
||||
|
'algn' => 'bl', |
||||
|
'rotWithShape' => '0', |
||||
|
), |
||||
|
21 => array( |
||||
|
'effect' => 'outerShdw', |
||||
|
'blur' => '76200', |
||||
|
'direction' => '13500000', |
||||
|
'size' => array( |
||||
|
'sy' => '23000', |
||||
|
'kx' => '1200000', |
||||
|
), |
||||
|
'algn' => 'br', |
||||
|
'rotWithShape' => '0', |
||||
|
), |
||||
|
22 => array( |
||||
|
'effect' => 'outerShdw', |
||||
|
'blur' => '76200', |
||||
|
'distance' => '12700', |
||||
|
'direction' => '2700000', |
||||
|
'size' => array( |
||||
|
'sy' => '-23000', |
||||
|
'kx' => '-800400', |
||||
|
), |
||||
|
'algn' => 'bl', |
||||
|
'rotWithShape' => '0', |
||||
|
), |
||||
|
23 => array( |
||||
|
'effect' => 'outerShdw', |
||||
|
'blur' => '76200', |
||||
|
'distance' => '12700', |
||||
|
'direction' => '8100000', |
||||
|
'size' => array( |
||||
|
'sy' => '-23000', |
||||
|
'kx' => '800400', |
||||
|
), |
||||
|
'algn' => 'br', |
||||
|
'rotWithShape' => '0', |
||||
|
), |
||||
|
); |
||||
|
|
||||
|
return $presets_options[$shadow_presets_option]; |
||||
|
} |
||||
|
|
||||
|
protected function getArrayElementsValue($properties, $elements) |
||||
|
{ |
||||
|
$reference = & $properties; |
||||
|
if (!is_array($elements)) { |
||||
|
return $reference[$elements]; |
||||
|
} else { |
||||
|
foreach ($elements as $keys) { |
||||
|
$reference = & $reference[$keys]; |
||||
|
} |
||||
|
return $reference; |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
ChartDirector |
||||
|
http://www.advsofteng.com/cdphp.html |
||||
|
|
||||
|
GraPHPite |
||||
|
http://graphpite.sourceforge.net/ |
||||
|
|
||||
|
JpGraph |
||||
|
http://www.aditus.nu/jpgraph/ |
||||
|
|
||||
|
LibChart |
||||
|
http://naku.dohcrew.com/libchart/pages/introduction/ |
||||
|
|
||||
|
pChart |
||||
|
http://pchart.sourceforge.net/ |
||||
|
|
||||
|
TeeChart |
||||
|
http://www.steema.com/products/teechart/overview.html |
||||
@ -0,0 +1,837 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart_Renderer |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
require_once(PHPExcel_Settings::getChartRendererPath().'/jpgraph.php'); |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Chart_Renderer_jpgraph |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart_Renderer |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Chart_Renderer_jpgraph |
||||
|
{ |
||||
|
private static $_width = 640; |
||||
|
|
||||
|
private static $_height = 480; |
||||
|
|
||||
|
private static $_colourSet = array( 'mediumpurple1', 'palegreen3', 'gold1', 'cadetblue1', |
||||
|
'darkmagenta', 'coral', 'dodgerblue3', 'eggplant', |
||||
|
'mediumblue', 'magenta', 'sandybrown', 'cyan', |
||||
|
'firebrick1', 'forestgreen', 'deeppink4', 'darkolivegreen', |
||||
|
'goldenrod2' |
||||
|
); |
||||
|
|
||||
|
private static $_markSet = array( 'diamond' => MARK_DIAMOND, |
||||
|
'square' => MARK_SQUARE, |
||||
|
'triangle' => MARK_UTRIANGLE, |
||||
|
'x' => MARK_X, |
||||
|
'star' => MARK_STAR, |
||||
|
'dot' => MARK_FILLEDCIRCLE, |
||||
|
'dash' => MARK_DTRIANGLE, |
||||
|
'circle' => MARK_CIRCLE, |
||||
|
'plus' => MARK_CROSS |
||||
|
); |
||||
|
|
||||
|
|
||||
|
private $_chart = null; |
||||
|
|
||||
|
private $_graph = null; |
||||
|
|
||||
|
private static $_plotColour = 0; |
||||
|
|
||||
|
private static $_plotMark = 0; |
||||
|
|
||||
|
|
||||
|
private function _formatPointMarker($seriesPlot,$markerID) { |
||||
|
$plotMarkKeys = array_keys(self::$_markSet); |
||||
|
if (is_null($markerID)) { |
||||
|
// Use default plot marker (next marker in the series) |
||||
|
self::$_plotMark %= count(self::$_markSet); |
||||
|
$seriesPlot->mark->SetType(self::$_markSet[$plotMarkKeys[self::$_plotMark++]]); |
||||
|
} elseif ($markerID !== 'none') { |
||||
|
// Use specified plot marker (if it exists) |
||||
|
if (isset(self::$_markSet[$markerID])) { |
||||
|
$seriesPlot->mark->SetType(self::$_markSet[$markerID]); |
||||
|
} else { |
||||
|
// If the specified plot marker doesn't exist, use default plot marker (next marker in the series) |
||||
|
self::$_plotMark %= count(self::$_markSet); |
||||
|
$seriesPlot->mark->SetType(self::$_markSet[$plotMarkKeys[self::$_plotMark++]]); |
||||
|
} |
||||
|
} else { |
||||
|
// Hide plot marker |
||||
|
$seriesPlot->mark->Hide(); |
||||
|
} |
||||
|
$seriesPlot->mark->SetColor(self::$_colourSet[self::$_plotColour]); |
||||
|
$seriesPlot->mark->SetFillColor(self::$_colourSet[self::$_plotColour]); |
||||
|
$seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]); |
||||
|
|
||||
|
return $seriesPlot; |
||||
|
} // function _formatPointMarker() |
||||
|
|
||||
|
|
||||
|
private function _formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation = '') { |
||||
|
$datasetLabelFormatCode = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getFormatCode(); |
||||
|
if (!is_null($datasetLabelFormatCode)) { |
||||
|
// Retrieve any label formatting code |
||||
|
$datasetLabelFormatCode = stripslashes($datasetLabelFormatCode); |
||||
|
} |
||||
|
|
||||
|
$testCurrentIndex = 0; |
||||
|
foreach($datasetLabels as $i => $datasetLabel) { |
||||
|
if (is_array($datasetLabel)) { |
||||
|
if ($rotation == 'bar') { |
||||
|
$datasetLabels[$i] = implode(" ",$datasetLabel); |
||||
|
} else { |
||||
|
$datasetLabel = array_reverse($datasetLabel); |
||||
|
$datasetLabels[$i] = implode("\n",$datasetLabel); |
||||
|
} |
||||
|
} else { |
||||
|
// Format labels according to any formatting code |
||||
|
if (!is_null($datasetLabelFormatCode)) { |
||||
|
$datasetLabels[$i] = PHPExcel_Style_NumberFormat::toFormattedString($datasetLabel,$datasetLabelFormatCode); |
||||
|
} |
||||
|
} |
||||
|
++$testCurrentIndex; |
||||
|
} |
||||
|
|
||||
|
return $datasetLabels; |
||||
|
} // function _formatDataSetLabels() |
||||
|
|
||||
|
|
||||
|
private function _percentageSumCalculation($groupID,$seriesCount) { |
||||
|
// Adjust our values to a percentage value across all series in the group |
||||
|
for($i = 0; $i < $seriesCount; ++$i) { |
||||
|
if ($i == 0) { |
||||
|
$sumValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues(); |
||||
|
} else { |
||||
|
$nextValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues(); |
||||
|
foreach($nextValues as $k => $value) { |
||||
|
if (isset($sumValues[$k])) { |
||||
|
$sumValues[$k] += $value; |
||||
|
} else { |
||||
|
$sumValues[$k] = $value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $sumValues; |
||||
|
} // function _percentageSumCalculation() |
||||
|
|
||||
|
|
||||
|
private function _percentageAdjustValues($dataValues,$sumValues) { |
||||
|
foreach($dataValues as $k => $dataValue) { |
||||
|
$dataValues[$k] = $dataValue / $sumValues[$k] * 100; |
||||
|
} |
||||
|
|
||||
|
return $dataValues; |
||||
|
} // function _percentageAdjustValues() |
||||
|
|
||||
|
|
||||
|
private function _getCaption($captionElement) { |
||||
|
// Read any caption |
||||
|
$caption = (!is_null($captionElement)) ? $captionElement->getCaption() : NULL; |
||||
|
// Test if we have a title caption to display |
||||
|
if (!is_null($caption)) { |
||||
|
// If we do, it could be a plain string or an array |
||||
|
if (is_array($caption)) { |
||||
|
// Implode an array to a plain string |
||||
|
$caption = implode('',$caption); |
||||
|
} |
||||
|
} |
||||
|
return $caption; |
||||
|
} // function _getCaption() |
||||
|
|
||||
|
|
||||
|
private function _renderTitle() { |
||||
|
$title = $this->_getCaption($this->_chart->getTitle()); |
||||
|
if (!is_null($title)) { |
||||
|
$this->_graph->title->Set($title); |
||||
|
} |
||||
|
} // function _renderTitle() |
||||
|
|
||||
|
|
||||
|
private function _renderLegend() { |
||||
|
$legend = $this->_chart->getLegend(); |
||||
|
if (!is_null($legend)) { |
||||
|
$legendPosition = $legend->getPosition(); |
||||
|
$legendOverlay = $legend->getOverlay(); |
||||
|
switch ($legendPosition) { |
||||
|
case 'r' : |
||||
|
$this->_graph->legend->SetPos(0.01,0.5,'right','center'); // right |
||||
|
$this->_graph->legend->SetColumns(1); |
||||
|
break; |
||||
|
case 'l' : |
||||
|
$this->_graph->legend->SetPos(0.01,0.5,'left','center'); // left |
||||
|
$this->_graph->legend->SetColumns(1); |
||||
|
break; |
||||
|
case 't' : |
||||
|
$this->_graph->legend->SetPos(0.5,0.01,'center','top'); // top |
||||
|
break; |
||||
|
case 'b' : |
||||
|
$this->_graph->legend->SetPos(0.5,0.99,'center','bottom'); // bottom |
||||
|
break; |
||||
|
default : |
||||
|
$this->_graph->legend->SetPos(0.01,0.01,'right','top'); // top-right |
||||
|
$this->_graph->legend->SetColumns(1); |
||||
|
break; |
||||
|
} |
||||
|
} else { |
||||
|
$this->_graph->legend->Hide(); |
||||
|
} |
||||
|
} // function _renderLegend() |
||||
|
|
||||
|
|
||||
|
private function _renderCartesianPlotArea($type='textlin') { |
||||
|
$this->_graph = new Graph(self::$_width,self::$_height); |
||||
|
$this->_graph->SetScale($type); |
||||
|
|
||||
|
$this->_renderTitle(); |
||||
|
|
||||
|
// Rotate for bar rather than column chart |
||||
|
$rotation = $this->_chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotDirection(); |
||||
|
$reverse = ($rotation == 'bar') ? true : false; |
||||
|
|
||||
|
$xAxisLabel = $this->_chart->getXAxisLabel(); |
||||
|
if (!is_null($xAxisLabel)) { |
||||
|
$title = $this->_getCaption($xAxisLabel); |
||||
|
if (!is_null($title)) { |
||||
|
$this->_graph->xaxis->SetTitle($title,'center'); |
||||
|
$this->_graph->xaxis->title->SetMargin(35); |
||||
|
if ($reverse) { |
||||
|
$this->_graph->xaxis->title->SetAngle(90); |
||||
|
$this->_graph->xaxis->title->SetMargin(90); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$yAxisLabel = $this->_chart->getYAxisLabel(); |
||||
|
if (!is_null($yAxisLabel)) { |
||||
|
$title = $this->_getCaption($yAxisLabel); |
||||
|
if (!is_null($title)) { |
||||
|
$this->_graph->yaxis->SetTitle($title,'center'); |
||||
|
if ($reverse) { |
||||
|
$this->_graph->yaxis->title->SetAngle(0); |
||||
|
$this->_graph->yaxis->title->SetMargin(-55); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} // function _renderCartesianPlotArea() |
||||
|
|
||||
|
|
||||
|
private function _renderPiePlotArea($doughnut = False) { |
||||
|
$this->_graph = new PieGraph(self::$_width,self::$_height); |
||||
|
|
||||
|
$this->_renderTitle(); |
||||
|
} // function _renderPiePlotArea() |
||||
|
|
||||
|
|
||||
|
private function _renderRadarPlotArea() { |
||||
|
$this->_graph = new RadarGraph(self::$_width,self::$_height); |
||||
|
$this->_graph->SetScale('lin'); |
||||
|
|
||||
|
$this->_renderTitle(); |
||||
|
} // function _renderRadarPlotArea() |
||||
|
|
||||
|
|
||||
|
private function _renderPlotLine($groupID, $filled = false, $combination = false, $dimensions = '2d') { |
||||
|
$grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping(); |
||||
|
|
||||
|
$labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount()); |
||||
|
if ($labelCount > 0) { |
||||
|
$datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues(); |
||||
|
$datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount); |
||||
|
$this->_graph->xaxis->SetTickLabels($datasetLabels); |
||||
|
} |
||||
|
|
||||
|
$seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount(); |
||||
|
$seriesPlots = array(); |
||||
|
if ($grouping == 'percentStacked') { |
||||
|
$sumValues = $this->_percentageSumCalculation($groupID,$seriesCount); |
||||
|
} |
||||
|
|
||||
|
// Loop through each data series in turn |
||||
|
for($i = 0; $i < $seriesCount; ++$i) { |
||||
|
$dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues(); |
||||
|
$marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker(); |
||||
|
|
||||
|
if ($grouping == 'percentStacked') { |
||||
|
$dataValues = $this->_percentageAdjustValues($dataValues,$sumValues); |
||||
|
} |
||||
|
|
||||
|
// Fill in any missing values in the $dataValues array |
||||
|
$testCurrentIndex = 0; |
||||
|
foreach($dataValues as $k => $dataValue) { |
||||
|
while($k != $testCurrentIndex) { |
||||
|
$dataValues[$testCurrentIndex] = null; |
||||
|
++$testCurrentIndex; |
||||
|
} |
||||
|
++$testCurrentIndex; |
||||
|
} |
||||
|
|
||||
|
$seriesPlot = new LinePlot($dataValues); |
||||
|
if ($combination) { |
||||
|
$seriesPlot->SetBarCenter(); |
||||
|
} |
||||
|
|
||||
|
if ($filled) { |
||||
|
$seriesPlot->SetFilled(true); |
||||
|
$seriesPlot->SetColor('black'); |
||||
|
$seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour++]); |
||||
|
} else { |
||||
|
// Set the appropriate plot marker |
||||
|
$this->_formatPointMarker($seriesPlot,$marker); |
||||
|
} |
||||
|
$dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue(); |
||||
|
$seriesPlot->SetLegend($dataLabel); |
||||
|
|
||||
|
$seriesPlots[] = $seriesPlot; |
||||
|
} |
||||
|
|
||||
|
if ($grouping == 'standard') { |
||||
|
$groupPlot = $seriesPlots; |
||||
|
} else { |
||||
|
$groupPlot = new AccLinePlot($seriesPlots); |
||||
|
} |
||||
|
$this->_graph->Add($groupPlot); |
||||
|
} // function _renderPlotLine() |
||||
|
|
||||
|
|
||||
|
private function _renderPlotBar($groupID, $dimensions = '2d') { |
||||
|
$rotation = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotDirection(); |
||||
|
// Rotate for bar rather than column chart |
||||
|
if (($groupID == 0) && ($rotation == 'bar')) { |
||||
|
$this->_graph->Set90AndMargin(); |
||||
|
} |
||||
|
$grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping(); |
||||
|
|
||||
|
$labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount()); |
||||
|
if ($labelCount > 0) { |
||||
|
$datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues(); |
||||
|
$datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation); |
||||
|
// Rotate for bar rather than column chart |
||||
|
if ($rotation == 'bar') { |
||||
|
$datasetLabels = array_reverse($datasetLabels); |
||||
|
$this->_graph->yaxis->SetPos('max'); |
||||
|
$this->_graph->yaxis->SetLabelAlign('center','top'); |
||||
|
$this->_graph->yaxis->SetLabelSide(SIDE_RIGHT); |
||||
|
} |
||||
|
$this->_graph->xaxis->SetTickLabels($datasetLabels); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
$seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount(); |
||||
|
$seriesPlots = array(); |
||||
|
if ($grouping == 'percentStacked') { |
||||
|
$sumValues = $this->_percentageSumCalculation($groupID,$seriesCount); |
||||
|
} |
||||
|
|
||||
|
// Loop through each data series in turn |
||||
|
for($j = 0; $j < $seriesCount; ++$j) { |
||||
|
$dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($j)->getDataValues(); |
||||
|
if ($grouping == 'percentStacked') { |
||||
|
$dataValues = $this->_percentageAdjustValues($dataValues,$sumValues); |
||||
|
} |
||||
|
|
||||
|
// Fill in any missing values in the $dataValues array |
||||
|
$testCurrentIndex = 0; |
||||
|
foreach($dataValues as $k => $dataValue) { |
||||
|
while($k != $testCurrentIndex) { |
||||
|
$dataValues[$testCurrentIndex] = null; |
||||
|
++$testCurrentIndex; |
||||
|
} |
||||
|
++$testCurrentIndex; |
||||
|
} |
||||
|
|
||||
|
// Reverse the $dataValues order for bar rather than column chart |
||||
|
if ($rotation == 'bar') { |
||||
|
$dataValues = array_reverse($dataValues); |
||||
|
} |
||||
|
$seriesPlot = new BarPlot($dataValues); |
||||
|
$seriesPlot->SetColor('black'); |
||||
|
$seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour++]); |
||||
|
if ($dimensions == '3d') { |
||||
|
$seriesPlot->SetShadow(); |
||||
|
} |
||||
|
if (!$this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)) { |
||||
|
$dataLabel = ''; |
||||
|
} else { |
||||
|
$dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)->getDataValue(); |
||||
|
} |
||||
|
$seriesPlot->SetLegend($dataLabel); |
||||
|
|
||||
|
$seriesPlots[] = $seriesPlot; |
||||
|
} |
||||
|
// Reverse the plot order for bar rather than column chart |
||||
|
if (($rotation == 'bar') && (!($grouping == 'percentStacked'))) { |
||||
|
$seriesPlots = array_reverse($seriesPlots); |
||||
|
} |
||||
|
|
||||
|
if ($grouping == 'clustered') { |
||||
|
$groupPlot = new GroupBarPlot($seriesPlots); |
||||
|
} elseif ($grouping == 'standard') { |
||||
|
$groupPlot = new GroupBarPlot($seriesPlots); |
||||
|
} else { |
||||
|
$groupPlot = new AccBarPlot($seriesPlots); |
||||
|
if ($dimensions == '3d') { |
||||
|
$groupPlot->SetShadow(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$this->_graph->Add($groupPlot); |
||||
|
} // function _renderPlotBar() |
||||
|
|
||||
|
|
||||
|
private function _renderPlotScatter($groupID,$bubble) { |
||||
|
$grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping(); |
||||
|
$scatterStyle = $bubbleSize = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle(); |
||||
|
|
||||
|
$seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount(); |
||||
|
$seriesPlots = array(); |
||||
|
|
||||
|
// Loop through each data series in turn |
||||
|
for($i = 0; $i < $seriesCount; ++$i) { |
||||
|
$dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues(); |
||||
|
$dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues(); |
||||
|
|
||||
|
foreach($dataValuesY as $k => $dataValueY) { |
||||
|
$dataValuesY[$k] = $k; |
||||
|
} |
||||
|
|
||||
|
$seriesPlot = new ScatterPlot($dataValuesX,$dataValuesY); |
||||
|
if ($scatterStyle == 'lineMarker') { |
||||
|
$seriesPlot->SetLinkPoints(); |
||||
|
$seriesPlot->link->SetColor(self::$_colourSet[self::$_plotColour]); |
||||
|
} elseif ($scatterStyle == 'smoothMarker') { |
||||
|
$spline = new Spline($dataValuesY,$dataValuesX); |
||||
|
list($splineDataY,$splineDataX) = $spline->Get(count($dataValuesX) * self::$_width / 20); |
||||
|
$lplot = new LinePlot($splineDataX,$splineDataY); |
||||
|
$lplot->SetColor(self::$_colourSet[self::$_plotColour]); |
||||
|
|
||||
|
$this->_graph->Add($lplot); |
||||
|
} |
||||
|
|
||||
|
if ($bubble) { |
||||
|
$this->_formatPointMarker($seriesPlot,'dot'); |
||||
|
$seriesPlot->mark->SetColor('black'); |
||||
|
$seriesPlot->mark->SetSize($bubbleSize); |
||||
|
} else { |
||||
|
$marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker(); |
||||
|
$this->_formatPointMarker($seriesPlot,$marker); |
||||
|
} |
||||
|
$dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue(); |
||||
|
$seriesPlot->SetLegend($dataLabel); |
||||
|
|
||||
|
$this->_graph->Add($seriesPlot); |
||||
|
} |
||||
|
} // function _renderPlotScatter() |
||||
|
|
||||
|
|
||||
|
private function _renderPlotRadar($groupID) { |
||||
|
$radarStyle = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle(); |
||||
|
|
||||
|
$seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount(); |
||||
|
$seriesPlots = array(); |
||||
|
|
||||
|
// Loop through each data series in turn |
||||
|
for($i = 0; $i < $seriesCount; ++$i) { |
||||
|
$dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues(); |
||||
|
$dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues(); |
||||
|
$marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker(); |
||||
|
|
||||
|
$dataValues = array(); |
||||
|
foreach($dataValuesY as $k => $dataValueY) { |
||||
|
$dataValues[$k] = implode(' ',array_reverse($dataValueY)); |
||||
|
} |
||||
|
$tmp = array_shift($dataValues); |
||||
|
$dataValues[] = $tmp; |
||||
|
$tmp = array_shift($dataValuesX); |
||||
|
$dataValuesX[] = $tmp; |
||||
|
|
||||
|
$this->_graph->SetTitles(array_reverse($dataValues)); |
||||
|
|
||||
|
$seriesPlot = new RadarPlot(array_reverse($dataValuesX)); |
||||
|
|
||||
|
$dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue(); |
||||
|
$seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]); |
||||
|
if ($radarStyle == 'filled') { |
||||
|
$seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour]); |
||||
|
} |
||||
|
$this->_formatPointMarker($seriesPlot,$marker); |
||||
|
$seriesPlot->SetLegend($dataLabel); |
||||
|
|
||||
|
$this->_graph->Add($seriesPlot); |
||||
|
} |
||||
|
} // function _renderPlotRadar() |
||||
|
|
||||
|
|
||||
|
private function _renderPlotContour($groupID) { |
||||
|
$contourStyle = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle(); |
||||
|
|
||||
|
$seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount(); |
||||
|
$seriesPlots = array(); |
||||
|
|
||||
|
$dataValues = array(); |
||||
|
// Loop through each data series in turn |
||||
|
for($i = 0; $i < $seriesCount; ++$i) { |
||||
|
$dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues(); |
||||
|
$dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues(); |
||||
|
|
||||
|
$dataValues[$i] = $dataValuesX; |
||||
|
} |
||||
|
$seriesPlot = new ContourPlot($dataValues); |
||||
|
|
||||
|
$this->_graph->Add($seriesPlot); |
||||
|
} // function _renderPlotContour() |
||||
|
|
||||
|
|
||||
|
private function _renderPlotStock($groupID) { |
||||
|
$seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount(); |
||||
|
$plotOrder = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotOrder(); |
||||
|
$seriesPlots = array(); |
||||
|
|
||||
|
$dataValues = array(); |
||||
|
// Loop through each data series in turn |
||||
|
for($i = 0; $i < $seriesCount; ++$i) { |
||||
|
$dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues(); |
||||
|
$dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues(); |
||||
|
|
||||
|
foreach($dataValuesX as $j => $dataValueX) |
||||
|
$dataValues[$j][$plotOrder[$i]] = $dataValueX; |
||||
|
} |
||||
|
|
||||
|
$seriesPlot = new StockPlot($dataValues); |
||||
|
|
||||
|
$this->_graph->Add($seriesPlot); |
||||
|
} // function _renderPlotStock() |
||||
|
|
||||
|
|
||||
|
private function _renderAreaChart($groupCount, $dimensions = '2d') { |
||||
|
require_once('jpgraph_line.php'); |
||||
|
|
||||
|
$this->_renderCartesianPlotArea(); |
||||
|
|
||||
|
for($i = 0; $i < $groupCount; ++$i) { |
||||
|
$this->_renderPlotLine($i,True,False,$dimensions); |
||||
|
} |
||||
|
} // function _renderAreaChart() |
||||
|
|
||||
|
|
||||
|
private function _renderLineChart($groupCount, $dimensions = '2d') { |
||||
|
require_once('jpgraph_line.php'); |
||||
|
|
||||
|
$this->_renderCartesianPlotArea(); |
||||
|
|
||||
|
for($i = 0; $i < $groupCount; ++$i) { |
||||
|
$this->_renderPlotLine($i,False,False,$dimensions); |
||||
|
} |
||||
|
} // function _renderLineChart() |
||||
|
|
||||
|
|
||||
|
private function _renderBarChart($groupCount, $dimensions = '2d') { |
||||
|
require_once('jpgraph_bar.php'); |
||||
|
|
||||
|
$this->_renderCartesianPlotArea(); |
||||
|
|
||||
|
for($i = 0; $i < $groupCount; ++$i) { |
||||
|
$this->_renderPlotBar($i,$dimensions); |
||||
|
} |
||||
|
} // function _renderBarChart() |
||||
|
|
||||
|
|
||||
|
private function _renderScatterChart($groupCount) { |
||||
|
require_once('jpgraph_scatter.php'); |
||||
|
require_once('jpgraph_regstat.php'); |
||||
|
require_once('jpgraph_line.php'); |
||||
|
|
||||
|
$this->_renderCartesianPlotArea('linlin'); |
||||
|
|
||||
|
for($i = 0; $i < $groupCount; ++$i) { |
||||
|
$this->_renderPlotScatter($i,false); |
||||
|
} |
||||
|
} // function _renderScatterChart() |
||||
|
|
||||
|
|
||||
|
private function _renderBubbleChart($groupCount) { |
||||
|
require_once('jpgraph_scatter.php'); |
||||
|
|
||||
|
$this->_renderCartesianPlotArea('linlin'); |
||||
|
|
||||
|
for($i = 0; $i < $groupCount; ++$i) { |
||||
|
$this->_renderPlotScatter($i,true); |
||||
|
} |
||||
|
} // function _renderBubbleChart() |
||||
|
|
||||
|
|
||||
|
private function _renderPieChart($groupCount, $dimensions = '2d', $doughnut = False, $multiplePlots = False) { |
||||
|
require_once('jpgraph_pie.php'); |
||||
|
if ($dimensions == '3d') { |
||||
|
require_once('jpgraph_pie3d.php'); |
||||
|
} |
||||
|
|
||||
|
$this->_renderPiePlotArea($doughnut); |
||||
|
|
||||
|
$iLimit = ($multiplePlots) ? $groupCount : 1; |
||||
|
for($groupID = 0; $groupID < $iLimit; ++$groupID) { |
||||
|
$grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping(); |
||||
|
$exploded = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle(); |
||||
|
if ($groupID == 0) { |
||||
|
$labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount()); |
||||
|
if ($labelCount > 0) { |
||||
|
$datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues(); |
||||
|
$datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount(); |
||||
|
$seriesPlots = array(); |
||||
|
// For pie charts, we only display the first series: doughnut charts generally display all series |
||||
|
$jLimit = ($multiplePlots) ? $seriesCount : 1; |
||||
|
// Loop through each data series in turn |
||||
|
for($j = 0; $j < $jLimit; ++$j) { |
||||
|
$dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($j)->getDataValues(); |
||||
|
|
||||
|
// Fill in any missing values in the $dataValues array |
||||
|
$testCurrentIndex = 0; |
||||
|
foreach($dataValues as $k => $dataValue) { |
||||
|
while($k != $testCurrentIndex) { |
||||
|
$dataValues[$testCurrentIndex] = null; |
||||
|
++$testCurrentIndex; |
||||
|
} |
||||
|
++$testCurrentIndex; |
||||
|
} |
||||
|
|
||||
|
if ($dimensions == '3d') { |
||||
|
$seriesPlot = new PiePlot3D($dataValues); |
||||
|
} else { |
||||
|
if ($doughnut) { |
||||
|
$seriesPlot = new PiePlotC($dataValues); |
||||
|
} else { |
||||
|
$seriesPlot = new PiePlot($dataValues); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if ($multiplePlots) { |
||||
|
$seriesPlot->SetSize(($jLimit-$j) / ($jLimit * 4)); |
||||
|
} |
||||
|
|
||||
|
if ($doughnut) { |
||||
|
$seriesPlot->SetMidColor('white'); |
||||
|
} |
||||
|
|
||||
|
$seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]); |
||||
|
if (count($datasetLabels) > 0) |
||||
|
$seriesPlot->SetLabels(array_fill(0,count($datasetLabels),'')); |
||||
|
if ($dimensions != '3d') { |
||||
|
$seriesPlot->SetGuideLines(false); |
||||
|
} |
||||
|
if ($j == 0) { |
||||
|
if ($exploded) { |
||||
|
$seriesPlot->ExplodeAll(); |
||||
|
} |
||||
|
$seriesPlot->SetLegends($datasetLabels); |
||||
|
} |
||||
|
|
||||
|
$this->_graph->Add($seriesPlot); |
||||
|
} |
||||
|
} |
||||
|
} // function _renderPieChart() |
||||
|
|
||||
|
|
||||
|
private function _renderRadarChart($groupCount) { |
||||
|
require_once('jpgraph_radar.php'); |
||||
|
|
||||
|
$this->_renderRadarPlotArea(); |
||||
|
|
||||
|
for($groupID = 0; $groupID < $groupCount; ++$groupID) { |
||||
|
$this->_renderPlotRadar($groupID); |
||||
|
} |
||||
|
} // function _renderRadarChart() |
||||
|
|
||||
|
|
||||
|
private function _renderStockChart($groupCount) { |
||||
|
require_once('jpgraph_stock.php'); |
||||
|
|
||||
|
$this->_renderCartesianPlotArea(); |
||||
|
|
||||
|
for($groupID = 0; $groupID < $groupCount; ++$i) { |
||||
|
$this->_renderPlotStock($groupID); |
||||
|
} |
||||
|
} // function _renderStockChart() |
||||
|
|
||||
|
|
||||
|
private function _renderContourChart($groupCount,$dimensions) { |
||||
|
require_once('jpgraph_contour.php'); |
||||
|
|
||||
|
$this->_renderCartesianPlotArea('intint'); |
||||
|
|
||||
|
for($i = 0; $i < $groupCount; ++$i) { |
||||
|
$this->_renderPlotContour($i); |
||||
|
} |
||||
|
} // function _renderContourChart() |
||||
|
|
||||
|
|
||||
|
private function _renderCombinationChart($groupCount,$dimensions,$outputDestination) { |
||||
|
require_once('jpgraph_line.php'); |
||||
|
require_once('jpgraph_bar.php'); |
||||
|
require_once('jpgraph_scatter.php'); |
||||
|
require_once('jpgraph_regstat.php'); |
||||
|
require_once('jpgraph_line.php'); |
||||
|
|
||||
|
$this->_renderCartesianPlotArea(); |
||||
|
|
||||
|
for($i = 0; $i < $groupCount; ++$i) { |
||||
|
$dimensions = null; |
||||
|
$chartType = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType(); |
||||
|
switch ($chartType) { |
||||
|
case 'area3DChart' : |
||||
|
$dimensions = '3d'; |
||||
|
case 'areaChart' : |
||||
|
$this->_renderPlotLine($i,True,True,$dimensions); |
||||
|
break; |
||||
|
case 'bar3DChart' : |
||||
|
$dimensions = '3d'; |
||||
|
case 'barChart' : |
||||
|
$this->_renderPlotBar($i,$dimensions); |
||||
|
break; |
||||
|
case 'line3DChart' : |
||||
|
$dimensions = '3d'; |
||||
|
case 'lineChart' : |
||||
|
$this->_renderPlotLine($i,False,True,$dimensions); |
||||
|
break; |
||||
|
case 'scatterChart' : |
||||
|
$this->_renderPlotScatter($i,false); |
||||
|
break; |
||||
|
case 'bubbleChart' : |
||||
|
$this->_renderPlotScatter($i,true); |
||||
|
break; |
||||
|
default : |
||||
|
$this->_graph = null; |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$this->_renderLegend(); |
||||
|
|
||||
|
$this->_graph->Stroke($outputDestination); |
||||
|
return true; |
||||
|
} // function _renderCombinationChart() |
||||
|
|
||||
|
|
||||
|
public function render($outputDestination) { |
||||
|
self::$_plotColour = 0; |
||||
|
|
||||
|
$groupCount = $this->_chart->getPlotArea()->getPlotGroupCount(); |
||||
|
|
||||
|
$dimensions = null; |
||||
|
if ($groupCount == 1) { |
||||
|
$chartType = $this->_chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType(); |
||||
|
} else { |
||||
|
$chartTypes = array(); |
||||
|
for($i = 0; $i < $groupCount; ++$i) { |
||||
|
$chartTypes[] = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType(); |
||||
|
} |
||||
|
$chartTypes = array_unique($chartTypes); |
||||
|
if (count($chartTypes) == 1) { |
||||
|
$chartType = array_pop($chartTypes); |
||||
|
} elseif (count($chartTypes) == 0) { |
||||
|
echo 'Chart is not yet implemented<br />'; |
||||
|
return false; |
||||
|
} else { |
||||
|
return $this->_renderCombinationChart($groupCount,$dimensions,$outputDestination); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
switch ($chartType) { |
||||
|
case 'area3DChart' : |
||||
|
$dimensions = '3d'; |
||||
|
case 'areaChart' : |
||||
|
$this->_renderAreaChart($groupCount,$dimensions); |
||||
|
break; |
||||
|
case 'bar3DChart' : |
||||
|
$dimensions = '3d'; |
||||
|
case 'barChart' : |
||||
|
$this->_renderBarChart($groupCount,$dimensions); |
||||
|
break; |
||||
|
case 'line3DChart' : |
||||
|
$dimensions = '3d'; |
||||
|
case 'lineChart' : |
||||
|
$this->_renderLineChart($groupCount,$dimensions); |
||||
|
break; |
||||
|
case 'pie3DChart' : |
||||
|
$dimensions = '3d'; |
||||
|
case 'pieChart' : |
||||
|
$this->_renderPieChart($groupCount,$dimensions,False,False); |
||||
|
break; |
||||
|
case 'doughnut3DChart' : |
||||
|
$dimensions = '3d'; |
||||
|
case 'doughnutChart' : |
||||
|
$this->_renderPieChart($groupCount,$dimensions,True,True); |
||||
|
break; |
||||
|
case 'scatterChart' : |
||||
|
$this->_renderScatterChart($groupCount); |
||||
|
break; |
||||
|
case 'bubbleChart' : |
||||
|
$this->_renderBubbleChart($groupCount); |
||||
|
break; |
||||
|
case 'radarChart' : |
||||
|
$this->_renderRadarChart($groupCount); |
||||
|
break; |
||||
|
case 'surface3DChart' : |
||||
|
$dimensions = '3d'; |
||||
|
case 'surfaceChart' : |
||||
|
$this->_renderContourChart($groupCount,$dimensions); |
||||
|
break; |
||||
|
case 'stockChart' : |
||||
|
$this->_renderStockChart($groupCount,$dimensions); |
||||
|
break; |
||||
|
default : |
||||
|
echo $chartType.' is not yet implemented<br />'; |
||||
|
return false; |
||||
|
} |
||||
|
$this->_renderLegend(); |
||||
|
|
||||
|
$this->_graph->Stroke($outputDestination); |
||||
|
return true; |
||||
|
} // function render() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Chart_Renderer_jpgraph |
||||
|
*/ |
||||
|
public function __construct(PHPExcel_Chart $chart) |
||||
|
{ |
||||
|
$this->_graph = null; |
||||
|
$this->_chart = $chart; |
||||
|
} // function __construct() |
||||
|
|
||||
|
} // PHPExcel_Chart_Renderer_jpgraph |
||||
@ -0,0 +1,89 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Chart_Title |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Chart |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Chart_Title |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* Title Caption |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_caption = null; |
||||
|
|
||||
|
/** |
||||
|
* Title Layout |
||||
|
* |
||||
|
* @var PHPExcel_Chart_Layout |
||||
|
*/ |
||||
|
private $_layout = null; |
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Chart_Title |
||||
|
*/ |
||||
|
public function __construct($caption = null, PHPExcel_Chart_Layout $layout = null) |
||||
|
{ |
||||
|
$this->_caption = $caption; |
||||
|
$this->_layout = $layout; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get caption |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getCaption() { |
||||
|
return $this->_caption; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set caption |
||||
|
* |
||||
|
* @param string $caption |
||||
|
*/ |
||||
|
public function setCaption($caption = null) { |
||||
|
$this->_caption = $caption; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Layout |
||||
|
* |
||||
|
* @return PHPExcel_Chart_Layout |
||||
|
*/ |
||||
|
public function getLayout() { |
||||
|
return $this->_layout; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,808 @@ |
|||||
|
<?php |
||||
|
|
||||
|
class PHPExcel_Helper_HTML |
||||
|
{ |
||||
|
protected static $colourMap = array( |
||||
|
'aliceblue' => 'f0f8ff', |
||||
|
'antiquewhite' => 'faebd7', |
||||
|
'antiquewhite1' => 'ffefdb', |
||||
|
'antiquewhite2' => 'eedfcc', |
||||
|
'antiquewhite3' => 'cdc0b0', |
||||
|
'antiquewhite4' => '8b8378', |
||||
|
'aqua' => '00ffff', |
||||
|
'aquamarine1' => '7fffd4', |
||||
|
'aquamarine2' => '76eec6', |
||||
|
'aquamarine4' => '458b74', |
||||
|
'azure1' => 'f0ffff', |
||||
|
'azure2' => 'e0eeee', |
||||
|
'azure3' => 'c1cdcd', |
||||
|
'azure4' => '838b8b', |
||||
|
'beige' => 'f5f5dc', |
||||
|
'bisque1' => 'ffe4c4', |
||||
|
'bisque2' => 'eed5b7', |
||||
|
'bisque3' => 'cdb79e', |
||||
|
'bisque4' => '8b7d6b', |
||||
|
'black' => '000000', |
||||
|
'blanchedalmond' => 'ffebcd', |
||||
|
'blue' => '0000ff', |
||||
|
'blue1' => '0000ff', |
||||
|
'blue2' => '0000ee', |
||||
|
'blue4' => '00008b', |
||||
|
'blueviolet' => '8a2be2', |
||||
|
'brown' => 'a52a2a', |
||||
|
'brown1' => 'ff4040', |
||||
|
'brown2' => 'ee3b3b', |
||||
|
'brown3' => 'cd3333', |
||||
|
'brown4' => '8b2323', |
||||
|
'burlywood' => 'deb887', |
||||
|
'burlywood1' => 'ffd39b', |
||||
|
'burlywood2' => 'eec591', |
||||
|
'burlywood3' => 'cdaa7d', |
||||
|
'burlywood4' => '8b7355', |
||||
|
'cadetblue' => '5f9ea0', |
||||
|
'cadetblue1' => '98f5ff', |
||||
|
'cadetblue2' => '8ee5ee', |
||||
|
'cadetblue3' => '7ac5cd', |
||||
|
'cadetblue4' => '53868b', |
||||
|
'chartreuse1' => '7fff00', |
||||
|
'chartreuse2' => '76ee00', |
||||
|
'chartreuse3' => '66cd00', |
||||
|
'chartreuse4' => '458b00', |
||||
|
'chocolate' => 'd2691e', |
||||
|
'chocolate1' => 'ff7f24', |
||||
|
'chocolate2' => 'ee7621', |
||||
|
'chocolate3' => 'cd661d', |
||||
|
'coral' => 'ff7f50', |
||||
|
'coral1' => 'ff7256', |
||||
|
'coral2' => 'ee6a50', |
||||
|
'coral3' => 'cd5b45', |
||||
|
'coral4' => '8b3e2f', |
||||
|
'cornflowerblue' => '6495ed', |
||||
|
'cornsilk1' => 'fff8dc', |
||||
|
'cornsilk2' => 'eee8cd', |
||||
|
'cornsilk3' => 'cdc8b1', |
||||
|
'cornsilk4' => '8b8878', |
||||
|
'cyan1' => '00ffff', |
||||
|
'cyan2' => '00eeee', |
||||
|
'cyan3' => '00cdcd', |
||||
|
'cyan4' => '008b8b', |
||||
|
'darkgoldenrod' => 'b8860b', |
||||
|
'darkgoldenrod1' => 'ffb90f', |
||||
|
'darkgoldenrod2' => 'eead0e', |
||||
|
'darkgoldenrod3' => 'cd950c', |
||||
|
'darkgoldenrod4' => '8b6508', |
||||
|
'darkgreen' => '006400', |
||||
|
'darkkhaki' => 'bdb76b', |
||||
|
'darkolivegreen' => '556b2f', |
||||
|
'darkolivegreen1' => 'caff70', |
||||
|
'darkolivegreen2' => 'bcee68', |
||||
|
'darkolivegreen3' => 'a2cd5a', |
||||
|
'darkolivegreen4' => '6e8b3d', |
||||
|
'darkorange' => 'ff8c00', |
||||
|
'darkorange1' => 'ff7f00', |
||||
|
'darkorange2' => 'ee7600', |
||||
|
'darkorange3' => 'cd6600', |
||||
|
'darkorange4' => '8b4500', |
||||
|
'darkorchid' => '9932cc', |
||||
|
'darkorchid1' => 'bf3eff', |
||||
|
'darkorchid2' => 'b23aee', |
||||
|
'darkorchid3' => '9a32cd', |
||||
|
'darkorchid4' => '68228b', |
||||
|
'darksalmon' => 'e9967a', |
||||
|
'darkseagreen' => '8fbc8f', |
||||
|
'darkseagreen1' => 'c1ffc1', |
||||
|
'darkseagreen2' => 'b4eeb4', |
||||
|
'darkseagreen3' => '9bcd9b', |
||||
|
'darkseagreen4' => '698b69', |
||||
|
'darkslateblue' => '483d8b', |
||||
|
'darkslategray' => '2f4f4f', |
||||
|
'darkslategray1' => '97ffff', |
||||
|
'darkslategray2' => '8deeee', |
||||
|
'darkslategray3' => '79cdcd', |
||||
|
'darkslategray4' => '528b8b', |
||||
|
'darkturquoise' => '00ced1', |
||||
|
'darkviolet' => '9400d3', |
||||
|
'deeppink1' => 'ff1493', |
||||
|
'deeppink2' => 'ee1289', |
||||
|
'deeppink3' => 'cd1076', |
||||
|
'deeppink4' => '8b0a50', |
||||
|
'deepskyblue1' => '00bfff', |
||||
|
'deepskyblue2' => '00b2ee', |
||||
|
'deepskyblue3' => '009acd', |
||||
|
'deepskyblue4' => '00688b', |
||||
|
'dimgray' => '696969', |
||||
|
'dodgerblue1' => '1e90ff', |
||||
|
'dodgerblue2' => '1c86ee', |
||||
|
'dodgerblue3' => '1874cd', |
||||
|
'dodgerblue4' => '104e8b', |
||||
|
'firebrick' => 'b22222', |
||||
|
'firebrick1' => 'ff3030', |
||||
|
'firebrick2' => 'ee2c2c', |
||||
|
'firebrick3' => 'cd2626', |
||||
|
'firebrick4' => '8b1a1a', |
||||
|
'floralwhite' => 'fffaf0', |
||||
|
'forestgreen' => '228b22', |
||||
|
'fuchsia' => 'ff00ff', |
||||
|
'gainsboro' => 'dcdcdc', |
||||
|
'ghostwhite' => 'f8f8ff', |
||||
|
'gold1' => 'ffd700', |
||||
|
'gold2' => 'eec900', |
||||
|
'gold3' => 'cdad00', |
||||
|
'gold4' => '8b7500', |
||||
|
'goldenrod' => 'daa520', |
||||
|
'goldenrod1' => 'ffc125', |
||||
|
'goldenrod2' => 'eeb422', |
||||
|
'goldenrod3' => 'cd9b1d', |
||||
|
'goldenrod4' => '8b6914', |
||||
|
'gray' => 'bebebe', |
||||
|
'gray1' => '030303', |
||||
|
'gray10' => '1a1a1a', |
||||
|
'gray11' => '1c1c1c', |
||||
|
'gray12' => '1f1f1f', |
||||
|
'gray13' => '212121', |
||||
|
'gray14' => '242424', |
||||
|
'gray15' => '262626', |
||||
|
'gray16' => '292929', |
||||
|
'gray17' => '2b2b2b', |
||||
|
'gray18' => '2e2e2e', |
||||
|
'gray19' => '303030', |
||||
|
'gray2' => '050505', |
||||
|
'gray20' => '333333', |
||||
|
'gray21' => '363636', |
||||
|
'gray22' => '383838', |
||||
|
'gray23' => '3b3b3b', |
||||
|
'gray24' => '3d3d3d', |
||||
|
'gray25' => '404040', |
||||
|
'gray26' => '424242', |
||||
|
'gray27' => '454545', |
||||
|
'gray28' => '474747', |
||||
|
'gray29' => '4a4a4a', |
||||
|
'gray3' => '080808', |
||||
|
'gray30' => '4d4d4d', |
||||
|
'gray31' => '4f4f4f', |
||||
|
'gray32' => '525252', |
||||
|
'gray33' => '545454', |
||||
|
'gray34' => '575757', |
||||
|
'gray35' => '595959', |
||||
|
'gray36' => '5c5c5c', |
||||
|
'gray37' => '5e5e5e', |
||||
|
'gray38' => '616161', |
||||
|
'gray39' => '636363', |
||||
|
'gray4' => '0a0a0a', |
||||
|
'gray40' => '666666', |
||||
|
'gray41' => '696969', |
||||
|
'gray42' => '6b6b6b', |
||||
|
'gray43' => '6e6e6e', |
||||
|
'gray44' => '707070', |
||||
|
'gray45' => '737373', |
||||
|
'gray46' => '757575', |
||||
|
'gray47' => '787878', |
||||
|
'gray48' => '7a7a7a', |
||||
|
'gray49' => '7d7d7d', |
||||
|
'gray5' => '0d0d0d', |
||||
|
'gray50' => '7f7f7f', |
||||
|
'gray51' => '828282', |
||||
|
'gray52' => '858585', |
||||
|
'gray53' => '878787', |
||||
|
'gray54' => '8a8a8a', |
||||
|
'gray55' => '8c8c8c', |
||||
|
'gray56' => '8f8f8f', |
||||
|
'gray57' => '919191', |
||||
|
'gray58' => '949494', |
||||
|
'gray59' => '969696', |
||||
|
'gray6' => '0f0f0f', |
||||
|
'gray60' => '999999', |
||||
|
'gray61' => '9c9c9c', |
||||
|
'gray62' => '9e9e9e', |
||||
|
'gray63' => 'a1a1a1', |
||||
|
'gray64' => 'a3a3a3', |
||||
|
'gray65' => 'a6a6a6', |
||||
|
'gray66' => 'a8a8a8', |
||||
|
'gray67' => 'ababab', |
||||
|
'gray68' => 'adadad', |
||||
|
'gray69' => 'b0b0b0', |
||||
|
'gray7' => '121212', |
||||
|
'gray70' => 'b3b3b3', |
||||
|
'gray71' => 'b5b5b5', |
||||
|
'gray72' => 'b8b8b8', |
||||
|
'gray73' => 'bababa', |
||||
|
'gray74' => 'bdbdbd', |
||||
|
'gray75' => 'bfbfbf', |
||||
|
'gray76' => 'c2c2c2', |
||||
|
'gray77' => 'c4c4c4', |
||||
|
'gray78' => 'c7c7c7', |
||||
|
'gray79' => 'c9c9c9', |
||||
|
'gray8' => '141414', |
||||
|
'gray80' => 'cccccc', |
||||
|
'gray81' => 'cfcfcf', |
||||
|
'gray82' => 'd1d1d1', |
||||
|
'gray83' => 'd4d4d4', |
||||
|
'gray84' => 'd6d6d6', |
||||
|
'gray85' => 'd9d9d9', |
||||
|
'gray86' => 'dbdbdb', |
||||
|
'gray87' => 'dedede', |
||||
|
'gray88' => 'e0e0e0', |
||||
|
'gray89' => 'e3e3e3', |
||||
|
'gray9' => '171717', |
||||
|
'gray90' => 'e5e5e5', |
||||
|
'gray91' => 'e8e8e8', |
||||
|
'gray92' => 'ebebeb', |
||||
|
'gray93' => 'ededed', |
||||
|
'gray94' => 'f0f0f0', |
||||
|
'gray95' => 'f2f2f2', |
||||
|
'gray97' => 'f7f7f7', |
||||
|
'gray98' => 'fafafa', |
||||
|
'gray99' => 'fcfcfc', |
||||
|
'green' => '00ff00', |
||||
|
'green1' => '00ff00', |
||||
|
'green2' => '00ee00', |
||||
|
'green3' => '00cd00', |
||||
|
'green4' => '008b00', |
||||
|
'greenyellow' => 'adff2f', |
||||
|
'honeydew1' => 'f0fff0', |
||||
|
'honeydew2' => 'e0eee0', |
||||
|
'honeydew3' => 'c1cdc1', |
||||
|
'honeydew4' => '838b83', |
||||
|
'hotpink' => 'ff69b4', |
||||
|
'hotpink1' => 'ff6eb4', |
||||
|
'hotpink2' => 'ee6aa7', |
||||
|
'hotpink3' => 'cd6090', |
||||
|
'hotpink4' => '8b3a62', |
||||
|
'indianred' => 'cd5c5c', |
||||
|
'indianred1' => 'ff6a6a', |
||||
|
'indianred2' => 'ee6363', |
||||
|
'indianred3' => 'cd5555', |
||||
|
'indianred4' => '8b3a3a', |
||||
|
'ivory1' => 'fffff0', |
||||
|
'ivory2' => 'eeeee0', |
||||
|
'ivory3' => 'cdcdc1', |
||||
|
'ivory4' => '8b8b83', |
||||
|
'khaki' => 'f0e68c', |
||||
|
'khaki1' => 'fff68f', |
||||
|
'khaki2' => 'eee685', |
||||
|
'khaki3' => 'cdc673', |
||||
|
'khaki4' => '8b864e', |
||||
|
'lavender' => 'e6e6fa', |
||||
|
'lavenderblush1' => 'fff0f5', |
||||
|
'lavenderblush2' => 'eee0e5', |
||||
|
'lavenderblush3' => 'cdc1c5', |
||||
|
'lavenderblush4' => '8b8386', |
||||
|
'lawngreen' => '7cfc00', |
||||
|
'lemonchiffon1' => 'fffacd', |
||||
|
'lemonchiffon2' => 'eee9bf', |
||||
|
'lemonchiffon3' => 'cdc9a5', |
||||
|
'lemonchiffon4' => '8b8970', |
||||
|
'light' => 'eedd82', |
||||
|
'lightblue' => 'add8e6', |
||||
|
'lightblue1' => 'bfefff', |
||||
|
'lightblue2' => 'b2dfee', |
||||
|
'lightblue3' => '9ac0cd', |
||||
|
'lightblue4' => '68838b', |
||||
|
'lightcoral' => 'f08080', |
||||
|
'lightcyan1' => 'e0ffff', |
||||
|
'lightcyan2' => 'd1eeee', |
||||
|
'lightcyan3' => 'b4cdcd', |
||||
|
'lightcyan4' => '7a8b8b', |
||||
|
'lightgoldenrod1' => 'ffec8b', |
||||
|
'lightgoldenrod2' => 'eedc82', |
||||
|
'lightgoldenrod3' => 'cdbe70', |
||||
|
'lightgoldenrod4' => '8b814c', |
||||
|
'lightgoldenrodyellow' => 'fafad2', |
||||
|
'lightgray' => 'd3d3d3', |
||||
|
'lightpink' => 'ffb6c1', |
||||
|
'lightpink1' => 'ffaeb9', |
||||
|
'lightpink2' => 'eea2ad', |
||||
|
'lightpink3' => 'cd8c95', |
||||
|
'lightpink4' => '8b5f65', |
||||
|
'lightsalmon1' => 'ffa07a', |
||||
|
'lightsalmon2' => 'ee9572', |
||||
|
'lightsalmon3' => 'cd8162', |
||||
|
'lightsalmon4' => '8b5742', |
||||
|
'lightseagreen' => '20b2aa', |
||||
|
'lightskyblue' => '87cefa', |
||||
|
'lightskyblue1' => 'b0e2ff', |
||||
|
'lightskyblue2' => 'a4d3ee', |
||||
|
'lightskyblue3' => '8db6cd', |
||||
|
'lightskyblue4' => '607b8b', |
||||
|
'lightslateblue' => '8470ff', |
||||
|
'lightslategray' => '778899', |
||||
|
'lightsteelblue' => 'b0c4de', |
||||
|
'lightsteelblue1' => 'cae1ff', |
||||
|
'lightsteelblue2' => 'bcd2ee', |
||||
|
'lightsteelblue3' => 'a2b5cd', |
||||
|
'lightsteelblue4' => '6e7b8b', |
||||
|
'lightyellow1' => 'ffffe0', |
||||
|
'lightyellow2' => 'eeeed1', |
||||
|
'lightyellow3' => 'cdcdb4', |
||||
|
'lightyellow4' => '8b8b7a', |
||||
|
'lime' => '00ff00', |
||||
|
'limegreen' => '32cd32', |
||||
|
'linen' => 'faf0e6', |
||||
|
'magenta' => 'ff00ff', |
||||
|
'magenta2' => 'ee00ee', |
||||
|
'magenta3' => 'cd00cd', |
||||
|
'magenta4' => '8b008b', |
||||
|
'maroon' => 'b03060', |
||||
|
'maroon1' => 'ff34b3', |
||||
|
'maroon2' => 'ee30a7', |
||||
|
'maroon3' => 'cd2990', |
||||
|
'maroon4' => '8b1c62', |
||||
|
'medium' => '66cdaa', |
||||
|
'mediumaquamarine' => '66cdaa', |
||||
|
'mediumblue' => '0000cd', |
||||
|
'mediumorchid' => 'ba55d3', |
||||
|
'mediumorchid1' => 'e066ff', |
||||
|
'mediumorchid2' => 'd15fee', |
||||
|
'mediumorchid3' => 'b452cd', |
||||
|
'mediumorchid4' => '7a378b', |
||||
|
'mediumpurple' => '9370db', |
||||
|
'mediumpurple1' => 'ab82ff', |
||||
|
'mediumpurple2' => '9f79ee', |
||||
|
'mediumpurple3' => '8968cd', |
||||
|
'mediumpurple4' => '5d478b', |
||||
|
'mediumseagreen' => '3cb371', |
||||
|
'mediumslateblue' => '7b68ee', |
||||
|
'mediumspringgreen' => '00fa9a', |
||||
|
'mediumturquoise' => '48d1cc', |
||||
|
'mediumvioletred' => 'c71585', |
||||
|
'midnightblue' => '191970', |
||||
|
'mintcream' => 'f5fffa', |
||||
|
'mistyrose1' => 'ffe4e1', |
||||
|
'mistyrose2' => 'eed5d2', |
||||
|
'mistyrose3' => 'cdb7b5', |
||||
|
'mistyrose4' => '8b7d7b', |
||||
|
'moccasin' => 'ffe4b5', |
||||
|
'navajowhite1' => 'ffdead', |
||||
|
'navajowhite2' => 'eecfa1', |
||||
|
'navajowhite3' => 'cdb38b', |
||||
|
'navajowhite4' => '8b795e', |
||||
|
'navy' => '000080', |
||||
|
'navyblue' => '000080', |
||||
|
'oldlace' => 'fdf5e6', |
||||
|
'olive' => '808000', |
||||
|
'olivedrab' => '6b8e23', |
||||
|
'olivedrab1' => 'c0ff3e', |
||||
|
'olivedrab2' => 'b3ee3a', |
||||
|
'olivedrab4' => '698b22', |
||||
|
'orange' => 'ffa500', |
||||
|
'orange1' => 'ffa500', |
||||
|
'orange2' => 'ee9a00', |
||||
|
'orange3' => 'cd8500', |
||||
|
'orange4' => '8b5a00', |
||||
|
'orangered1' => 'ff4500', |
||||
|
'orangered2' => 'ee4000', |
||||
|
'orangered3' => 'cd3700', |
||||
|
'orangered4' => '8b2500', |
||||
|
'orchid' => 'da70d6', |
||||
|
'orchid1' => 'ff83fa', |
||||
|
'orchid2' => 'ee7ae9', |
||||
|
'orchid3' => 'cd69c9', |
||||
|
'orchid4' => '8b4789', |
||||
|
'pale' => 'db7093', |
||||
|
'palegoldenrod' => 'eee8aa', |
||||
|
'palegreen' => '98fb98', |
||||
|
'palegreen1' => '9aff9a', |
||||
|
'palegreen2' => '90ee90', |
||||
|
'palegreen3' => '7ccd7c', |
||||
|
'palegreen4' => '548b54', |
||||
|
'paleturquoise' => 'afeeee', |
||||
|
'paleturquoise1' => 'bbffff', |
||||
|
'paleturquoise2' => 'aeeeee', |
||||
|
'paleturquoise3' => '96cdcd', |
||||
|
'paleturquoise4' => '668b8b', |
||||
|
'palevioletred' => 'db7093', |
||||
|
'palevioletred1' => 'ff82ab', |
||||
|
'palevioletred2' => 'ee799f', |
||||
|
'palevioletred3' => 'cd6889', |
||||
|
'palevioletred4' => '8b475d', |
||||
|
'papayawhip' => 'ffefd5', |
||||
|
'peachpuff1' => 'ffdab9', |
||||
|
'peachpuff2' => 'eecbad', |
||||
|
'peachpuff3' => 'cdaf95', |
||||
|
'peachpuff4' => '8b7765', |
||||
|
'pink' => 'ffc0cb', |
||||
|
'pink1' => 'ffb5c5', |
||||
|
'pink2' => 'eea9b8', |
||||
|
'pink3' => 'cd919e', |
||||
|
'pink4' => '8b636c', |
||||
|
'plum' => 'dda0dd', |
||||
|
'plum1' => 'ffbbff', |
||||
|
'plum2' => 'eeaeee', |
||||
|
'plum3' => 'cd96cd', |
||||
|
'plum4' => '8b668b', |
||||
|
'powderblue' => 'b0e0e6', |
||||
|
'purple' => 'a020f0', |
||||
|
'rebeccapurple' => '663399', |
||||
|
'purple1' => '9b30ff', |
||||
|
'purple2' => '912cee', |
||||
|
'purple3' => '7d26cd', |
||||
|
'purple4' => '551a8b', |
||||
|
'red' => 'ff0000', |
||||
|
'red1' => 'ff0000', |
||||
|
'red2' => 'ee0000', |
||||
|
'red3' => 'cd0000', |
||||
|
'red4' => '8b0000', |
||||
|
'rosybrown' => 'bc8f8f', |
||||
|
'rosybrown1' => 'ffc1c1', |
||||
|
'rosybrown2' => 'eeb4b4', |
||||
|
'rosybrown3' => 'cd9b9b', |
||||
|
'rosybrown4' => '8b6969', |
||||
|
'royalblue' => '4169e1', |
||||
|
'royalblue1' => '4876ff', |
||||
|
'royalblue2' => '436eee', |
||||
|
'royalblue3' => '3a5fcd', |
||||
|
'royalblue4' => '27408b', |
||||
|
'saddlebrown' => '8b4513', |
||||
|
'salmon' => 'fa8072', |
||||
|
'salmon1' => 'ff8c69', |
||||
|
'salmon2' => 'ee8262', |
||||
|
'salmon3' => 'cd7054', |
||||
|
'salmon4' => '8b4c39', |
||||
|
'sandybrown' => 'f4a460', |
||||
|
'seagreen1' => '54ff9f', |
||||
|
'seagreen2' => '4eee94', |
||||
|
'seagreen3' => '43cd80', |
||||
|
'seagreen4' => '2e8b57', |
||||
|
'seashell1' => 'fff5ee', |
||||
|
'seashell2' => 'eee5de', |
||||
|
'seashell3' => 'cdc5bf', |
||||
|
'seashell4' => '8b8682', |
||||
|
'sienna' => 'a0522d', |
||||
|
'sienna1' => 'ff8247', |
||||
|
'sienna2' => 'ee7942', |
||||
|
'sienna3' => 'cd6839', |
||||
|
'sienna4' => '8b4726', |
||||
|
'silver' => 'c0c0c0', |
||||
|
'skyblue' => '87ceeb', |
||||
|
'skyblue1' => '87ceff', |
||||
|
'skyblue2' => '7ec0ee', |
||||
|
'skyblue3' => '6ca6cd', |
||||
|
'skyblue4' => '4a708b', |
||||
|
'slateblue' => '6a5acd', |
||||
|
'slateblue1' => '836fff', |
||||
|
'slateblue2' => '7a67ee', |
||||
|
'slateblue3' => '6959cd', |
||||
|
'slateblue4' => '473c8b', |
||||
|
'slategray' => '708090', |
||||
|
'slategray1' => 'c6e2ff', |
||||
|
'slategray2' => 'b9d3ee', |
||||
|
'slategray3' => '9fb6cd', |
||||
|
'slategray4' => '6c7b8b', |
||||
|
'snow1' => 'fffafa', |
||||
|
'snow2' => 'eee9e9', |
||||
|
'snow3' => 'cdc9c9', |
||||
|
'snow4' => '8b8989', |
||||
|
'springgreen1' => '00ff7f', |
||||
|
'springgreen2' => '00ee76', |
||||
|
'springgreen3' => '00cd66', |
||||
|
'springgreen4' => '008b45', |
||||
|
'steelblue' => '4682b4', |
||||
|
'steelblue1' => '63b8ff', |
||||
|
'steelblue2' => '5cacee', |
||||
|
'steelblue3' => '4f94cd', |
||||
|
'steelblue4' => '36648b', |
||||
|
'tan' => 'd2b48c', |
||||
|
'tan1' => 'ffa54f', |
||||
|
'tan2' => 'ee9a49', |
||||
|
'tan3' => 'cd853f', |
||||
|
'tan4' => '8b5a2b', |
||||
|
'teal' => '008080', |
||||
|
'thistle' => 'd8bfd8', |
||||
|
'thistle1' => 'ffe1ff', |
||||
|
'thistle2' => 'eed2ee', |
||||
|
'thistle3' => 'cdb5cd', |
||||
|
'thistle4' => '8b7b8b', |
||||
|
'tomato1' => 'ff6347', |
||||
|
'tomato2' => 'ee5c42', |
||||
|
'tomato3' => 'cd4f39', |
||||
|
'tomato4' => '8b3626', |
||||
|
'turquoise' => '40e0d0', |
||||
|
'turquoise1' => '00f5ff', |
||||
|
'turquoise2' => '00e5ee', |
||||
|
'turquoise3' => '00c5cd', |
||||
|
'turquoise4' => '00868b', |
||||
|
'violet' => 'ee82ee', |
||||
|
'violetred' => 'd02090', |
||||
|
'violetred1' => 'ff3e96', |
||||
|
'violetred2' => 'ee3a8c', |
||||
|
'violetred3' => 'cd3278', |
||||
|
'violetred4' => '8b2252', |
||||
|
'wheat' => 'f5deb3', |
||||
|
'wheat1' => 'ffe7ba', |
||||
|
'wheat2' => 'eed8ae', |
||||
|
'wheat3' => 'cdba96', |
||||
|
'wheat4' => '8b7e66', |
||||
|
'white' => 'ffffff', |
||||
|
'whitesmoke' => 'f5f5f5', |
||||
|
'yellow' => 'ffff00', |
||||
|
'yellow1' => 'ffff00', |
||||
|
'yellow2' => 'eeee00', |
||||
|
'yellow3' => 'cdcd00', |
||||
|
'yellow4' => '8b8b00', |
||||
|
'yellowgreen' => '9acd32', |
||||
|
); |
||||
|
|
||||
|
protected $face; |
||||
|
protected $size; |
||||
|
protected $color; |
||||
|
|
||||
|
protected $bold = false; |
||||
|
protected $italic = false; |
||||
|
protected $underline = false; |
||||
|
protected $superscript = false; |
||||
|
protected $subscript = false; |
||||
|
protected $strikethrough = false; |
||||
|
|
||||
|
protected $startTagCallbacks = array( |
||||
|
'font' => 'startFontTag', |
||||
|
'b' => 'startBoldTag', |
||||
|
'strong' => 'startBoldTag', |
||||
|
'i' => 'startItalicTag', |
||||
|
'em' => 'startItalicTag', |
||||
|
'u' => 'startUnderlineTag', |
||||
|
'ins' => 'startUnderlineTag', |
||||
|
'del' => 'startStrikethruTag', |
||||
|
'sup' => 'startSuperscriptTag', |
||||
|
'sub' => 'startSubscriptTag', |
||||
|
); |
||||
|
|
||||
|
protected $endTagCallbacks = array( |
||||
|
'font' => 'endFontTag', |
||||
|
'b' => 'endBoldTag', |
||||
|
'strong' => 'endBoldTag', |
||||
|
'i' => 'endItalicTag', |
||||
|
'em' => 'endItalicTag', |
||||
|
'u' => 'endUnderlineTag', |
||||
|
'ins' => 'endUnderlineTag', |
||||
|
'del' => 'endStrikethruTag', |
||||
|
'sup' => 'endSuperscriptTag', |
||||
|
'sub' => 'endSubscriptTag', |
||||
|
'br' => 'breakTag', |
||||
|
'p' => 'breakTag', |
||||
|
'h1' => 'breakTag', |
||||
|
'h2' => 'breakTag', |
||||
|
'h3' => 'breakTag', |
||||
|
'h4' => 'breakTag', |
||||
|
'h5' => 'breakTag', |
||||
|
'h6' => 'breakTag', |
||||
|
); |
||||
|
|
||||
|
protected $stack = array(); |
||||
|
|
||||
|
protected $stringData = ''; |
||||
|
|
||||
|
protected $richTextObject; |
||||
|
|
||||
|
protected function initialise() |
||||
|
{ |
||||
|
$this->face = $this->size = $this->color = null; |
||||
|
$this->bold = $this->italic = $this->underline = $this->superscript = $this->subscript = $this->strikethrough = false; |
||||
|
|
||||
|
$this->stack = array(); |
||||
|
|
||||
|
$this->stringData = ''; |
||||
|
} |
||||
|
|
||||
|
public function toRichTextObject($html) |
||||
|
{ |
||||
|
$this->initialise(); |
||||
|
|
||||
|
// Create a new DOM object |
||||
|
$dom = new \DOMDocument; |
||||
|
// Load the HTML file into the DOM object |
||||
|
// Note the use of error suppression, because typically this will be an html fragment, so not fully valid markup |
||||
|
$loaded = @$dom->loadHTML($html); |
||||
|
|
||||
|
// Discard excess white space |
||||
|
$dom->preserveWhiteSpace = false; |
||||
|
|
||||
|
$this->richTextObject = new PHPExcel_RichText();; |
||||
|
$this->parseElements($dom); |
||||
|
|
||||
|
// Clean any further spurious whitespace |
||||
|
$this->cleanWhitespace(); |
||||
|
|
||||
|
return $this->richTextObject; |
||||
|
} |
||||
|
|
||||
|
protected function cleanWhitespace() |
||||
|
{ |
||||
|
foreach ($this->richTextObject->getRichTextElements() as $key => $element) { |
||||
|
$text = $element->getText(); |
||||
|
// Trim any leading spaces on the first run |
||||
|
if ($key == 0) { |
||||
|
$text = ltrim($text); |
||||
|
} |
||||
|
// Trim any spaces immediately after a line break |
||||
|
$text = preg_replace('/\n */mu', "\n", $text); |
||||
|
$element->setText($text); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected function buildTextRun() |
||||
|
{ |
||||
|
$text = $this->stringData; |
||||
|
if (trim($text) === '') { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
$richtextRun = $this->richTextObject->createTextRun($this->stringData); |
||||
|
if ($this->face) { |
||||
|
$richtextRun->getFont()->setName($this->face); |
||||
|
} |
||||
|
if ($this->size) { |
||||
|
$richtextRun->getFont()->setSize($this->size); |
||||
|
} |
||||
|
if ($this->color) { |
||||
|
$richtextRun->getFont()->setColor(new PHPExcel_Style_Color('ff' . $this->color)); |
||||
|
} |
||||
|
if ($this->bold) { |
||||
|
$richtextRun->getFont()->setBold(true); |
||||
|
} |
||||
|
if ($this->italic) { |
||||
|
$richtextRun->getFont()->setItalic(true); |
||||
|
} |
||||
|
if ($this->underline) { |
||||
|
$richtextRun->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE); |
||||
|
} |
||||
|
if ($this->superscript) { |
||||
|
$richtextRun->getFont()->setSuperScript(true); |
||||
|
} |
||||
|
if ($this->subscript) { |
||||
|
$richtextRun->getFont()->setSubScript(true); |
||||
|
} |
||||
|
if ($this->strikethrough) { |
||||
|
$richtextRun->getFont()->setStrikethrough(true); |
||||
|
} |
||||
|
$this->stringData = ''; |
||||
|
} |
||||
|
|
||||
|
protected function rgbToColour($rgb) |
||||
|
{ |
||||
|
preg_match_all('/\d+/', $rgb, $values); |
||||
|
foreach ($values[0] as &$value) { |
||||
|
$value = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); |
||||
|
} |
||||
|
return implode($values[0]); |
||||
|
} |
||||
|
|
||||
|
protected function colourNameLookup($rgb) |
||||
|
{ |
||||
|
return self::$colourMap[$rgb]; |
||||
|
} |
||||
|
|
||||
|
protected function startFontTag($tag) |
||||
|
{ |
||||
|
foreach ($tag->attributes as $attribute) { |
||||
|
$attributeName = strtolower($attribute->name); |
||||
|
$attributeValue = $attribute->value; |
||||
|
|
||||
|
if ($attributeName == 'color') { |
||||
|
if (preg_match('/rgb\s*\(/', $attributeValue)) { |
||||
|
$this->$attributeName = $this->rgbToColour($attributeValue); |
||||
|
} elseif (strpos(trim($attributeValue), '#') === 0) { |
||||
|
$this->$attributeName = ltrim($attributeValue, '#'); |
||||
|
} else { |
||||
|
$this->$attributeName = $this->colourNameLookup($attributeValue); |
||||
|
} |
||||
|
} else { |
||||
|
$this->$attributeName = $attributeValue; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected function endFontTag() |
||||
|
{ |
||||
|
$this->face = $this->size = $this->color = null; |
||||
|
} |
||||
|
|
||||
|
protected function startBoldTag() |
||||
|
{ |
||||
|
$this->bold = true; |
||||
|
} |
||||
|
|
||||
|
protected function endBoldTag() |
||||
|
{ |
||||
|
$this->bold = false; |
||||
|
} |
||||
|
|
||||
|
protected function startItalicTag() |
||||
|
{ |
||||
|
$this->italic = true; |
||||
|
} |
||||
|
|
||||
|
protected function endItalicTag() |
||||
|
{ |
||||
|
$this->italic = false; |
||||
|
} |
||||
|
|
||||
|
protected function startUnderlineTag() |
||||
|
{ |
||||
|
$this->underline = true; |
||||
|
} |
||||
|
|
||||
|
protected function endUnderlineTag() |
||||
|
{ |
||||
|
$this->underline = false; |
||||
|
} |
||||
|
|
||||
|
protected function startSubscriptTag() |
||||
|
{ |
||||
|
$this->subscript = true; |
||||
|
} |
||||
|
|
||||
|
protected function endSubscriptTag() |
||||
|
{ |
||||
|
$this->subscript = false; |
||||
|
} |
||||
|
|
||||
|
protected function startSuperscriptTag() |
||||
|
{ |
||||
|
$this->superscript = true; |
||||
|
} |
||||
|
|
||||
|
protected function endSuperscriptTag() |
||||
|
{ |
||||
|
$this->superscript = false; |
||||
|
} |
||||
|
|
||||
|
protected function startStrikethruTag() |
||||
|
{ |
||||
|
$this->strikethrough = true; |
||||
|
} |
||||
|
|
||||
|
protected function endStrikethruTag() |
||||
|
{ |
||||
|
$this->strikethrough = false; |
||||
|
} |
||||
|
|
||||
|
protected function breakTag() |
||||
|
{ |
||||
|
$this->stringData .= "\n"; |
||||
|
} |
||||
|
|
||||
|
protected function parseTextNode(DOMText $textNode) |
||||
|
{ |
||||
|
$domText = preg_replace( |
||||
|
'/\s+/u', |
||||
|
' ', |
||||
|
str_replace(array("\r", "\n"), ' ', $textNode->nodeValue) |
||||
|
); |
||||
|
$this->stringData .= $domText; |
||||
|
$this->buildTextRun(); |
||||
|
} |
||||
|
|
||||
|
protected function handleCallback($element, $callbackTag, $callbacks) |
||||
|
{ |
||||
|
if (isset($callbacks[$callbackTag])) { |
||||
|
$elementHandler = $callbacks[$callbackTag]; |
||||
|
if (method_exists($this, $elementHandler)) { |
||||
|
call_user_func(array($this, $elementHandler), $element); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected function parseElementNode(DOMElement $element) |
||||
|
{ |
||||
|
$callbackTag = strtolower($element->nodeName); |
||||
|
$this->stack[] = $callbackTag; |
||||
|
|
||||
|
$this->handleCallback($element, $callbackTag, $this->startTagCallbacks); |
||||
|
|
||||
|
$this->parseElements($element); |
||||
|
array_pop($this->stack); |
||||
|
|
||||
|
$this->handleCallback($element, $callbackTag, $this->endTagCallbacks); |
||||
|
} |
||||
|
|
||||
|
protected function parseElements(DOMNode $element) |
||||
|
{ |
||||
|
foreach ($element->childNodes as $child) { |
||||
|
if ($child instanceof DOMText) { |
||||
|
$this->parseTextNode($child); |
||||
|
} elseif ($child instanceof DOMElement) { |
||||
|
$this->parseElementNode($child); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,227 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_Abstract |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader |
||||
|
{ |
||||
|
/** |
||||
|
* Read data only? |
||||
|
* Identifies whether the Reader should only read data values for cells, and ignore any formatting information; |
||||
|
* or whether it should read both data and formatting |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
protected $_readDataOnly = FALSE; |
||||
|
|
||||
|
/** |
||||
|
* Read charts that are defined in the workbook? |
||||
|
* Identifies whether the Reader should read the definitions for any charts that exist in the workbook; |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
protected $_includeCharts = FALSE; |
||||
|
|
||||
|
/** |
||||
|
* Restrict which sheets should be loaded? |
||||
|
* This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded. |
||||
|
* |
||||
|
* @var array of string |
||||
|
*/ |
||||
|
protected $_loadSheetsOnly = NULL; |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_IReadFilter instance |
||||
|
* |
||||
|
* @var PHPExcel_Reader_IReadFilter |
||||
|
*/ |
||||
|
protected $_readFilter = NULL; |
||||
|
|
||||
|
protected $_fileHandle = NULL; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Read data only? |
||||
|
* If this is true, then the Reader will only read data values for cells, it will not read any formatting information. |
||||
|
* If false (the default) it will read data and formatting. |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getReadDataOnly() { |
||||
|
return $this->_readDataOnly; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set read data only |
||||
|
* Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information. |
||||
|
* Set to false (the default) to advise the Reader to read both data and formatting for cells. |
||||
|
* |
||||
|
* @param boolean $pValue |
||||
|
* |
||||
|
* @return PHPExcel_Reader_IReader |
||||
|
*/ |
||||
|
public function setReadDataOnly($pValue = FALSE) { |
||||
|
$this->_readDataOnly = $pValue; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read charts in workbook? |
||||
|
* If this is true, then the Reader will include any charts that exist in the workbook. |
||||
|
* Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value. |
||||
|
* If false (the default) it will ignore any charts defined in the workbook file. |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getIncludeCharts() { |
||||
|
return $this->_includeCharts; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set read charts in workbook |
||||
|
* Set to true, to advise the Reader to include any charts that exist in the workbook. |
||||
|
* Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value. |
||||
|
* Set to false (the default) to discard charts. |
||||
|
* |
||||
|
* @param boolean $pValue |
||||
|
* |
||||
|
* @return PHPExcel_Reader_IReader |
||||
|
*/ |
||||
|
public function setIncludeCharts($pValue = FALSE) { |
||||
|
$this->_includeCharts = (boolean) $pValue; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get which sheets to load |
||||
|
* Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null |
||||
|
* indicating that all worksheets in the workbook should be loaded. |
||||
|
* |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function getLoadSheetsOnly() |
||||
|
{ |
||||
|
return $this->_loadSheetsOnly; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set which sheets to load |
||||
|
* |
||||
|
* @param mixed $value |
||||
|
* This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name. |
||||
|
* If NULL, then it tells the Reader to read all worksheets in the workbook |
||||
|
* |
||||
|
* @return PHPExcel_Reader_IReader |
||||
|
*/ |
||||
|
public function setLoadSheetsOnly($value = NULL) |
||||
|
{ |
||||
|
$this->_loadSheetsOnly = is_array($value) ? |
||||
|
$value : array($value); |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set all sheets to load |
||||
|
* Tells the Reader to load all worksheets from the workbook. |
||||
|
* |
||||
|
* @return PHPExcel_Reader_IReader |
||||
|
*/ |
||||
|
public function setLoadAllSheets() |
||||
|
{ |
||||
|
$this->_loadSheetsOnly = NULL; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read filter |
||||
|
* |
||||
|
* @return PHPExcel_Reader_IReadFilter |
||||
|
*/ |
||||
|
public function getReadFilter() { |
||||
|
return $this->_readFilter; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set read filter |
||||
|
* |
||||
|
* @param PHPExcel_Reader_IReadFilter $pValue |
||||
|
* @return PHPExcel_Reader_IReader |
||||
|
*/ |
||||
|
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) { |
||||
|
$this->_readFilter = $pValue; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Open file for reading |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
* @return resource |
||||
|
*/ |
||||
|
protected function _openFile($pFilename) |
||||
|
{ |
||||
|
// Check if file exists |
||||
|
if (!file_exists($pFilename) || !is_readable($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
||||
|
} |
||||
|
|
||||
|
// Open file |
||||
|
$this->_fileHandle = fopen($pFilename, 'r'); |
||||
|
if ($this->_fileHandle === FALSE) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open file " . $pFilename . " for reading."); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Can the current PHPExcel_Reader_IReader read the file? |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @return boolean |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function canRead($pFilename) |
||||
|
{ |
||||
|
// Check if file exists |
||||
|
try { |
||||
|
$this->_openFile($pFilename); |
||||
|
} catch (Exception $e) { |
||||
|
return FALSE; |
||||
|
} |
||||
|
|
||||
|
$readable = $this->_isValidFormat(); |
||||
|
fclose ($this->_fileHandle); |
||||
|
return $readable; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,415 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** PHPExcel root directory */ |
||||
|
if (!defined('PHPEXCEL_ROOT')) { |
||||
|
/** |
||||
|
* @ignore |
||||
|
*/ |
||||
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
||||
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_CSV |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Reader_CSV extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader |
||||
|
{ |
||||
|
/** |
||||
|
* Input encoding |
||||
|
* |
||||
|
* @access private |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_inputEncoding = 'UTF-8'; |
||||
|
|
||||
|
/** |
||||
|
* Delimiter |
||||
|
* |
||||
|
* @access private |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_delimiter = ','; |
||||
|
|
||||
|
/** |
||||
|
* Enclosure |
||||
|
* |
||||
|
* @access private |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_enclosure = '"'; |
||||
|
|
||||
|
/** |
||||
|
* Line ending |
||||
|
* |
||||
|
* @access private |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_lineEnding = PHP_EOL; |
||||
|
|
||||
|
/** |
||||
|
* Sheet index to read |
||||
|
* |
||||
|
* @access private |
||||
|
* @var int |
||||
|
*/ |
||||
|
private $_sheetIndex = 0; |
||||
|
|
||||
|
/** |
||||
|
* Load rows contiguously |
||||
|
* |
||||
|
* @access private |
||||
|
* @var int |
||||
|
*/ |
||||
|
private $_contiguous = false; |
||||
|
|
||||
|
/** |
||||
|
* Row counter for loading rows contiguously |
||||
|
* |
||||
|
* @var int |
||||
|
*/ |
||||
|
private $_contiguousRow = -1; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Reader_CSV |
||||
|
*/ |
||||
|
public function __construct() { |
||||
|
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Validate that the current file is a CSV file |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
protected function _isValidFormat() |
||||
|
{ |
||||
|
return TRUE; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set input encoding |
||||
|
* |
||||
|
* @param string $pValue Input encoding |
||||
|
*/ |
||||
|
public function setInputEncoding($pValue = 'UTF-8') |
||||
|
{ |
||||
|
$this->_inputEncoding = $pValue; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get input encoding |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getInputEncoding() |
||||
|
{ |
||||
|
return $this->_inputEncoding; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Move filepointer past any BOM marker |
||||
|
* |
||||
|
*/ |
||||
|
protected function _skipBOM() |
||||
|
{ |
||||
|
rewind($fileHandle); |
||||
|
|
||||
|
switch ($this->_inputEncoding) { |
||||
|
case 'UTF-8': |
||||
|
fgets($this->_fileHandle, 4) == "\xEF\xBB\xBF" ? |
||||
|
fseek($this->_fileHandle, 3) : fseek($this->_fileHandle, 0); |
||||
|
break; |
||||
|
case 'UTF-16LE': |
||||
|
fgets($this->_fileHandle, 3) == "\xFF\xFE" ? |
||||
|
fseek($this->_fileHandle, 2) : fseek($this->_fileHandle, 0); |
||||
|
break; |
||||
|
case 'UTF-16BE': |
||||
|
fgets($this->_fileHandle, 3) == "\xFE\xFF" ? |
||||
|
fseek($this->_fileHandle, 2) : fseek($this->_fileHandle, 0); |
||||
|
break; |
||||
|
case 'UTF-32LE': |
||||
|
fgets($this->_fileHandle, 5) == "\xFF\xFE\x00\x00" ? |
||||
|
fseek($this->_fileHandle, 4) : fseek($this->_fileHandle, 0); |
||||
|
break; |
||||
|
case 'UTF-32BE': |
||||
|
fgets($this->_fileHandle, 5) == "\x00\x00\xFE\xFF" ? |
||||
|
fseek($this->_fileHandle, 4) : fseek($this->_fileHandle, 0); |
||||
|
break; |
||||
|
default: |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function listWorksheetInfo($pFilename) |
||||
|
{ |
||||
|
// Open file |
||||
|
$this->_openFile($pFilename); |
||||
|
if (!$this->_isValidFormat()) { |
||||
|
fclose ($this->_fileHandle); |
||||
|
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file."); |
||||
|
} |
||||
|
$fileHandle = $this->_fileHandle; |
||||
|
|
||||
|
// Skip BOM, if any |
||||
|
$this->_skipBOM(); |
||||
|
|
||||
|
$escapeEnclosures = array( "\\" . $this->_enclosure, $this->_enclosure . $this->_enclosure ); |
||||
|
|
||||
|
$worksheetInfo = array(); |
||||
|
$worksheetInfo[0]['worksheetName'] = 'Worksheet'; |
||||
|
$worksheetInfo[0]['lastColumnLetter'] = 'A'; |
||||
|
$worksheetInfo[0]['lastColumnIndex'] = 0; |
||||
|
$worksheetInfo[0]['totalRows'] = 0; |
||||
|
$worksheetInfo[0]['totalColumns'] = 0; |
||||
|
|
||||
|
// Loop through each line of the file in turn |
||||
|
while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) { |
||||
|
$worksheetInfo[0]['totalRows']++; |
||||
|
$worksheetInfo[0]['lastColumnIndex'] = max($worksheetInfo[0]['lastColumnIndex'], count($rowData) - 1); |
||||
|
} |
||||
|
|
||||
|
$worksheetInfo[0]['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']); |
||||
|
$worksheetInfo[0]['totalColumns'] = $worksheetInfo[0]['lastColumnIndex'] + 1; |
||||
|
|
||||
|
// Close file |
||||
|
fclose($fileHandle); |
||||
|
|
||||
|
return $worksheetInfo; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Loads PHPExcel from file |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @return PHPExcel |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function load($pFilename) |
||||
|
{ |
||||
|
// Create new PHPExcel |
||||
|
$objPHPExcel = new PHPExcel(); |
||||
|
|
||||
|
// Load into this instance |
||||
|
return $this->loadIntoExisting($pFilename, $objPHPExcel); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Loads PHPExcel from file into PHPExcel instance |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @param PHPExcel $objPHPExcel |
||||
|
* @return PHPExcel |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) |
||||
|
{ |
||||
|
$lineEnding = ini_get('auto_detect_line_endings'); |
||||
|
ini_set('auto_detect_line_endings', true); |
||||
|
|
||||
|
// Open file |
||||
|
$this->_openFile($pFilename); |
||||
|
if (!$this->_isValidFormat()) { |
||||
|
fclose ($this->_fileHandle); |
||||
|
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file."); |
||||
|
} |
||||
|
$fileHandle = $this->_fileHandle; |
||||
|
|
||||
|
// Skip BOM, if any |
||||
|
$this->_skipBOM(); |
||||
|
|
||||
|
// Create new PHPExcel object |
||||
|
while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) { |
||||
|
$objPHPExcel->createSheet(); |
||||
|
} |
||||
|
$sheet = $objPHPExcel->setActiveSheetIndex($this->_sheetIndex); |
||||
|
|
||||
|
$escapeEnclosures = array( "\\" . $this->_enclosure, |
||||
|
$this->_enclosure . $this->_enclosure |
||||
|
); |
||||
|
|
||||
|
// Set our starting row based on whether we're in contiguous mode or not |
||||
|
$currentRow = 1; |
||||
|
if ($this->_contiguous) { |
||||
|
$currentRow = ($this->_contiguousRow == -1) ? $sheet->getHighestRow(): $this->_contiguousRow; |
||||
|
} |
||||
|
|
||||
|
// Loop through each line of the file in turn |
||||
|
while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) { |
||||
|
$columnLetter = 'A'; |
||||
|
foreach($rowData as $rowDatum) { |
||||
|
if ($rowDatum != '' && $this->_readFilter->readCell($columnLetter, $currentRow)) { |
||||
|
// Unescape enclosures |
||||
|
$rowDatum = str_replace($escapeEnclosures, $this->_enclosure, $rowDatum); |
||||
|
|
||||
|
// Convert encoding if necessary |
||||
|
if ($this->_inputEncoding !== 'UTF-8') { |
||||
|
$rowDatum = PHPExcel_Shared_String::ConvertEncoding($rowDatum, 'UTF-8', $this->_inputEncoding); |
||||
|
} |
||||
|
|
||||
|
// Set cell value |
||||
|
$sheet->getCell($columnLetter . $currentRow)->setValue($rowDatum); |
||||
|
} |
||||
|
++$columnLetter; |
||||
|
} |
||||
|
++$currentRow; |
||||
|
} |
||||
|
|
||||
|
// Close file |
||||
|
fclose($fileHandle); |
||||
|
|
||||
|
if ($this->_contiguous) { |
||||
|
$this->_contiguousRow = $currentRow; |
||||
|
} |
||||
|
|
||||
|
ini_set('auto_detect_line_endings', $lineEnding); |
||||
|
|
||||
|
// Return |
||||
|
return $objPHPExcel; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get delimiter |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getDelimiter() { |
||||
|
return $this->_delimiter; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set delimiter |
||||
|
* |
||||
|
* @param string $pValue Delimiter, defaults to , |
||||
|
* @return PHPExcel_Reader_CSV |
||||
|
*/ |
||||
|
public function setDelimiter($pValue = ',') { |
||||
|
$this->_delimiter = $pValue; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get enclosure |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getEnclosure() { |
||||
|
return $this->_enclosure; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set enclosure |
||||
|
* |
||||
|
* @param string $pValue Enclosure, defaults to " |
||||
|
* @return PHPExcel_Reader_CSV |
||||
|
*/ |
||||
|
public function setEnclosure($pValue = '"') { |
||||
|
if ($pValue == '') { |
||||
|
$pValue = '"'; |
||||
|
} |
||||
|
$this->_enclosure = $pValue; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get line ending |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getLineEnding() { |
||||
|
return $this->_lineEnding; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set line ending |
||||
|
* |
||||
|
* @param string $pValue Line ending, defaults to OS line ending (PHP_EOL) |
||||
|
* @return PHPExcel_Reader_CSV |
||||
|
*/ |
||||
|
public function setLineEnding($pValue = PHP_EOL) { |
||||
|
$this->_lineEnding = $pValue; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get sheet index |
||||
|
* |
||||
|
* @return integer |
||||
|
*/ |
||||
|
public function getSheetIndex() { |
||||
|
return $this->_sheetIndex; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set sheet index |
||||
|
* |
||||
|
* @param integer $pValue Sheet index |
||||
|
* @return PHPExcel_Reader_CSV |
||||
|
*/ |
||||
|
public function setSheetIndex($pValue = 0) { |
||||
|
$this->_sheetIndex = $pValue; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set Contiguous |
||||
|
* |
||||
|
* @param boolean $contiguous |
||||
|
*/ |
||||
|
public function setContiguous($contiguous = FALSE) |
||||
|
{ |
||||
|
$this->_contiguous = (bool) $contiguous; |
||||
|
if (!$contiguous) { |
||||
|
$this->_contiguousRow = -1; |
||||
|
} |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Contiguous |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function getContiguous() { |
||||
|
return $this->_contiguous; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,58 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** PHPExcel root directory */ |
||||
|
if (!defined('PHPEXCEL_ROOT')) { |
||||
|
/** |
||||
|
* @ignore |
||||
|
*/ |
||||
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
||||
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_DefaultReadFilter |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Reader_DefaultReadFilter implements PHPExcel_Reader_IReadFilter |
||||
|
{ |
||||
|
/** |
||||
|
* Should this cell be read? |
||||
|
* |
||||
|
* @param $column String column index |
||||
|
* @param $row Row index |
||||
|
* @param $worksheetName Optional worksheet name |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function readCell($column, $row, $worksheetName = '') { |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,802 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** PHPExcel root directory */ |
||||
|
if (!defined('PHPEXCEL_ROOT')) { |
||||
|
/** |
||||
|
* @ignore |
||||
|
*/ |
||||
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
||||
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_Excel2003XML |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader |
||||
|
{ |
||||
|
/** |
||||
|
* Formats |
||||
|
* |
||||
|
* @var array |
||||
|
*/ |
||||
|
private $_styles = array(); |
||||
|
|
||||
|
/** |
||||
|
* Character set used in the file |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_charSet = 'UTF-8'; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Reader_Excel2003XML |
||||
|
*/ |
||||
|
public function __construct() { |
||||
|
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Can the current PHPExcel_Reader_IReader read the file? |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @return boolean |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function canRead($pFilename) |
||||
|
{ |
||||
|
|
||||
|
// Office xmlns:o="urn:schemas-microsoft-com:office:office" |
||||
|
// Excel xmlns:x="urn:schemas-microsoft-com:office:excel" |
||||
|
// XML Spreadsheet xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" |
||||
|
// Spreadsheet component xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" |
||||
|
// XML schema xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" |
||||
|
// XML data type xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" |
||||
|
// MS-persist recordset xmlns:rs="urn:schemas-microsoft-com:rowset" |
||||
|
// Rowset xmlns:z="#RowsetSchema" |
||||
|
// |
||||
|
|
||||
|
$signature = array( |
||||
|
'<?xml version="1.0"', |
||||
|
'<?mso-application progid="Excel.Sheet"?>' |
||||
|
); |
||||
|
|
||||
|
// Open file |
||||
|
$this->_openFile($pFilename); |
||||
|
$fileHandle = $this->_fileHandle; |
||||
|
|
||||
|
// Read sample data (first 2 KB will do) |
||||
|
$data = fread($fileHandle, 2048); |
||||
|
fclose($fileHandle); |
||||
|
|
||||
|
$valid = true; |
||||
|
foreach($signature as $match) { |
||||
|
// every part of the signature must be present |
||||
|
if (strpos($data, $match) === false) { |
||||
|
$valid = false; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Retrieve charset encoding |
||||
|
if(preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/um',$data,$matches)) { |
||||
|
$this->_charSet = strtoupper($matches[1]); |
||||
|
} |
||||
|
// echo 'Character Set is ',$this->_charSet,'<br />'; |
||||
|
|
||||
|
return $valid; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function listWorksheetNames($pFilename) |
||||
|
{ |
||||
|
// Check if file exists |
||||
|
if (!file_exists($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
||||
|
} |
||||
|
if (!$this->canRead($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file."); |
||||
|
} |
||||
|
|
||||
|
$worksheetNames = array(); |
||||
|
|
||||
|
$xml = simplexml_load_file($pFilename); |
||||
|
$namespaces = $xml->getNamespaces(true); |
||||
|
|
||||
|
$xml_ss = $xml->children($namespaces['ss']); |
||||
|
foreach($xml_ss->Worksheet as $worksheet) { |
||||
|
$worksheet_ss = $worksheet->attributes($namespaces['ss']); |
||||
|
$worksheetNames[] = self::_convertStringEncoding((string) $worksheet_ss['Name'],$this->_charSet); |
||||
|
} |
||||
|
|
||||
|
return $worksheetNames; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function listWorksheetInfo($pFilename) |
||||
|
{ |
||||
|
// Check if file exists |
||||
|
if (!file_exists($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
||||
|
} |
||||
|
|
||||
|
$worksheetInfo = array(); |
||||
|
|
||||
|
$xml = simplexml_load_file($pFilename); |
||||
|
$namespaces = $xml->getNamespaces(true); |
||||
|
|
||||
|
$worksheetID = 1; |
||||
|
$xml_ss = $xml->children($namespaces['ss']); |
||||
|
foreach($xml_ss->Worksheet as $worksheet) { |
||||
|
$worksheet_ss = $worksheet->attributes($namespaces['ss']); |
||||
|
|
||||
|
$tmpInfo = array(); |
||||
|
$tmpInfo['worksheetName'] = ''; |
||||
|
$tmpInfo['lastColumnLetter'] = 'A'; |
||||
|
$tmpInfo['lastColumnIndex'] = 0; |
||||
|
$tmpInfo['totalRows'] = 0; |
||||
|
$tmpInfo['totalColumns'] = 0; |
||||
|
|
||||
|
if (isset($worksheet_ss['Name'])) { |
||||
|
$tmpInfo['worksheetName'] = (string) $worksheet_ss['Name']; |
||||
|
} else { |
||||
|
$tmpInfo['worksheetName'] = "Worksheet_{$worksheetID}"; |
||||
|
} |
||||
|
|
||||
|
if (isset($worksheet->Table->Row)) { |
||||
|
$rowIndex = 0; |
||||
|
|
||||
|
foreach($worksheet->Table->Row as $rowData) { |
||||
|
$columnIndex = 0; |
||||
|
$rowHasData = false; |
||||
|
|
||||
|
foreach($rowData->Cell as $cell) { |
||||
|
if (isset($cell->Data)) { |
||||
|
$tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex); |
||||
|
$rowHasData = true; |
||||
|
} |
||||
|
|
||||
|
++$columnIndex; |
||||
|
} |
||||
|
|
||||
|
++$rowIndex; |
||||
|
|
||||
|
if ($rowHasData) { |
||||
|
$tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); |
||||
|
$tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1; |
||||
|
|
||||
|
$worksheetInfo[] = $tmpInfo; |
||||
|
++$worksheetID; |
||||
|
} |
||||
|
|
||||
|
return $worksheetInfo; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Loads PHPExcel from file |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @return PHPExcel |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function load($pFilename) |
||||
|
{ |
||||
|
// Create new PHPExcel |
||||
|
$objPHPExcel = new PHPExcel(); |
||||
|
|
||||
|
// Load into this instance |
||||
|
return $this->loadIntoExisting($pFilename, $objPHPExcel); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private static function identifyFixedStyleValue($styleList,&$styleAttributeValue) { |
||||
|
$styleAttributeValue = strtolower($styleAttributeValue); |
||||
|
foreach($styleList as $style) { |
||||
|
if ($styleAttributeValue == strtolower($style)) { |
||||
|
$styleAttributeValue = $style; |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* pixel units to excel width units(units of 1/256th of a character width) |
||||
|
* @param pxs |
||||
|
* @return |
||||
|
*/ |
||||
|
private static function _pixel2WidthUnits($pxs) { |
||||
|
$UNIT_OFFSET_MAP = array(0, 36, 73, 109, 146, 182, 219); |
||||
|
|
||||
|
$widthUnits = 256 * ($pxs / 7); |
||||
|
$widthUnits += $UNIT_OFFSET_MAP[($pxs % 7)]; |
||||
|
return $widthUnits; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* excel width units(units of 1/256th of a character width) to pixel units |
||||
|
* @param widthUnits |
||||
|
* @return |
||||
|
*/ |
||||
|
private static function _widthUnits2Pixel($widthUnits) { |
||||
|
$pixels = ($widthUnits / 256) * 7; |
||||
|
$offsetWidthUnits = $widthUnits % 256; |
||||
|
$pixels += round($offsetWidthUnits / (256 / 7)); |
||||
|
return $pixels; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private static function _hex2str($hex) { |
||||
|
return chr(hexdec($hex[1])); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Loads PHPExcel from file into PHPExcel instance |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @param PHPExcel $objPHPExcel |
||||
|
* @return PHPExcel |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) |
||||
|
{ |
||||
|
$fromFormats = array('\-', '\ '); |
||||
|
$toFormats = array('-', ' '); |
||||
|
|
||||
|
$underlineStyles = array ( |
||||
|
PHPExcel_Style_Font::UNDERLINE_NONE, |
||||
|
PHPExcel_Style_Font::UNDERLINE_DOUBLE, |
||||
|
PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING, |
||||
|
PHPExcel_Style_Font::UNDERLINE_SINGLE, |
||||
|
PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING |
||||
|
); |
||||
|
$verticalAlignmentStyles = array ( |
||||
|
PHPExcel_Style_Alignment::VERTICAL_BOTTOM, |
||||
|
PHPExcel_Style_Alignment::VERTICAL_TOP, |
||||
|
PHPExcel_Style_Alignment::VERTICAL_CENTER, |
||||
|
PHPExcel_Style_Alignment::VERTICAL_JUSTIFY |
||||
|
); |
||||
|
$horizontalAlignmentStyles = array ( |
||||
|
PHPExcel_Style_Alignment::HORIZONTAL_GENERAL, |
||||
|
PHPExcel_Style_Alignment::HORIZONTAL_LEFT, |
||||
|
PHPExcel_Style_Alignment::HORIZONTAL_RIGHT, |
||||
|
PHPExcel_Style_Alignment::HORIZONTAL_CENTER, |
||||
|
PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS, |
||||
|
PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY |
||||
|
); |
||||
|
|
||||
|
$timezoneObj = new DateTimeZone('Europe/London'); |
||||
|
$GMT = new DateTimeZone('UTC'); |
||||
|
|
||||
|
|
||||
|
// Check if file exists |
||||
|
if (!file_exists($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
||||
|
} |
||||
|
|
||||
|
if (!$this->canRead($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file."); |
||||
|
} |
||||
|
|
||||
|
$xml = simplexml_load_file($pFilename); |
||||
|
$namespaces = $xml->getNamespaces(true); |
||||
|
|
||||
|
$docProps = $objPHPExcel->getProperties(); |
||||
|
if (isset($xml->DocumentProperties[0])) { |
||||
|
foreach($xml->DocumentProperties[0] as $propertyName => $propertyValue) { |
||||
|
switch ($propertyName) { |
||||
|
case 'Title' : |
||||
|
$docProps->setTitle(self::_convertStringEncoding($propertyValue,$this->_charSet)); |
||||
|
break; |
||||
|
case 'Subject' : |
||||
|
$docProps->setSubject(self::_convertStringEncoding($propertyValue,$this->_charSet)); |
||||
|
break; |
||||
|
case 'Author' : |
||||
|
$docProps->setCreator(self::_convertStringEncoding($propertyValue,$this->_charSet)); |
||||
|
break; |
||||
|
case 'Created' : |
||||
|
$creationDate = strtotime($propertyValue); |
||||
|
$docProps->setCreated($creationDate); |
||||
|
break; |
||||
|
case 'LastAuthor' : |
||||
|
$docProps->setLastModifiedBy(self::_convertStringEncoding($propertyValue,$this->_charSet)); |
||||
|
break; |
||||
|
case 'LastSaved' : |
||||
|
$lastSaveDate = strtotime($propertyValue); |
||||
|
$docProps->setModified($lastSaveDate); |
||||
|
break; |
||||
|
case 'Company' : |
||||
|
$docProps->setCompany(self::_convertStringEncoding($propertyValue,$this->_charSet)); |
||||
|
break; |
||||
|
case 'Category' : |
||||
|
$docProps->setCategory(self::_convertStringEncoding($propertyValue,$this->_charSet)); |
||||
|
break; |
||||
|
case 'Manager' : |
||||
|
$docProps->setManager(self::_convertStringEncoding($propertyValue,$this->_charSet)); |
||||
|
break; |
||||
|
case 'Keywords' : |
||||
|
$docProps->setKeywords(self::_convertStringEncoding($propertyValue,$this->_charSet)); |
||||
|
break; |
||||
|
case 'Description' : |
||||
|
$docProps->setDescription(self::_convertStringEncoding($propertyValue,$this->_charSet)); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
if (isset($xml->CustomDocumentProperties)) { |
||||
|
foreach($xml->CustomDocumentProperties[0] as $propertyName => $propertyValue) { |
||||
|
$propertyAttributes = $propertyValue->attributes($namespaces['dt']); |
||||
|
$propertyName = preg_replace_callback('/_x([0-9a-z]{4})_/','PHPExcel_Reader_Excel2003XML::_hex2str',$propertyName); |
||||
|
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_UNKNOWN; |
||||
|
switch((string) $propertyAttributes) { |
||||
|
case 'string' : |
||||
|
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING; |
||||
|
$propertyValue = trim($propertyValue); |
||||
|
break; |
||||
|
case 'boolean' : |
||||
|
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN; |
||||
|
$propertyValue = (bool) $propertyValue; |
||||
|
break; |
||||
|
case 'integer' : |
||||
|
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_INTEGER; |
||||
|
$propertyValue = intval($propertyValue); |
||||
|
break; |
||||
|
case 'float' : |
||||
|
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_FLOAT; |
||||
|
$propertyValue = floatval($propertyValue); |
||||
|
break; |
||||
|
case 'dateTime.tz' : |
||||
|
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE; |
||||
|
$propertyValue = strtotime(trim($propertyValue)); |
||||
|
break; |
||||
|
} |
||||
|
$docProps->setCustomProperty($propertyName,$propertyValue,$propertyType); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
foreach($xml->Styles[0] as $style) { |
||||
|
$style_ss = $style->attributes($namespaces['ss']); |
||||
|
$styleID = (string) $style_ss['ID']; |
||||
|
// echo 'Style ID = '.$styleID.'<br />'; |
||||
|
if ($styleID == 'Default') { |
||||
|
$this->_styles['Default'] = array(); |
||||
|
} else { |
||||
|
$this->_styles[$styleID] = $this->_styles['Default']; |
||||
|
} |
||||
|
foreach ($style as $styleType => $styleData) { |
||||
|
$styleAttributes = $styleData->attributes($namespaces['ss']); |
||||
|
// echo $styleType.'<br />'; |
||||
|
switch ($styleType) { |
||||
|
case 'Alignment' : |
||||
|
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) { |
||||
|
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />'; |
||||
|
$styleAttributeValue = (string) $styleAttributeValue; |
||||
|
switch ($styleAttributeKey) { |
||||
|
case 'Vertical' : |
||||
|
if (self::identifyFixedStyleValue($verticalAlignmentStyles,$styleAttributeValue)) { |
||||
|
$this->_styles[$styleID]['alignment']['vertical'] = $styleAttributeValue; |
||||
|
} |
||||
|
break; |
||||
|
case 'Horizontal' : |
||||
|
if (self::identifyFixedStyleValue($horizontalAlignmentStyles,$styleAttributeValue)) { |
||||
|
$this->_styles[$styleID]['alignment']['horizontal'] = $styleAttributeValue; |
||||
|
} |
||||
|
break; |
||||
|
case 'WrapText' : |
||||
|
$this->_styles[$styleID]['alignment']['wrap'] = true; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
break; |
||||
|
case 'Borders' : |
||||
|
foreach($styleData->Border as $borderStyle) { |
||||
|
$borderAttributes = $borderStyle->attributes($namespaces['ss']); |
||||
|
$thisBorder = array(); |
||||
|
foreach($borderAttributes as $borderStyleKey => $borderStyleValue) { |
||||
|
// echo $borderStyleKey.' = '.$borderStyleValue.'<br />'; |
||||
|
switch ($borderStyleKey) { |
||||
|
case 'LineStyle' : |
||||
|
$thisBorder['style'] = PHPExcel_Style_Border::BORDER_MEDIUM; |
||||
|
// $thisBorder['style'] = $borderStyleValue; |
||||
|
break; |
||||
|
case 'Weight' : |
||||
|
// $thisBorder['style'] = $borderStyleValue; |
||||
|
break; |
||||
|
case 'Position' : |
||||
|
$borderPosition = strtolower($borderStyleValue); |
||||
|
break; |
||||
|
case 'Color' : |
||||
|
$borderColour = substr($borderStyleValue,1); |
||||
|
$thisBorder['color']['rgb'] = $borderColour; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
if (!empty($thisBorder)) { |
||||
|
if (($borderPosition == 'left') || ($borderPosition == 'right') || ($borderPosition == 'top') || ($borderPosition == 'bottom')) { |
||||
|
$this->_styles[$styleID]['borders'][$borderPosition] = $thisBorder; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
break; |
||||
|
case 'Font' : |
||||
|
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) { |
||||
|
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />'; |
||||
|
$styleAttributeValue = (string) $styleAttributeValue; |
||||
|
switch ($styleAttributeKey) { |
||||
|
case 'FontName' : |
||||
|
$this->_styles[$styleID]['font']['name'] = $styleAttributeValue; |
||||
|
break; |
||||
|
case 'Size' : |
||||
|
$this->_styles[$styleID]['font']['size'] = $styleAttributeValue; |
||||
|
break; |
||||
|
case 'Color' : |
||||
|
$this->_styles[$styleID]['font']['color']['rgb'] = substr($styleAttributeValue,1); |
||||
|
break; |
||||
|
case 'Bold' : |
||||
|
$this->_styles[$styleID]['font']['bold'] = true; |
||||
|
break; |
||||
|
case 'Italic' : |
||||
|
$this->_styles[$styleID]['font']['italic'] = true; |
||||
|
break; |
||||
|
case 'Underline' : |
||||
|
if (self::identifyFixedStyleValue($underlineStyles,$styleAttributeValue)) { |
||||
|
$this->_styles[$styleID]['font']['underline'] = $styleAttributeValue; |
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
break; |
||||
|
case 'Interior' : |
||||
|
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) { |
||||
|
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />'; |
||||
|
switch ($styleAttributeKey) { |
||||
|
case 'Color' : |
||||
|
$this->_styles[$styleID]['fill']['color']['rgb'] = substr($styleAttributeValue,1); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
break; |
||||
|
case 'NumberFormat' : |
||||
|
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) { |
||||
|
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />'; |
||||
|
$styleAttributeValue = str_replace($fromFormats,$toFormats,$styleAttributeValue); |
||||
|
switch ($styleAttributeValue) { |
||||
|
case 'Short Date' : |
||||
|
$styleAttributeValue = 'dd/mm/yyyy'; |
||||
|
break; |
||||
|
} |
||||
|
if ($styleAttributeValue > '') { |
||||
|
$this->_styles[$styleID]['numberformat']['code'] = $styleAttributeValue; |
||||
|
} |
||||
|
} |
||||
|
break; |
||||
|
case 'Protection' : |
||||
|
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) { |
||||
|
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />'; |
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
// print_r($this->_styles[$styleID]); |
||||
|
// echo '<hr />'; |
||||
|
} |
||||
|
// echo '<hr />'; |
||||
|
|
||||
|
$worksheetID = 0; |
||||
|
$xml_ss = $xml->children($namespaces['ss']); |
||||
|
|
||||
|
foreach($xml_ss->Worksheet as $worksheet) { |
||||
|
$worksheet_ss = $worksheet->attributes($namespaces['ss']); |
||||
|
|
||||
|
if ((isset($this->_loadSheetsOnly)) && (isset($worksheet_ss['Name'])) && |
||||
|
(!in_array($worksheet_ss['Name'], $this->_loadSheetsOnly))) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// echo '<h3>Worksheet: ',$worksheet_ss['Name'],'<h3>'; |
||||
|
// |
||||
|
// Create new Worksheet |
||||
|
$objPHPExcel->createSheet(); |
||||
|
$objPHPExcel->setActiveSheetIndex($worksheetID); |
||||
|
if (isset($worksheet_ss['Name'])) { |
||||
|
$worksheetName = self::_convertStringEncoding((string) $worksheet_ss['Name'],$this->_charSet); |
||||
|
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in |
||||
|
// formula cells... during the load, all formulae should be correct, and we're simply bringing |
||||
|
// the worksheet name in line with the formula, not the reverse |
||||
|
$objPHPExcel->getActiveSheet()->setTitle($worksheetName,false); |
||||
|
} |
||||
|
|
||||
|
$columnID = 'A'; |
||||
|
if (isset($worksheet->Table->Column)) { |
||||
|
foreach($worksheet->Table->Column as $columnData) { |
||||
|
$columnData_ss = $columnData->attributes($namespaces['ss']); |
||||
|
if (isset($columnData_ss['Index'])) { |
||||
|
$columnID = PHPExcel_Cell::stringFromColumnIndex($columnData_ss['Index']-1); |
||||
|
} |
||||
|
if (isset($columnData_ss['Width'])) { |
||||
|
$columnWidth = $columnData_ss['Width']; |
||||
|
// echo '<b>Setting column width for '.$columnID.' to '.$columnWidth.'</b><br />'; |
||||
|
$objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setWidth($columnWidth / 5.4); |
||||
|
} |
||||
|
++$columnID; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$rowID = 1; |
||||
|
if (isset($worksheet->Table->Row)) { |
||||
|
foreach($worksheet->Table->Row as $rowData) { |
||||
|
$rowHasData = false; |
||||
|
$row_ss = $rowData->attributes($namespaces['ss']); |
||||
|
if (isset($row_ss['Index'])) { |
||||
|
$rowID = (integer) $row_ss['Index']; |
||||
|
} |
||||
|
// echo '<b>Row '.$rowID.'</b><br />'; |
||||
|
|
||||
|
$columnID = 'A'; |
||||
|
foreach($rowData->Cell as $cell) { |
||||
|
|
||||
|
$cell_ss = $cell->attributes($namespaces['ss']); |
||||
|
if (isset($cell_ss['Index'])) { |
||||
|
$columnID = PHPExcel_Cell::stringFromColumnIndex($cell_ss['Index']-1); |
||||
|
} |
||||
|
$cellRange = $columnID.$rowID; |
||||
|
|
||||
|
if ($this->getReadFilter() !== NULL) { |
||||
|
if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) { |
||||
|
continue; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if ((isset($cell_ss['MergeAcross'])) || (isset($cell_ss['MergeDown']))) { |
||||
|
$columnTo = $columnID; |
||||
|
if (isset($cell_ss['MergeAcross'])) { |
||||
|
$columnTo = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cell_ss['MergeAcross'] -1); |
||||
|
} |
||||
|
$rowTo = $rowID; |
||||
|
if (isset($cell_ss['MergeDown'])) { |
||||
|
$rowTo = $rowTo + $cell_ss['MergeDown']; |
||||
|
} |
||||
|
$cellRange .= ':'.$columnTo.$rowTo; |
||||
|
$objPHPExcel->getActiveSheet()->mergeCells($cellRange); |
||||
|
} |
||||
|
|
||||
|
$cellIsSet = $hasCalculatedValue = false; |
||||
|
$cellDataFormula = ''; |
||||
|
if (isset($cell_ss['Formula'])) { |
||||
|
$cellDataFormula = $cell_ss['Formula']; |
||||
|
// added this as a check for array formulas |
||||
|
if (isset($cell_ss['ArrayRange'])) { |
||||
|
$cellDataCSEFormula = $cell_ss['ArrayRange']; |
||||
|
// echo "found an array formula at ".$columnID.$rowID."<br />"; |
||||
|
} |
||||
|
$hasCalculatedValue = true; |
||||
|
} |
||||
|
if (isset($cell->Data)) { |
||||
|
$cellValue = $cellData = $cell->Data; |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_NULL; |
||||
|
$cellData_ss = $cellData->attributes($namespaces['ss']); |
||||
|
if (isset($cellData_ss['Type'])) { |
||||
|
$cellDataType = $cellData_ss['Type']; |
||||
|
switch ($cellDataType) { |
||||
|
/* |
||||
|
const TYPE_STRING = 's'; |
||||
|
const TYPE_FORMULA = 'f'; |
||||
|
const TYPE_NUMERIC = 'n'; |
||||
|
const TYPE_BOOL = 'b'; |
||||
|
const TYPE_NULL = 'null'; |
||||
|
const TYPE_INLINE = 'inlineStr'; |
||||
|
const TYPE_ERROR = 'e'; |
||||
|
*/ |
||||
|
case 'String' : |
||||
|
$cellValue = self::_convertStringEncoding($cellValue,$this->_charSet); |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_STRING; |
||||
|
break; |
||||
|
case 'Number' : |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC; |
||||
|
$cellValue = (float) $cellValue; |
||||
|
if (floor($cellValue) == $cellValue) { |
||||
|
$cellValue = (integer) $cellValue; |
||||
|
} |
||||
|
break; |
||||
|
case 'Boolean' : |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_BOOL; |
||||
|
$cellValue = ($cellValue != 0); |
||||
|
break; |
||||
|
case 'DateTime' : |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC; |
||||
|
$cellValue = PHPExcel_Shared_Date::PHPToExcel(strtotime($cellValue)); |
||||
|
break; |
||||
|
case 'Error' : |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_ERROR; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if ($hasCalculatedValue) { |
||||
|
// echo 'FORMULA<br />'; |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_FORMULA; |
||||
|
$columnNumber = PHPExcel_Cell::columnIndexFromString($columnID); |
||||
|
if (substr($cellDataFormula,0,3) == 'of:') { |
||||
|
$cellDataFormula = substr($cellDataFormula,3); |
||||
|
// echo 'Before: ',$cellDataFormula,'<br />'; |
||||
|
$temp = explode('"',$cellDataFormula); |
||||
|
$key = false; |
||||
|
foreach($temp as &$value) { |
||||
|
// Only replace in alternate array entries (i.e. non-quoted blocks) |
||||
|
if ($key = !$key) { |
||||
|
$value = str_replace(array('[.','.',']'),'',$value); |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
// Convert R1C1 style references to A1 style references (but only when not quoted) |
||||
|
// echo 'Before: ',$cellDataFormula,'<br />'; |
||||
|
$temp = explode('"',$cellDataFormula); |
||||
|
$key = false; |
||||
|
foreach($temp as &$value) { |
||||
|
// Only replace in alternate array entries (i.e. non-quoted blocks) |
||||
|
if ($key = !$key) { |
||||
|
preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE); |
||||
|
// Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way |
||||
|
// through the formula from left to right. Reversing means that we work right to left.through |
||||
|
// the formula |
||||
|
$cellReferences = array_reverse($cellReferences); |
||||
|
// Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent, |
||||
|
// then modify the formula to use that new reference |
||||
|
foreach($cellReferences as $cellReference) { |
||||
|
$rowReference = $cellReference[2][0]; |
||||
|
// Empty R reference is the current row |
||||
|
if ($rowReference == '') $rowReference = $rowID; |
||||
|
// Bracketed R references are relative to the current row |
||||
|
if ($rowReference{0} == '[') $rowReference = $rowID + trim($rowReference,'[]'); |
||||
|
$columnReference = $cellReference[4][0]; |
||||
|
// Empty C reference is the current column |
||||
|
if ($columnReference == '') $columnReference = $columnNumber; |
||||
|
// Bracketed C references are relative to the current column |
||||
|
if ($columnReference{0} == '[') $columnReference = $columnNumber + trim($columnReference,'[]'); |
||||
|
$A1CellReference = PHPExcel_Cell::stringFromColumnIndex($columnReference-1).$rowReference; |
||||
|
$value = substr_replace($value,$A1CellReference,$cellReference[0][1],strlen($cellReference[0][0])); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
unset($value); |
||||
|
// Then rebuild the formula string |
||||
|
$cellDataFormula = implode('"',$temp); |
||||
|
// echo 'After: ',$cellDataFormula,'<br />'; |
||||
|
} |
||||
|
|
||||
|
// echo 'Cell '.$columnID.$rowID.' is a '.$type.' with a value of '.(($hasCalculatedValue) ? $cellDataFormula : $cellValue).'<br />'; |
||||
|
// |
||||
|
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $cellValue),$type); |
||||
|
if ($hasCalculatedValue) { |
||||
|
// echo 'Formula result is '.$cellValue.'<br />'; |
||||
|
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setCalculatedValue($cellValue); |
||||
|
} |
||||
|
$cellIsSet = $rowHasData = true; |
||||
|
} |
||||
|
|
||||
|
if (isset($cell->Comment)) { |
||||
|
// echo '<b>comment found</b><br />'; |
||||
|
$commentAttributes = $cell->Comment->attributes($namespaces['ss']); |
||||
|
$author = 'unknown'; |
||||
|
if (isset($commentAttributes->Author)) { |
||||
|
$author = (string)$commentAttributes->Author; |
||||
|
// echo 'Author: ',$author,'<br />'; |
||||
|
} |
||||
|
$node = $cell->Comment->Data->asXML(); |
||||
|
// $annotation = str_replace('html:','',substr($node,49,-10)); |
||||
|
// echo $annotation,'<br />'; |
||||
|
$annotation = strip_tags($node); |
||||
|
// echo 'Annotation: ',$annotation,'<br />'; |
||||
|
$objPHPExcel->getActiveSheet()->getComment( $columnID.$rowID ) |
||||
|
->setAuthor(self::_convertStringEncoding($author ,$this->_charSet)) |
||||
|
->setText($this->_parseRichText($annotation) ); |
||||
|
} |
||||
|
|
||||
|
if (($cellIsSet) && (isset($cell_ss['StyleID']))) { |
||||
|
$style = (string) $cell_ss['StyleID']; |
||||
|
// echo 'Cell style for '.$columnID.$rowID.' is '.$style.'<br />'; |
||||
|
if ((isset($this->_styles[$style])) && (!empty($this->_styles[$style]))) { |
||||
|
// echo 'Cell '.$columnID.$rowID.'<br />'; |
||||
|
// print_r($this->_styles[$style]); |
||||
|
// echo '<br />'; |
||||
|
if (!$objPHPExcel->getActiveSheet()->cellExists($columnID.$rowID)) { |
||||
|
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValue(NULL); |
||||
|
} |
||||
|
$objPHPExcel->getActiveSheet()->getStyle($cellRange)->applyFromArray($this->_styles[$style]); |
||||
|
} |
||||
|
} |
||||
|
++$columnID; |
||||
|
} |
||||
|
|
||||
|
if ($rowHasData) { |
||||
|
if (isset($row_ss['StyleID'])) { |
||||
|
$rowStyle = $row_ss['StyleID']; |
||||
|
} |
||||
|
if (isset($row_ss['Height'])) { |
||||
|
$rowHeight = $row_ss['Height']; |
||||
|
// echo '<b>Setting row height to '.$rowHeight.'</b><br />'; |
||||
|
$objPHPExcel->getActiveSheet()->getRowDimension($rowID)->setRowHeight($rowHeight); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
++$rowID; |
||||
|
} |
||||
|
} |
||||
|
++$worksheetID; |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
return $objPHPExcel; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private static function _convertStringEncoding($string,$charset) { |
||||
|
if ($charset != 'UTF-8') { |
||||
|
return PHPExcel_Shared_String::ConvertEncoding($string,'UTF-8',$charset); |
||||
|
} |
||||
|
return $string; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private function _parseRichText($is = '') { |
||||
|
$value = new PHPExcel_RichText(); |
||||
|
|
||||
|
$value->createText(self::_convertStringEncoding($is,$this->_charSet)); |
||||
|
|
||||
|
return $value; |
||||
|
} |
||||
|
|
||||
|
} |
||||
File diff suppressed because it is too large
@ -0,0 +1,517 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader_Excel2007 |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_Excel2007_Chart |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader_Excel2007 |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Reader_Excel2007_Chart |
||||
|
{ |
||||
|
private static function _getAttribute($component, $name, $format) { |
||||
|
$attributes = $component->attributes(); |
||||
|
if (isset($attributes[$name])) { |
||||
|
if ($format == 'string') { |
||||
|
return (string) $attributes[$name]; |
||||
|
} elseif ($format == 'integer') { |
||||
|
return (integer) $attributes[$name]; |
||||
|
} elseif ($format == 'boolean') { |
||||
|
return (boolean) ($attributes[$name] === '0' || $attributes[$name] !== 'true') ? false : true; |
||||
|
} else { |
||||
|
return (float) $attributes[$name]; |
||||
|
} |
||||
|
} |
||||
|
return null; |
||||
|
} // function _getAttribute() |
||||
|
|
||||
|
|
||||
|
private static function _readColor($color,$background=false) { |
||||
|
if (isset($color["rgb"])) { |
||||
|
return (string)$color["rgb"]; |
||||
|
} else if (isset($color["indexed"])) { |
||||
|
return PHPExcel_Style_Color::indexedColor($color["indexed"]-7,$background)->getARGB(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public static function readChart($chartElements,$chartName) { |
||||
|
$namespacesChartMeta = $chartElements->getNamespaces(true); |
||||
|
$chartElementsC = $chartElements->children($namespacesChartMeta['c']); |
||||
|
|
||||
|
$XaxisLabel = $YaxisLabel = $legend = $title = NULL; |
||||
|
$dispBlanksAs = $plotVisOnly = NULL; |
||||
|
|
||||
|
foreach($chartElementsC as $chartElementKey => $chartElement) { |
||||
|
switch ($chartElementKey) { |
||||
|
case "chart": |
||||
|
foreach($chartElement as $chartDetailsKey => $chartDetails) { |
||||
|
$chartDetailsC = $chartDetails->children($namespacesChartMeta['c']); |
||||
|
switch ($chartDetailsKey) { |
||||
|
case "plotArea": |
||||
|
$plotAreaLayout = $XaxisLable = $YaxisLable = null; |
||||
|
$plotSeries = $plotAttributes = array(); |
||||
|
foreach($chartDetails as $chartDetailKey => $chartDetail) { |
||||
|
switch ($chartDetailKey) { |
||||
|
case "layout": |
||||
|
$plotAreaLayout = self::_chartLayoutDetails($chartDetail,$namespacesChartMeta,'plotArea'); |
||||
|
break; |
||||
|
case "catAx": |
||||
|
if (isset($chartDetail->title)) { |
||||
|
$XaxisLabel = self::_chartTitle($chartDetail->title->children($namespacesChartMeta['c']),$namespacesChartMeta,'cat'); |
||||
|
} |
||||
|
break; |
||||
|
case "dateAx": |
||||
|
if (isset($chartDetail->title)) { |
||||
|
$XaxisLabel = self::_chartTitle($chartDetail->title->children($namespacesChartMeta['c']),$namespacesChartMeta,'cat'); |
||||
|
} |
||||
|
break; |
||||
|
case "valAx": |
||||
|
if (isset($chartDetail->title)) { |
||||
|
$YaxisLabel = self::_chartTitle($chartDetail->title->children($namespacesChartMeta['c']),$namespacesChartMeta,'cat'); |
||||
|
} |
||||
|
break; |
||||
|
case "barChart": |
||||
|
case "bar3DChart": |
||||
|
$barDirection = self::_getAttribute($chartDetail->barDir, 'val', 'string'); |
||||
|
$plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey); |
||||
|
$plotSer->setPlotDirection($barDirection); |
||||
|
$plotSeries[] = $plotSer; |
||||
|
$plotAttributes = self::_readChartAttributes($chartDetail); |
||||
|
break; |
||||
|
case "lineChart": |
||||
|
case "line3DChart": |
||||
|
$plotSeries[] = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey); |
||||
|
$plotAttributes = self::_readChartAttributes($chartDetail); |
||||
|
break; |
||||
|
case "areaChart": |
||||
|
case "area3DChart": |
||||
|
$plotSeries[] = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey); |
||||
|
$plotAttributes = self::_readChartAttributes($chartDetail); |
||||
|
break; |
||||
|
case "doughnutChart": |
||||
|
case "pieChart": |
||||
|
case "pie3DChart": |
||||
|
$explosion = isset($chartDetail->ser->explosion); |
||||
|
$plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey); |
||||
|
$plotSer->setPlotStyle($explosion); |
||||
|
$plotSeries[] = $plotSer; |
||||
|
$plotAttributes = self::_readChartAttributes($chartDetail); |
||||
|
break; |
||||
|
case "scatterChart": |
||||
|
$scatterStyle = self::_getAttribute($chartDetail->scatterStyle, 'val', 'string'); |
||||
|
$plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey); |
||||
|
$plotSer->setPlotStyle($scatterStyle); |
||||
|
$plotSeries[] = $plotSer; |
||||
|
$plotAttributes = self::_readChartAttributes($chartDetail); |
||||
|
break; |
||||
|
case "bubbleChart": |
||||
|
$bubbleScale = self::_getAttribute($chartDetail->bubbleScale, 'val', 'integer'); |
||||
|
$plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey); |
||||
|
$plotSer->setPlotStyle($bubbleScale); |
||||
|
$plotSeries[] = $plotSer; |
||||
|
$plotAttributes = self::_readChartAttributes($chartDetail); |
||||
|
break; |
||||
|
case "radarChart": |
||||
|
$radarStyle = self::_getAttribute($chartDetail->radarStyle, 'val', 'string'); |
||||
|
$plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey); |
||||
|
$plotSer->setPlotStyle($radarStyle); |
||||
|
$plotSeries[] = $plotSer; |
||||
|
$plotAttributes = self::_readChartAttributes($chartDetail); |
||||
|
break; |
||||
|
case "surfaceChart": |
||||
|
case "surface3DChart": |
||||
|
$wireFrame = self::_getAttribute($chartDetail->wireframe, 'val', 'boolean'); |
||||
|
$plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey); |
||||
|
$plotSer->setPlotStyle($wireFrame); |
||||
|
$plotSeries[] = $plotSer; |
||||
|
$plotAttributes = self::_readChartAttributes($chartDetail); |
||||
|
break; |
||||
|
case "stockChart": |
||||
|
$plotSeries[] = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey); |
||||
|
$plotAttributes = self::_readChartAttributes($plotAreaLayout); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
if ($plotAreaLayout == NULL) { |
||||
|
$plotAreaLayout = new PHPExcel_Chart_Layout(); |
||||
|
} |
||||
|
$plotArea = new PHPExcel_Chart_PlotArea($plotAreaLayout,$plotSeries); |
||||
|
self::_setChartAttributes($plotAreaLayout,$plotAttributes); |
||||
|
break; |
||||
|
case "plotVisOnly": |
||||
|
$plotVisOnly = self::_getAttribute($chartDetails, 'val', 'string'); |
||||
|
break; |
||||
|
case "dispBlanksAs": |
||||
|
$dispBlanksAs = self::_getAttribute($chartDetails, 'val', 'string'); |
||||
|
break; |
||||
|
case "title": |
||||
|
$title = self::_chartTitle($chartDetails,$namespacesChartMeta,'title'); |
||||
|
break; |
||||
|
case "legend": |
||||
|
$legendPos = 'r'; |
||||
|
$legendLayout = null; |
||||
|
$legendOverlay = false; |
||||
|
foreach($chartDetails as $chartDetailKey => $chartDetail) { |
||||
|
switch ($chartDetailKey) { |
||||
|
case "legendPos": |
||||
|
$legendPos = self::_getAttribute($chartDetail, 'val', 'string'); |
||||
|
break; |
||||
|
case "overlay": |
||||
|
$legendOverlay = self::_getAttribute($chartDetail, 'val', 'boolean'); |
||||
|
break; |
||||
|
case "layout": |
||||
|
$legendLayout = self::_chartLayoutDetails($chartDetail,$namespacesChartMeta,'legend'); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
$legend = new PHPExcel_Chart_Legend($legendPos, $legendLayout, $legendOverlay); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$chart = new PHPExcel_Chart($chartName,$title,$legend,$plotArea,$plotVisOnly,$dispBlanksAs,$XaxisLabel,$YaxisLabel); |
||||
|
|
||||
|
return $chart; |
||||
|
} // function readChart() |
||||
|
|
||||
|
|
||||
|
private static function _chartTitle($titleDetails,$namespacesChartMeta,$type) { |
||||
|
$caption = array(); |
||||
|
$titleLayout = null; |
||||
|
foreach($titleDetails as $titleDetailKey => $chartDetail) { |
||||
|
switch ($titleDetailKey) { |
||||
|
case "tx": |
||||
|
$titleDetails = $chartDetail->rich->children($namespacesChartMeta['a']); |
||||
|
foreach($titleDetails as $titleKey => $titleDetail) { |
||||
|
switch ($titleKey) { |
||||
|
case "p": |
||||
|
$titleDetailPart = $titleDetail->children($namespacesChartMeta['a']); |
||||
|
$caption[] = self::_parseRichText($titleDetailPart); |
||||
|
} |
||||
|
} |
||||
|
break; |
||||
|
case "layout": |
||||
|
$titleLayout = self::_chartLayoutDetails($chartDetail,$namespacesChartMeta); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return new PHPExcel_Chart_Title($caption, $titleLayout); |
||||
|
} // function _chartTitle() |
||||
|
|
||||
|
|
||||
|
private static function _chartLayoutDetails($chartDetail,$namespacesChartMeta) { |
||||
|
if (!isset($chartDetail->manualLayout)) { |
||||
|
return null; |
||||
|
} |
||||
|
$details = $chartDetail->manualLayout->children($namespacesChartMeta['c']); |
||||
|
if (is_null($details)) { |
||||
|
return null; |
||||
|
} |
||||
|
$layout = array(); |
||||
|
foreach($details as $detailKey => $detail) { |
||||
|
// echo $detailKey,' => ',self::_getAttribute($detail, 'val', 'string'),PHP_EOL; |
||||
|
$layout[$detailKey] = self::_getAttribute($detail, 'val', 'string'); |
||||
|
} |
||||
|
return new PHPExcel_Chart_Layout($layout); |
||||
|
} // function _chartLayoutDetails() |
||||
|
|
||||
|
|
||||
|
private static function _chartDataSeries($chartDetail,$namespacesChartMeta,$plotType) { |
||||
|
$multiSeriesType = NULL; |
||||
|
$smoothLine = false; |
||||
|
$seriesLabel = $seriesCategory = $seriesValues = $plotOrder = array(); |
||||
|
|
||||
|
$seriesDetailSet = $chartDetail->children($namespacesChartMeta['c']); |
||||
|
foreach($seriesDetailSet as $seriesDetailKey => $seriesDetails) { |
||||
|
switch ($seriesDetailKey) { |
||||
|
case "grouping": |
||||
|
$multiSeriesType = self::_getAttribute($chartDetail->grouping, 'val', 'string'); |
||||
|
break; |
||||
|
case "ser": |
||||
|
$marker = NULL; |
||||
|
foreach($seriesDetails as $seriesKey => $seriesDetail) { |
||||
|
switch ($seriesKey) { |
||||
|
case "idx": |
||||
|
$seriesIndex = self::_getAttribute($seriesDetail, 'val', 'integer'); |
||||
|
break; |
||||
|
case "order": |
||||
|
$seriesOrder = self::_getAttribute($seriesDetail, 'val', 'integer'); |
||||
|
$plotOrder[$seriesIndex] = $seriesOrder; |
||||
|
break; |
||||
|
case "tx": |
||||
|
$seriesLabel[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta); |
||||
|
break; |
||||
|
case "marker": |
||||
|
$marker = self::_getAttribute($seriesDetail->symbol, 'val', 'string'); |
||||
|
break; |
||||
|
case "smooth": |
||||
|
$smoothLine = self::_getAttribute($seriesDetail, 'val', 'boolean'); |
||||
|
break; |
||||
|
case "cat": |
||||
|
$seriesCategory[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta); |
||||
|
break; |
||||
|
case "val": |
||||
|
$seriesValues[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta,$marker); |
||||
|
break; |
||||
|
case "xVal": |
||||
|
$seriesCategory[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta,$marker); |
||||
|
break; |
||||
|
case "yVal": |
||||
|
$seriesValues[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta,$marker); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return new PHPExcel_Chart_DataSeries($plotType,$multiSeriesType,$plotOrder,$seriesLabel,$seriesCategory,$seriesValues,$smoothLine); |
||||
|
} // function _chartDataSeries() |
||||
|
|
||||
|
|
||||
|
private static function _chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker = null, $smoothLine = false) { |
||||
|
if (isset($seriesDetail->strRef)) { |
||||
|
$seriesSource = (string) $seriesDetail->strRef->f; |
||||
|
$seriesData = self::_chartDataSeriesValues($seriesDetail->strRef->strCache->children($namespacesChartMeta['c']),'s'); |
||||
|
|
||||
|
return new PHPExcel_Chart_DataSeriesValues('String',$seriesSource,$seriesData['formatCode'],$seriesData['pointCount'],$seriesData['dataValues'],$marker,$smoothLine); |
||||
|
} elseif (isset($seriesDetail->numRef)) { |
||||
|
$seriesSource = (string) $seriesDetail->numRef->f; |
||||
|
$seriesData = self::_chartDataSeriesValues($seriesDetail->numRef->numCache->children($namespacesChartMeta['c'])); |
||||
|
|
||||
|
return new PHPExcel_Chart_DataSeriesValues('Number',$seriesSource,$seriesData['formatCode'],$seriesData['pointCount'],$seriesData['dataValues'],$marker,$smoothLine); |
||||
|
} elseif (isset($seriesDetail->multiLvlStrRef)) { |
||||
|
$seriesSource = (string) $seriesDetail->multiLvlStrRef->f; |
||||
|
$seriesData = self::_chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlStrRef->multiLvlStrCache->children($namespacesChartMeta['c']),'s'); |
||||
|
$seriesData['pointCount'] = count($seriesData['dataValues']); |
||||
|
|
||||
|
return new PHPExcel_Chart_DataSeriesValues('String',$seriesSource,$seriesData['formatCode'],$seriesData['pointCount'],$seriesData['dataValues'],$marker,$smoothLine); |
||||
|
} elseif (isset($seriesDetail->multiLvlNumRef)) { |
||||
|
$seriesSource = (string) $seriesDetail->multiLvlNumRef->f; |
||||
|
$seriesData = self::_chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlNumRef->multiLvlNumCache->children($namespacesChartMeta['c']),'s'); |
||||
|
$seriesData['pointCount'] = count($seriesData['dataValues']); |
||||
|
|
||||
|
return new PHPExcel_Chart_DataSeriesValues('String',$seriesSource,$seriesData['formatCode'],$seriesData['pointCount'],$seriesData['dataValues'],$marker,$smoothLine); |
||||
|
} |
||||
|
return null; |
||||
|
} // function _chartDataSeriesValueSet() |
||||
|
|
||||
|
|
||||
|
private static function _chartDataSeriesValues($seriesValueSet,$dataType='n') { |
||||
|
$seriesVal = array(); |
||||
|
$formatCode = ''; |
||||
|
$pointCount = 0; |
||||
|
|
||||
|
foreach($seriesValueSet as $seriesValueIdx => $seriesValue) { |
||||
|
switch ($seriesValueIdx) { |
||||
|
case 'ptCount': |
||||
|
$pointCount = self::_getAttribute($seriesValue, 'val', 'integer'); |
||||
|
break; |
||||
|
case 'formatCode': |
||||
|
$formatCode = (string) $seriesValue; |
||||
|
break; |
||||
|
case 'pt': |
||||
|
$pointVal = self::_getAttribute($seriesValue, 'idx', 'integer'); |
||||
|
if ($dataType == 's') { |
||||
|
$seriesVal[$pointVal] = (string) $seriesValue->v; |
||||
|
} else { |
||||
|
$seriesVal[$pointVal] = (float) $seriesValue->v; |
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (empty($seriesVal)) { |
||||
|
$seriesVal = NULL; |
||||
|
} |
||||
|
|
||||
|
return array( 'formatCode' => $formatCode, |
||||
|
'pointCount' => $pointCount, |
||||
|
'dataValues' => $seriesVal |
||||
|
); |
||||
|
} // function _chartDataSeriesValues() |
||||
|
|
||||
|
|
||||
|
private static function _chartDataSeriesValuesMultiLevel($seriesValueSet,$dataType='n') { |
||||
|
$seriesVal = array(); |
||||
|
$formatCode = ''; |
||||
|
$pointCount = 0; |
||||
|
|
||||
|
foreach($seriesValueSet->lvl as $seriesLevelIdx => $seriesLevel) { |
||||
|
foreach($seriesLevel as $seriesValueIdx => $seriesValue) { |
||||
|
switch ($seriesValueIdx) { |
||||
|
case 'ptCount': |
||||
|
$pointCount = self::_getAttribute($seriesValue, 'val', 'integer'); |
||||
|
break; |
||||
|
case 'formatCode': |
||||
|
$formatCode = (string) $seriesValue; |
||||
|
break; |
||||
|
case 'pt': |
||||
|
$pointVal = self::_getAttribute($seriesValue, 'idx', 'integer'); |
||||
|
if ($dataType == 's') { |
||||
|
$seriesVal[$pointVal][] = (string) $seriesValue->v; |
||||
|
} else { |
||||
|
$seriesVal[$pointVal][] = (float) $seriesValue->v; |
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return array( 'formatCode' => $formatCode, |
||||
|
'pointCount' => $pointCount, |
||||
|
'dataValues' => $seriesVal |
||||
|
); |
||||
|
} // function _chartDataSeriesValuesMultiLevel() |
||||
|
|
||||
|
private static function _parseRichText($titleDetailPart = null) { |
||||
|
$value = new PHPExcel_RichText(); |
||||
|
|
||||
|
foreach($titleDetailPart as $titleDetailElementKey => $titleDetailElement) { |
||||
|
if (isset($titleDetailElement->t)) { |
||||
|
$objText = $value->createTextRun( (string) $titleDetailElement->t ); |
||||
|
} |
||||
|
if (isset($titleDetailElement->rPr)) { |
||||
|
if (isset($titleDetailElement->rPr->rFont["val"])) { |
||||
|
$objText->getFont()->setName((string) $titleDetailElement->rPr->rFont["val"]); |
||||
|
} |
||||
|
|
||||
|
$fontSize = (self::_getAttribute($titleDetailElement->rPr, 'sz', 'integer')); |
||||
|
if (!is_null($fontSize)) { |
||||
|
$objText->getFont()->setSize(floor($fontSize / 100)); |
||||
|
} |
||||
|
|
||||
|
$fontColor = (self::_getAttribute($titleDetailElement->rPr, 'color', 'string')); |
||||
|
if (!is_null($fontColor)) { |
||||
|
$objText->getFont()->setColor( new PHPExcel_Style_Color( self::_readColor($fontColor) ) ); |
||||
|
} |
||||
|
|
||||
|
$bold = self::_getAttribute($titleDetailElement->rPr, 'b', 'boolean'); |
||||
|
if (!is_null($bold)) { |
||||
|
$objText->getFont()->setBold($bold); |
||||
|
} |
||||
|
|
||||
|
$italic = self::_getAttribute($titleDetailElement->rPr, 'i', 'boolean'); |
||||
|
if (!is_null($italic)) { |
||||
|
$objText->getFont()->setItalic($italic); |
||||
|
} |
||||
|
|
||||
|
$baseline = self::_getAttribute($titleDetailElement->rPr, 'baseline', 'integer'); |
||||
|
if (!is_null($baseline)) { |
||||
|
if ($baseline > 0) { |
||||
|
$objText->getFont()->setSuperScript(true); |
||||
|
} elseif($baseline < 0) { |
||||
|
$objText->getFont()->setSubScript(true); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$underscore = (self::_getAttribute($titleDetailElement->rPr, 'u', 'string')); |
||||
|
if (!is_null($underscore)) { |
||||
|
if ($underscore == 'sng') { |
||||
|
$objText->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE); |
||||
|
} elseif($underscore == 'dbl') { |
||||
|
$objText->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_DOUBLE); |
||||
|
} else { |
||||
|
$objText->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_NONE); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$strikethrough = (self::_getAttribute($titleDetailElement->rPr, 's', 'string')); |
||||
|
if (!is_null($strikethrough)) { |
||||
|
if ($strikethrough == 'noStrike') { |
||||
|
$objText->getFont()->setStrikethrough(false); |
||||
|
} else { |
||||
|
$objText->getFont()->setStrikethrough(true); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $value; |
||||
|
} |
||||
|
|
||||
|
private static function _readChartAttributes($chartDetail) { |
||||
|
$plotAttributes = array(); |
||||
|
if (isset($chartDetail->dLbls)) { |
||||
|
if (isset($chartDetail->dLbls->howLegendKey)) { |
||||
|
$plotAttributes['showLegendKey'] = self::_getAttribute($chartDetail->dLbls->showLegendKey, 'val', 'string'); |
||||
|
} |
||||
|
if (isset($chartDetail->dLbls->showVal)) { |
||||
|
$plotAttributes['showVal'] = self::_getAttribute($chartDetail->dLbls->showVal, 'val', 'string'); |
||||
|
} |
||||
|
if (isset($chartDetail->dLbls->showCatName)) { |
||||
|
$plotAttributes['showCatName'] = self::_getAttribute($chartDetail->dLbls->showCatName, 'val', 'string'); |
||||
|
} |
||||
|
if (isset($chartDetail->dLbls->showSerName)) { |
||||
|
$plotAttributes['showSerName'] = self::_getAttribute($chartDetail->dLbls->showSerName, 'val', 'string'); |
||||
|
} |
||||
|
if (isset($chartDetail->dLbls->showPercent)) { |
||||
|
$plotAttributes['showPercent'] = self::_getAttribute($chartDetail->dLbls->showPercent, 'val', 'string'); |
||||
|
} |
||||
|
if (isset($chartDetail->dLbls->showBubbleSize)) { |
||||
|
$plotAttributes['showBubbleSize'] = self::_getAttribute($chartDetail->dLbls->showBubbleSize, 'val', 'string'); |
||||
|
} |
||||
|
if (isset($chartDetail->dLbls->showLeaderLines)) { |
||||
|
$plotAttributes['showLeaderLines'] = self::_getAttribute($chartDetail->dLbls->showLeaderLines, 'val', 'string'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $plotAttributes; |
||||
|
} |
||||
|
|
||||
|
private static function _setChartAttributes($plotArea,$plotAttributes) |
||||
|
{ |
||||
|
foreach($plotAttributes as $plotAttributeKey => $plotAttributeValue) { |
||||
|
switch($plotAttributeKey) { |
||||
|
case 'showLegendKey' : |
||||
|
$plotArea->setShowLegendKey($plotAttributeValue); |
||||
|
break; |
||||
|
case 'showVal' : |
||||
|
$plotArea->setShowVal($plotAttributeValue); |
||||
|
break; |
||||
|
case 'showCatName' : |
||||
|
$plotArea->setShowCatName($plotAttributeValue); |
||||
|
break; |
||||
|
case 'showSerName' : |
||||
|
$plotArea->setShowSerName($plotAttributeValue); |
||||
|
break; |
||||
|
case 'showPercent' : |
||||
|
$plotArea->setShowPercent($plotAttributeValue); |
||||
|
break; |
||||
|
case 'showBubbleSize' : |
||||
|
$plotArea->setShowBubbleSize($plotAttributeValue); |
||||
|
break; |
||||
|
case 'showLeaderLines' : |
||||
|
$plotArea->setShowLeaderLines($plotAttributeValue); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,124 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader_Excel2007 |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_Excel2007_Theme |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader_Excel2007 |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Reader_Excel2007_Theme |
||||
|
{ |
||||
|
/** |
||||
|
* Theme Name |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_themeName; |
||||
|
|
||||
|
/** |
||||
|
* Colour Scheme Name |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_colourSchemeName; |
||||
|
|
||||
|
/** |
||||
|
* Colour Map indexed by position |
||||
|
* |
||||
|
* @var array of string |
||||
|
*/ |
||||
|
private $_colourMapValues; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Colour Map |
||||
|
* |
||||
|
* @var array of string |
||||
|
*/ |
||||
|
private $_colourMap; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Theme |
||||
|
* |
||||
|
*/ |
||||
|
public function __construct($themeName,$colourSchemeName,$colourMap) |
||||
|
{ |
||||
|
// Initialise values |
||||
|
$this->_themeName = $themeName; |
||||
|
$this->_colourSchemeName = $colourSchemeName; |
||||
|
$this->_colourMap = $colourMap; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get Theme Name |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getThemeName() |
||||
|
{ |
||||
|
return $this->_themeName; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get colour Scheme Name |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getColourSchemeName() { |
||||
|
return $this->_colourSchemeName; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get colour Map Value by Position |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getColourByIndex($index=0) { |
||||
|
if (isset($this->_colourMap[$index])) { |
||||
|
return $this->_colourMap[$index]; |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
||||
|
*/ |
||||
|
public function __clone() { |
||||
|
$vars = get_object_vars($this); |
||||
|
foreach ($vars as $key => $value) { |
||||
|
if ((is_object($value)) && ($key != '_parent')) { |
||||
|
$this->$key = clone $value; |
||||
|
} else { |
||||
|
$this->$key = $value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
File diff suppressed because it is too large
@ -0,0 +1,32 @@ |
|||||
|
<?php |
||||
|
|
||||
|
class PHPExcel_Reader_Excel5_Color |
||||
|
{ |
||||
|
/** |
||||
|
* Read color |
||||
|
* |
||||
|
* @param int $color Indexed color |
||||
|
* @param array $palette Color palette |
||||
|
* @return array RGB color value, example: array('rgb' => 'FF0000') |
||||
|
*/ |
||||
|
public static function map($color, $palette, $version) |
||||
|
{ |
||||
|
if ($color <= 0x07 || $color >= 0x40) { |
||||
|
// special built-in color |
||||
|
return PHPExcel_Reader_Excel5_Color_BuiltIn::lookup($color); |
||||
|
} elseif (isset($palette) && isset($palette[$color - 8])) { |
||||
|
// palette color, color index 0x08 maps to pallete index 0 |
||||
|
return $palette[$color - 8]; |
||||
|
} else { |
||||
|
// default color table |
||||
|
if ($version == PHPExcel_Reader_Excel5::XLS_BIFF8) { |
||||
|
return PHPExcel_Reader_Excel5_Color_BIFF8::lookup($color); |
||||
|
} else { |
||||
|
// BIFF5 |
||||
|
return PHPExcel_Reader_Excel5_Color_BIFF5::lookup($color); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $color; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
|
||||
|
class PHPExcel_Reader_Excel5_Color_BIFF5 |
||||
|
{ |
||||
|
protected static $map = array( |
||||
|
0x08 => '000000', |
||||
|
0x09 => 'FFFFFF', |
||||
|
0x0A => 'FF0000', |
||||
|
0x0B => '00FF00', |
||||
|
0x0C => '0000FF', |
||||
|
0x0D => 'FFFF00', |
||||
|
0x0E => 'FF00FF', |
||||
|
0x0F => '00FFFF', |
||||
|
0x10 => '800000', |
||||
|
0x11 => '008000', |
||||
|
0x12 => '000080', |
||||
|
0x13 => '808000', |
||||
|
0x14 => '800080', |
||||
|
0x15 => '008080', |
||||
|
0x16 => 'C0C0C0', |
||||
|
0x17 => '808080', |
||||
|
0x18 => '8080FF', |
||||
|
0x19 => '802060', |
||||
|
0x1A => 'FFFFC0', |
||||
|
0x1B => 'A0E0F0', |
||||
|
0x1C => '600080', |
||||
|
0x1D => 'FF8080', |
||||
|
0x1E => '0080C0', |
||||
|
0x1F => 'C0C0FF', |
||||
|
0x20 => '000080', |
||||
|
0x21 => 'FF00FF', |
||||
|
0x22 => 'FFFF00', |
||||
|
0x23 => '00FFFF', |
||||
|
0x24 => '800080', |
||||
|
0x25 => '800000', |
||||
|
0x26 => '008080', |
||||
|
0x27 => '0000FF', |
||||
|
0x28 => '00CFFF', |
||||
|
0x29 => '69FFFF', |
||||
|
0x2A => 'E0FFE0', |
||||
|
0x2B => 'FFFF80', |
||||
|
0x2C => 'A6CAF0', |
||||
|
0x2D => 'DD9CB3', |
||||
|
0x2E => 'B38FEE', |
||||
|
0x2F => 'E3E3E3', |
||||
|
0x30 => '2A6FF9', |
||||
|
0x31 => '3FB8CD', |
||||
|
0x32 => '488436', |
||||
|
0x33 => '958C41', |
||||
|
0x34 => '8E5E42', |
||||
|
0x35 => 'A0627A', |
||||
|
0x36 => '624FAC', |
||||
|
0x37 => '969696', |
||||
|
0x38 => '1D2FBE', |
||||
|
0x39 => '286676', |
||||
|
0x3A => '004500', |
||||
|
0x3B => '453E01', |
||||
|
0x3C => '6A2813', |
||||
|
0x3D => '85396A', |
||||
|
0x3E => '4A3285', |
||||
|
0x3F => '424242', |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Map color array from BIFF5 built-in color index |
||||
|
* |
||||
|
* @param int $color |
||||
|
* @return array |
||||
|
*/ |
||||
|
public static function lookup($color) |
||||
|
{ |
||||
|
if (isset(self::$map[$color])) { |
||||
|
return array('rgb' => self::$map[$color]); |
||||
|
} |
||||
|
return array('rgb' => '000000'); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
|
||||
|
class PHPExcel_Reader_Excel5_Color_BIFF8 |
||||
|
{ |
||||
|
protected static $map = array( |
||||
|
0x08 => '000000', |
||||
|
0x09 => 'FFFFFF', |
||||
|
0x0A => 'FF0000', |
||||
|
0x0B => '00FF00', |
||||
|
0x0C => '0000FF', |
||||
|
0x0D => 'FFFF00', |
||||
|
0x0E => 'FF00FF', |
||||
|
0x0F => '00FFFF', |
||||
|
0x10 => '800000', |
||||
|
0x11 => '008000', |
||||
|
0x12 => '000080', |
||||
|
0x13 => '808000', |
||||
|
0x14 => '800080', |
||||
|
0x15 => '008080', |
||||
|
0x16 => 'C0C0C0', |
||||
|
0x17 => '808080', |
||||
|
0x18 => '9999FF', |
||||
|
0x19 => '993366', |
||||
|
0x1A => 'FFFFCC', |
||||
|
0x1B => 'CCFFFF', |
||||
|
0x1C => '660066', |
||||
|
0x1D => 'FF8080', |
||||
|
0x1E => '0066CC', |
||||
|
0x1F => 'CCCCFF', |
||||
|
0x20 => '000080', |
||||
|
0x21 => 'FF00FF', |
||||
|
0x22 => 'FFFF00', |
||||
|
0x23 => '00FFFF', |
||||
|
0x24 => '800080', |
||||
|
0x25 => '800000', |
||||
|
0x26 => '008080', |
||||
|
0x27 => '0000FF', |
||||
|
0x28 => '00CCFF', |
||||
|
0x29 => 'CCFFFF', |
||||
|
0x2A => 'CCFFCC', |
||||
|
0x2B => 'FFFF99', |
||||
|
0x2C => '99CCFF', |
||||
|
0x2D => 'FF99CC', |
||||
|
0x2E => 'CC99FF', |
||||
|
0x2F => 'FFCC99', |
||||
|
0x30 => '3366FF', |
||||
|
0x31 => '33CCCC', |
||||
|
0x32 => '99CC00', |
||||
|
0x33 => 'FFCC00', |
||||
|
0x34 => 'FF9900', |
||||
|
0x35 => 'FF6600', |
||||
|
0x36 => '666699', |
||||
|
0x37 => '969696', |
||||
|
0x38 => '003366', |
||||
|
0x39 => '339966', |
||||
|
0x3A => '003300', |
||||
|
0x3B => '333300', |
||||
|
0x3C => '993300', |
||||
|
0x3D => '993366', |
||||
|
0x3E => '333399', |
||||
|
0x3F => '333333', |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Map color array from BIFF8 built-in color index |
||||
|
* |
||||
|
* @param int $color |
||||
|
* @return array |
||||
|
*/ |
||||
|
public static function lookup($color) |
||||
|
{ |
||||
|
if (isset(self::$map[$color])) { |
||||
|
return array('rgb' => self::$map[$color]); |
||||
|
} |
||||
|
return array('rgb' => '000000'); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,31 @@ |
|||||
|
<?php |
||||
|
|
||||
|
class PHPExcel_Reader_Excel5_Color_BuiltIn |
||||
|
{ |
||||
|
protected static $map = array( |
||||
|
0x00 => '000000', |
||||
|
0x01 => 'FFFFFF', |
||||
|
0x02 => 'FF0000', |
||||
|
0x03 => '00FF00', |
||||
|
0x04 => '0000FF', |
||||
|
0x05 => 'FFFF00', |
||||
|
0x06 => 'FF00FF', |
||||
|
0x07 => '00FFFF', |
||||
|
0x40 => '000000', // system window text color |
||||
|
0x41 => 'FFFFFF', // system window background color |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Map built-in color to RGB value |
||||
|
* |
||||
|
* @param int $color Indexed color |
||||
|
* @return array |
||||
|
*/ |
||||
|
public static function lookup($color) |
||||
|
{ |
||||
|
if (isset(self::$map[$color])) { |
||||
|
return array('rgb' => self::$map[$color]); |
||||
|
} |
||||
|
return array('rgb' => '000000'); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
<?php |
||||
|
|
||||
|
class PHPExcel_Reader_Excel5_ErrorCode |
||||
|
{ |
||||
|
protected static $map = array( |
||||
|
0x00 => '#NULL!', |
||||
|
0x07 => '#DIV/0!', |
||||
|
0x0F => '#VALUE!', |
||||
|
0x17 => '#REF!', |
||||
|
0x1D => '#NAME?', |
||||
|
0x24 => '#NUM!', |
||||
|
0x2A => '#N/A', |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Map error code, e.g. '#N/A' |
||||
|
* |
||||
|
* @param int $code |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function lookup($code) |
||||
|
{ |
||||
|
if (isset(self::$map[$code])) { |
||||
|
return self::$map[$code]; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,640 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader_Excel5 |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_Excel5_Escher |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader_Excel5 |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Reader_Excel5_Escher |
||||
|
{ |
||||
|
const DGGCONTAINER = 0xF000; |
||||
|
const BSTORECONTAINER = 0xF001; |
||||
|
const DGCONTAINER = 0xF002; |
||||
|
const SPGRCONTAINER = 0xF003; |
||||
|
const SPCONTAINER = 0xF004; |
||||
|
const DGG = 0xF006; |
||||
|
const BSE = 0xF007; |
||||
|
const DG = 0xF008; |
||||
|
const SPGR = 0xF009; |
||||
|
const SP = 0xF00A; |
||||
|
const OPT = 0xF00B; |
||||
|
const CLIENTTEXTBOX = 0xF00D; |
||||
|
const CLIENTANCHOR = 0xF010; |
||||
|
const CLIENTDATA = 0xF011; |
||||
|
const BLIPJPEG = 0xF01D; |
||||
|
const BLIPPNG = 0xF01E; |
||||
|
const SPLITMENUCOLORS = 0xF11E; |
||||
|
const TERTIARYOPT = 0xF122; |
||||
|
|
||||
|
/** |
||||
|
* Escher stream data (binary) |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_data; |
||||
|
|
||||
|
/** |
||||
|
* Size in bytes of the Escher stream data |
||||
|
* |
||||
|
* @var int |
||||
|
*/ |
||||
|
private $_dataSize; |
||||
|
|
||||
|
/** |
||||
|
* Current position of stream pointer in Escher stream data |
||||
|
* |
||||
|
* @var int |
||||
|
*/ |
||||
|
private $_pos; |
||||
|
|
||||
|
/** |
||||
|
* The object to be returned by the reader. Modified during load. |
||||
|
* |
||||
|
* @var mixed |
||||
|
*/ |
||||
|
private $_object; |
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Reader_Excel5_Escher instance |
||||
|
* |
||||
|
* @param mixed $object |
||||
|
*/ |
||||
|
public function __construct($object) |
||||
|
{ |
||||
|
$this->_object = $object; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Load Escher stream data. May be a partial Escher stream. |
||||
|
* |
||||
|
* @param string $data |
||||
|
*/ |
||||
|
public function load($data) |
||||
|
{ |
||||
|
$this->_data = $data; |
||||
|
|
||||
|
// total byte size of Excel data (workbook global substream + sheet substreams) |
||||
|
$this->_dataSize = strlen($this->_data); |
||||
|
|
||||
|
$this->_pos = 0; |
||||
|
|
||||
|
// Parse Escher stream |
||||
|
while ($this->_pos < $this->_dataSize) { |
||||
|
|
||||
|
// offset: 2; size: 2: Record Type |
||||
|
$fbt = PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos + 2); |
||||
|
|
||||
|
switch ($fbt) { |
||||
|
case self::DGGCONTAINER: $this->_readDggContainer(); break; |
||||
|
case self::DGG: $this->_readDgg(); break; |
||||
|
case self::BSTORECONTAINER: $this->_readBstoreContainer(); break; |
||||
|
case self::BSE: $this->_readBSE(); break; |
||||
|
case self::BLIPJPEG: $this->_readBlipJPEG(); break; |
||||
|
case self::BLIPPNG: $this->_readBlipPNG(); break; |
||||
|
case self::OPT: $this->_readOPT(); break; |
||||
|
case self::TERTIARYOPT: $this->_readTertiaryOPT(); break; |
||||
|
case self::SPLITMENUCOLORS: $this->_readSplitMenuColors(); break; |
||||
|
case self::DGCONTAINER: $this->_readDgContainer(); break; |
||||
|
case self::DG: $this->_readDg(); break; |
||||
|
case self::SPGRCONTAINER: $this->_readSpgrContainer(); break; |
||||
|
case self::SPCONTAINER: $this->_readSpContainer(); break; |
||||
|
case self::SPGR: $this->_readSpgr(); break; |
||||
|
case self::SP: $this->_readSp(); break; |
||||
|
case self::CLIENTTEXTBOX: $this->_readClientTextbox(); break; |
||||
|
case self::CLIENTANCHOR: $this->_readClientAnchor(); break; |
||||
|
case self::CLIENTDATA: $this->_readClientData(); break; |
||||
|
default: $this->_readDefault(); break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $this->_object; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read a generic record |
||||
|
*/ |
||||
|
private function _readDefault() |
||||
|
{ |
||||
|
// offset 0; size: 2; recVer and recInstance |
||||
|
$verInstance = PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos); |
||||
|
|
||||
|
// offset: 2; size: 2: Record Type |
||||
|
$fbt = PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos + 2); |
||||
|
|
||||
|
// bit: 0-3; mask: 0x000F; recVer |
||||
|
$recVer = (0x000F & $verInstance) >> 0; |
||||
|
|
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read DggContainer record (Drawing Group Container) |
||||
|
*/ |
||||
|
private function _readDggContainer() |
||||
|
{ |
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
|
||||
|
// record is a container, read contents |
||||
|
$dggContainer = new PHPExcel_Shared_Escher_DggContainer(); |
||||
|
$this->_object->setDggContainer($dggContainer); |
||||
|
$reader = new PHPExcel_Reader_Excel5_Escher($dggContainer); |
||||
|
$reader->load($recordData); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read Dgg record (Drawing Group) |
||||
|
*/ |
||||
|
private function _readDgg() |
||||
|
{ |
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read BstoreContainer record (Blip Store Container) |
||||
|
*/ |
||||
|
private function _readBstoreContainer() |
||||
|
{ |
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
|
||||
|
// record is a container, read contents |
||||
|
$bstoreContainer = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer(); |
||||
|
$this->_object->setBstoreContainer($bstoreContainer); |
||||
|
$reader = new PHPExcel_Reader_Excel5_Escher($bstoreContainer); |
||||
|
$reader->load($recordData); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read BSE record |
||||
|
*/ |
||||
|
private function _readBSE() |
||||
|
{ |
||||
|
// offset: 0; size: 2; recVer and recInstance |
||||
|
|
||||
|
// bit: 4-15; mask: 0xFFF0; recInstance |
||||
|
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4; |
||||
|
|
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
|
||||
|
// add BSE to BstoreContainer |
||||
|
$BSE = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE(); |
||||
|
$this->_object->addBSE($BSE); |
||||
|
|
||||
|
$BSE->setBLIPType($recInstance); |
||||
|
|
||||
|
// offset: 0; size: 1; btWin32 (MSOBLIPTYPE) |
||||
|
$btWin32 = ord($recordData[0]); |
||||
|
|
||||
|
// offset: 1; size: 1; btWin32 (MSOBLIPTYPE) |
||||
|
$btMacOS = ord($recordData[1]); |
||||
|
|
||||
|
// offset: 2; size: 16; MD4 digest |
||||
|
$rgbUid = substr($recordData, 2, 16); |
||||
|
|
||||
|
// offset: 18; size: 2; tag |
||||
|
$tag = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 18); |
||||
|
|
||||
|
// offset: 20; size: 4; size of BLIP in bytes |
||||
|
$size = PHPExcel_Reader_Excel5::_GetInt4d($recordData, 20); |
||||
|
|
||||
|
// offset: 24; size: 4; number of references to this BLIP |
||||
|
$cRef = PHPExcel_Reader_Excel5::_GetInt4d($recordData, 24); |
||||
|
|
||||
|
// offset: 28; size: 4; MSOFO file offset |
||||
|
$foDelay = PHPExcel_Reader_Excel5::_GetInt4d($recordData, 28); |
||||
|
|
||||
|
// offset: 32; size: 1; unused1 |
||||
|
$unused1 = ord($recordData{32}); |
||||
|
|
||||
|
// offset: 33; size: 1; size of nameData in bytes (including null terminator) |
||||
|
$cbName = ord($recordData{33}); |
||||
|
|
||||
|
// offset: 34; size: 1; unused2 |
||||
|
$unused2 = ord($recordData{34}); |
||||
|
|
||||
|
// offset: 35; size: 1; unused3 |
||||
|
$unused3 = ord($recordData{35}); |
||||
|
|
||||
|
// offset: 36; size: $cbName; nameData |
||||
|
$nameData = substr($recordData, 36, $cbName); |
||||
|
|
||||
|
// offset: 36 + $cbName, size: var; the BLIP data |
||||
|
$blipData = substr($recordData, 36 + $cbName); |
||||
|
|
||||
|
// record is a container, read contents |
||||
|
$reader = new PHPExcel_Reader_Excel5_Escher($BSE); |
||||
|
$reader->load($blipData); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read BlipJPEG record. Holds raw JPEG image data |
||||
|
*/ |
||||
|
private function _readBlipJPEG() |
||||
|
{ |
||||
|
// offset: 0; size: 2; recVer and recInstance |
||||
|
|
||||
|
// bit: 4-15; mask: 0xFFF0; recInstance |
||||
|
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4; |
||||
|
|
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
|
||||
|
$pos = 0; |
||||
|
|
||||
|
// offset: 0; size: 16; rgbUid1 (MD4 digest of) |
||||
|
$rgbUid1 = substr($recordData, 0, 16); |
||||
|
$pos += 16; |
||||
|
|
||||
|
// offset: 16; size: 16; rgbUid2 (MD4 digest), only if $recInstance = 0x46B or 0x6E3 |
||||
|
if (in_array($recInstance, array(0x046B, 0x06E3))) { |
||||
|
$rgbUid2 = substr($recordData, 16, 16); |
||||
|
$pos += 16; |
||||
|
} |
||||
|
|
||||
|
// offset: var; size: 1; tag |
||||
|
$tag = ord($recordData{$pos}); |
||||
|
$pos += 1; |
||||
|
|
||||
|
// offset: var; size: var; the raw image data |
||||
|
$data = substr($recordData, $pos); |
||||
|
|
||||
|
$blip = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip(); |
||||
|
$blip->setData($data); |
||||
|
|
||||
|
$this->_object->setBlip($blip); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read BlipPNG record. Holds raw PNG image data |
||||
|
*/ |
||||
|
private function _readBlipPNG() |
||||
|
{ |
||||
|
// offset: 0; size: 2; recVer and recInstance |
||||
|
|
||||
|
// bit: 4-15; mask: 0xFFF0; recInstance |
||||
|
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4; |
||||
|
|
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
|
||||
|
$pos = 0; |
||||
|
|
||||
|
// offset: 0; size: 16; rgbUid1 (MD4 digest of) |
||||
|
$rgbUid1 = substr($recordData, 0, 16); |
||||
|
$pos += 16; |
||||
|
|
||||
|
// offset: 16; size: 16; rgbUid2 (MD4 digest), only if $recInstance = 0x46B or 0x6E3 |
||||
|
if ($recInstance == 0x06E1) { |
||||
|
$rgbUid2 = substr($recordData, 16, 16); |
||||
|
$pos += 16; |
||||
|
} |
||||
|
|
||||
|
// offset: var; size: 1; tag |
||||
|
$tag = ord($recordData{$pos}); |
||||
|
$pos += 1; |
||||
|
|
||||
|
// offset: var; size: var; the raw image data |
||||
|
$data = substr($recordData, $pos); |
||||
|
|
||||
|
$blip = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip(); |
||||
|
$blip->setData($data); |
||||
|
|
||||
|
$this->_object->setBlip($blip); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read OPT record. This record may occur within DggContainer record or SpContainer |
||||
|
*/ |
||||
|
private function _readOPT() |
||||
|
{ |
||||
|
// offset: 0; size: 2; recVer and recInstance |
||||
|
|
||||
|
// bit: 4-15; mask: 0xFFF0; recInstance |
||||
|
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4; |
||||
|
|
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
|
||||
|
$this->_readOfficeArtRGFOPTE($recordData, $recInstance); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read TertiaryOPT record |
||||
|
*/ |
||||
|
private function _readTertiaryOPT() |
||||
|
{ |
||||
|
// offset: 0; size: 2; recVer and recInstance |
||||
|
|
||||
|
// bit: 4-15; mask: 0xFFF0; recInstance |
||||
|
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4; |
||||
|
|
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read SplitMenuColors record |
||||
|
*/ |
||||
|
private function _readSplitMenuColors() |
||||
|
{ |
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read DgContainer record (Drawing Container) |
||||
|
*/ |
||||
|
private function _readDgContainer() |
||||
|
{ |
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
|
||||
|
// record is a container, read contents |
||||
|
$dgContainer = new PHPExcel_Shared_Escher_DgContainer(); |
||||
|
$this->_object->setDgContainer($dgContainer); |
||||
|
$reader = new PHPExcel_Reader_Excel5_Escher($dgContainer); |
||||
|
$escher = $reader->load($recordData); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read Dg record (Drawing) |
||||
|
*/ |
||||
|
private function _readDg() |
||||
|
{ |
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read SpgrContainer record (Shape Group Container) |
||||
|
*/ |
||||
|
private function _readSpgrContainer() |
||||
|
{ |
||||
|
// context is either context DgContainer or SpgrContainer |
||||
|
|
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
|
||||
|
// record is a container, read contents |
||||
|
$spgrContainer = new PHPExcel_Shared_Escher_DgContainer_SpgrContainer(); |
||||
|
|
||||
|
if ($this->_object instanceof PHPExcel_Shared_Escher_DgContainer) { |
||||
|
// DgContainer |
||||
|
$this->_object->setSpgrContainer($spgrContainer); |
||||
|
} else { |
||||
|
// SpgrContainer |
||||
|
$this->_object->addChild($spgrContainer); |
||||
|
} |
||||
|
|
||||
|
$reader = new PHPExcel_Reader_Excel5_Escher($spgrContainer); |
||||
|
$escher = $reader->load($recordData); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read SpContainer record (Shape Container) |
||||
|
*/ |
||||
|
private function _readSpContainer() |
||||
|
{ |
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// add spContainer to spgrContainer |
||||
|
$spContainer = new PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer(); |
||||
|
$this->_object->addChild($spContainer); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
|
||||
|
// record is a container, read contents |
||||
|
$reader = new PHPExcel_Reader_Excel5_Escher($spContainer); |
||||
|
$escher = $reader->load($recordData); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read Spgr record (Shape Group) |
||||
|
*/ |
||||
|
private function _readSpgr() |
||||
|
{ |
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read Sp record (Shape) |
||||
|
*/ |
||||
|
private function _readSp() |
||||
|
{ |
||||
|
// offset: 0; size: 2; recVer and recInstance |
||||
|
|
||||
|
// bit: 4-15; mask: 0xFFF0; recInstance |
||||
|
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4; |
||||
|
|
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read ClientTextbox record |
||||
|
*/ |
||||
|
private function _readClientTextbox() |
||||
|
{ |
||||
|
// offset: 0; size: 2; recVer and recInstance |
||||
|
|
||||
|
// bit: 4-15; mask: 0xFFF0; recInstance |
||||
|
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4; |
||||
|
|
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read ClientAnchor record. This record holds information about where the shape is anchored in worksheet |
||||
|
*/ |
||||
|
private function _readClientAnchor() |
||||
|
{ |
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
|
||||
|
// offset: 2; size: 2; upper-left corner column index (0-based) |
||||
|
$c1 = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 2); |
||||
|
|
||||
|
// offset: 4; size: 2; upper-left corner horizontal offset in 1/1024 of column width |
||||
|
$startOffsetX = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 4); |
||||
|
|
||||
|
// offset: 6; size: 2; upper-left corner row index (0-based) |
||||
|
$r1 = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 6); |
||||
|
|
||||
|
// offset: 8; size: 2; upper-left corner vertical offset in 1/256 of row height |
||||
|
$startOffsetY = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 8); |
||||
|
|
||||
|
// offset: 10; size: 2; bottom-right corner column index (0-based) |
||||
|
$c2 = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 10); |
||||
|
|
||||
|
// offset: 12; size: 2; bottom-right corner horizontal offset in 1/1024 of column width |
||||
|
$endOffsetX = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 12); |
||||
|
|
||||
|
// offset: 14; size: 2; bottom-right corner row index (0-based) |
||||
|
$r2 = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 14); |
||||
|
|
||||
|
// offset: 16; size: 2; bottom-right corner vertical offset in 1/256 of row height |
||||
|
$endOffsetY = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 16); |
||||
|
|
||||
|
// set the start coordinates |
||||
|
$this->_object->setStartCoordinates(PHPExcel_Cell::stringFromColumnIndex($c1) . ($r1 + 1)); |
||||
|
|
||||
|
// set the start offsetX |
||||
|
$this->_object->setStartOffsetX($startOffsetX); |
||||
|
|
||||
|
// set the start offsetY |
||||
|
$this->_object->setStartOffsetY($startOffsetY); |
||||
|
|
||||
|
// set the end coordinates |
||||
|
$this->_object->setEndCoordinates(PHPExcel_Cell::stringFromColumnIndex($c2) . ($r2 + 1)); |
||||
|
|
||||
|
// set the end offsetX |
||||
|
$this->_object->setEndOffsetX($endOffsetX); |
||||
|
|
||||
|
// set the end offsetY |
||||
|
$this->_object->setEndOffsetY($endOffsetY); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read ClientData record |
||||
|
*/ |
||||
|
private function _readClientData() |
||||
|
{ |
||||
|
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4); |
||||
|
$recordData = substr($this->_data, $this->_pos + 8, $length); |
||||
|
|
||||
|
// move stream pointer to next record |
||||
|
$this->_pos += 8 + $length; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Read OfficeArtRGFOPTE table of property-value pairs |
||||
|
* |
||||
|
* @param string $data Binary data |
||||
|
* @param int $n Number of properties |
||||
|
*/ |
||||
|
private function _readOfficeArtRGFOPTE($data, $n) { |
||||
|
|
||||
|
$splicedComplexData = substr($data, 6 * $n); |
||||
|
|
||||
|
// loop through property-value pairs |
||||
|
for ($i = 0; $i < $n; ++$i) { |
||||
|
// read 6 bytes at a time |
||||
|
$fopte = substr($data, 6 * $i, 6); |
||||
|
|
||||
|
// offset: 0; size: 2; opid |
||||
|
$opid = PHPExcel_Reader_Excel5::_GetInt2d($fopte, 0); |
||||
|
|
||||
|
// bit: 0-13; mask: 0x3FFF; opid.opid |
||||
|
$opidOpid = (0x3FFF & $opid) >> 0; |
||||
|
|
||||
|
// bit: 14; mask 0x4000; 1 = value in op field is BLIP identifier |
||||
|
$opidFBid = (0x4000 & $opid) >> 14; |
||||
|
|
||||
|
// bit: 15; mask 0x8000; 1 = this is a complex property, op field specifies size of complex data |
||||
|
$opidFComplex = (0x8000 & $opid) >> 15; |
||||
|
|
||||
|
// offset: 2; size: 4; the value for this property |
||||
|
$op = PHPExcel_Reader_Excel5::_GetInt4d($fopte, 2); |
||||
|
|
||||
|
if ($opidFComplex) { |
||||
|
$complexData = substr($splicedComplexData, 0, $op); |
||||
|
$splicedComplexData = substr($splicedComplexData, $op); |
||||
|
|
||||
|
// we store string value with complex data |
||||
|
$value = $complexData; |
||||
|
} else { |
||||
|
// we store integer value |
||||
|
$value = $op; |
||||
|
} |
||||
|
|
||||
|
$this->_object->setOPT($opidOpid, $value); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,203 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_Excel5_MD5 |
||||
|
* |
||||
|
* 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 |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader_Excel5 |
||||
|
* @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_Reader_Excel5_MD5 |
||||
|
{ |
||||
|
// Context |
||||
|
private $a; |
||||
|
private $b; |
||||
|
private $c; |
||||
|
private $d; |
||||
|
|
||||
|
/** |
||||
|
* MD5 stream constructor |
||||
|
*/ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
$this->reset(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Reset the MD5 stream context |
||||
|
*/ |
||||
|
public function reset() |
||||
|
{ |
||||
|
$this->a = 0x67452301; |
||||
|
$this->b = 0xEFCDAB89; |
||||
|
$this->c = 0x98BADCFE; |
||||
|
$this->d = 0x10325476; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get MD5 stream context |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getContext() |
||||
|
{ |
||||
|
$s = ''; |
||||
|
foreach (array('a', 'b', 'c', 'd') as $i) { |
||||
|
$v = $this->{$i}; |
||||
|
$s .= chr($v & 0xff); |
||||
|
$s .= chr(($v >> 8) & 0xff); |
||||
|
$s .= chr(($v >> 16) & 0xff); |
||||
|
$s .= chr(($v >> 24) & 0xff); |
||||
|
} |
||||
|
|
||||
|
return $s; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Add data to context |
||||
|
* |
||||
|
* @param string $data Data to add |
||||
|
*/ |
||||
|
public function add($data) |
||||
|
{ |
||||
|
$words = array_values(unpack('V16', $data)); |
||||
|
|
||||
|
$A = $this->a; |
||||
|
$B = $this->b; |
||||
|
$C = $this->c; |
||||
|
$D = $this->d; |
||||
|
|
||||
|
$F = array('PHPExcel_Reader_Excel5_MD5','f'); |
||||
|
$G = array('PHPExcel_Reader_Excel5_MD5','g'); |
||||
|
$H = array('PHPExcel_Reader_Excel5_MD5','h'); |
||||
|
$I = array('PHPExcel_Reader_Excel5_MD5','i'); |
||||
|
|
||||
|
/* ROUND 1 */ |
||||
|
self::step($F, $A, $B, $C, $D, $words[0], 7, 0xd76aa478); |
||||
|
self::step($F, $D, $A, $B, $C, $words[1], 12, 0xe8c7b756); |
||||
|
self::step($F, $C, $D, $A, $B, $words[2], 17, 0x242070db); |
||||
|
self::step($F, $B, $C, $D, $A, $words[3], 22, 0xc1bdceee); |
||||
|
self::step($F, $A, $B, $C, $D, $words[4], 7, 0xf57c0faf); |
||||
|
self::step($F, $D, $A, $B, $C, $words[5], 12, 0x4787c62a); |
||||
|
self::step($F, $C, $D, $A, $B, $words[6], 17, 0xa8304613); |
||||
|
self::step($F, $B, $C, $D, $A, $words[7], 22, 0xfd469501); |
||||
|
self::step($F, $A, $B, $C, $D, $words[8], 7, 0x698098d8); |
||||
|
self::step($F, $D, $A, $B, $C, $words[9], 12, 0x8b44f7af); |
||||
|
self::step($F, $C, $D, $A, $B, $words[10], 17, 0xffff5bb1); |
||||
|
self::step($F, $B, $C, $D, $A, $words[11], 22, 0x895cd7be); |
||||
|
self::step($F, $A, $B, $C, $D, $words[12], 7, 0x6b901122); |
||||
|
self::step($F, $D, $A, $B, $C, $words[13], 12, 0xfd987193); |
||||
|
self::step($F, $C, $D, $A, $B, $words[14], 17, 0xa679438e); |
||||
|
self::step($F, $B, $C, $D, $A, $words[15], 22, 0x49b40821); |
||||
|
|
||||
|
/* ROUND 2 */ |
||||
|
self::step($G, $A, $B, $C, $D, $words[1], 5, 0xf61e2562); |
||||
|
self::step($G, $D, $A, $B, $C, $words[6], 9, 0xc040b340); |
||||
|
self::step($G, $C, $D, $A, $B, $words[11], 14, 0x265e5a51); |
||||
|
self::step($G, $B, $C, $D, $A, $words[0], 20, 0xe9b6c7aa); |
||||
|
self::step($G, $A, $B, $C, $D, $words[5], 5, 0xd62f105d); |
||||
|
self::step($G, $D, $A, $B, $C, $words[10], 9, 0x02441453); |
||||
|
self::step($G, $C, $D, $A, $B, $words[15], 14, 0xd8a1e681); |
||||
|
self::step($G, $B, $C, $D, $A, $words[4], 20, 0xe7d3fbc8); |
||||
|
self::step($G, $A, $B, $C, $D, $words[9], 5, 0x21e1cde6); |
||||
|
self::step($G, $D, $A, $B, $C, $words[14], 9, 0xc33707d6); |
||||
|
self::step($G, $C, $D, $A, $B, $words[3], 14, 0xf4d50d87); |
||||
|
self::step($G, $B, $C, $D, $A, $words[8], 20, 0x455a14ed); |
||||
|
self::step($G, $A, $B, $C, $D, $words[13], 5, 0xa9e3e905); |
||||
|
self::step($G, $D, $A, $B, $C, $words[2], 9, 0xfcefa3f8); |
||||
|
self::step($G, $C, $D, $A, $B, $words[7], 14, 0x676f02d9); |
||||
|
self::step($G, $B, $C, $D, $A, $words[12], 20, 0x8d2a4c8a); |
||||
|
|
||||
|
/* ROUND 3 */ |
||||
|
self::step($H, $A, $B, $C, $D, $words[5], 4, 0xfffa3942); |
||||
|
self::step($H, $D, $A, $B, $C, $words[8], 11, 0x8771f681); |
||||
|
self::step($H, $C, $D, $A, $B, $words[11], 16, 0x6d9d6122); |
||||
|
self::step($H, $B, $C, $D, $A, $words[14], 23, 0xfde5380c); |
||||
|
self::step($H, $A, $B, $C, $D, $words[1], 4, 0xa4beea44); |
||||
|
self::step($H, $D, $A, $B, $C, $words[4], 11, 0x4bdecfa9); |
||||
|
self::step($H, $C, $D, $A, $B, $words[7], 16, 0xf6bb4b60); |
||||
|
self::step($H, $B, $C, $D, $A, $words[10], 23, 0xbebfbc70); |
||||
|
self::step($H, $A, $B, $C, $D, $words[13], 4, 0x289b7ec6); |
||||
|
self::step($H, $D, $A, $B, $C, $words[0], 11, 0xeaa127fa); |
||||
|
self::step($H, $C, $D, $A, $B, $words[3], 16, 0xd4ef3085); |
||||
|
self::step($H, $B, $C, $D, $A, $words[6], 23, 0x04881d05); |
||||
|
self::step($H, $A, $B, $C, $D, $words[9], 4, 0xd9d4d039); |
||||
|
self::step($H, $D, $A, $B, $C, $words[12], 11, 0xe6db99e5); |
||||
|
self::step($H, $C, $D, $A, $B, $words[15], 16, 0x1fa27cf8); |
||||
|
self::step($H, $B, $C, $D, $A, $words[2], 23, 0xc4ac5665); |
||||
|
|
||||
|
/* ROUND 4 */ |
||||
|
self::step($I, $A, $B, $C, $D, $words[0], 6, 0xf4292244); |
||||
|
self::step($I, $D, $A, $B, $C, $words[7], 10, 0x432aff97); |
||||
|
self::step($I, $C, $D, $A, $B, $words[14], 15, 0xab9423a7); |
||||
|
self::step($I, $B, $C, $D, $A, $words[5], 21, 0xfc93a039); |
||||
|
self::step($I, $A, $B, $C, $D, $words[12], 6, 0x655b59c3); |
||||
|
self::step($I, $D, $A, $B, $C, $words[3], 10, 0x8f0ccc92); |
||||
|
self::step($I, $C, $D, $A, $B, $words[10], 15, 0xffeff47d); |
||||
|
self::step($I, $B, $C, $D, $A, $words[1], 21, 0x85845dd1); |
||||
|
self::step($I, $A, $B, $C, $D, $words[8], 6, 0x6fa87e4f); |
||||
|
self::step($I, $D, $A, $B, $C, $words[15], 10, 0xfe2ce6e0); |
||||
|
self::step($I, $C, $D, $A, $B, $words[6], 15, 0xa3014314); |
||||
|
self::step($I, $B, $C, $D, $A, $words[13], 21, 0x4e0811a1); |
||||
|
self::step($I, $A, $B, $C, $D, $words[4], 6, 0xf7537e82); |
||||
|
self::step($I, $D, $A, $B, $C, $words[11], 10, 0xbd3af235); |
||||
|
self::step($I, $C, $D, $A, $B, $words[2], 15, 0x2ad7d2bb); |
||||
|
self::step($I, $B, $C, $D, $A, $words[9], 21, 0xeb86d391); |
||||
|
|
||||
|
$this->a = ($this->a + $A) & 0xffffffff; |
||||
|
$this->b = ($this->b + $B) & 0xffffffff; |
||||
|
$this->c = ($this->c + $C) & 0xffffffff; |
||||
|
$this->d = ($this->d + $D) & 0xffffffff; |
||||
|
} |
||||
|
|
||||
|
private static function f($X, $Y, $Z) |
||||
|
{ |
||||
|
return (($X & $Y) | ((~ $X) & $Z)); // X AND Y OR NOT X AND Z |
||||
|
} |
||||
|
|
||||
|
private static function g($X, $Y, $Z) |
||||
|
{ |
||||
|
return (($X & $Z) | ($Y & (~ $Z))); // X AND Z OR Y AND NOT Z |
||||
|
} |
||||
|
|
||||
|
private static function h($X, $Y, $Z) |
||||
|
{ |
||||
|
return ($X ^ $Y ^ $Z); // X XOR Y XOR Z |
||||
|
} |
||||
|
|
||||
|
private static function i($X, $Y, $Z) |
||||
|
{ |
||||
|
return ($Y ^ ($X | (~ $Z))) ; // Y XOR (X OR NOT Z) |
||||
|
} |
||||
|
|
||||
|
private static function step($func, &$A, $B, $C, $D, $M, $s, $t) |
||||
|
{ |
||||
|
$A = ($A + call_user_func($func, $B, $C, $D) + $M + $t) & 0xffffffff; |
||||
|
$A = self::rotate($A, $s); |
||||
|
$A = ($B + $A) & 0xffffffff; |
||||
|
} |
||||
|
|
||||
|
private static function rotate($decimal, $bits) |
||||
|
{ |
||||
|
$binary = str_pad(decbin($decimal), 32, "0", STR_PAD_LEFT); |
||||
|
return bindec(substr($binary, $bits).substr($binary, 0, $bits)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,81 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_Excel5_RC4 |
||||
|
* |
||||
|
* 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 |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader_Excel5 |
||||
|
* @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_Reader_Excel5_RC4 |
||||
|
{ |
||||
|
// Context |
||||
|
protected $s = array(); |
||||
|
protected $i = 0; |
||||
|
protected $j = 0; |
||||
|
|
||||
|
/** |
||||
|
* RC4 stream decryption/encryption constrcutor |
||||
|
* |
||||
|
* @param string $key Encryption key/passphrase |
||||
|
*/ |
||||
|
public function __construct($key) |
||||
|
{ |
||||
|
$len = strlen($key); |
||||
|
|
||||
|
for ($this->i = 0; $this->i < 256; $this->i++) { |
||||
|
$this->s[$this->i] = $this->i; |
||||
|
} |
||||
|
|
||||
|
$this->j = 0; |
||||
|
for ($this->i = 0; $this->i < 256; $this->i++) { |
||||
|
$this->j = ($this->j + $this->s[$this->i] + ord($key[$this->i % $len])) % 256; |
||||
|
$t = $this->s[$this->i]; |
||||
|
$this->s[$this->i] = $this->s[$this->j]; |
||||
|
$this->s[$this->j] = $t; |
||||
|
} |
||||
|
$this->i = $this->j = 0; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Symmetric decryption/encryption function |
||||
|
* |
||||
|
* @param string $data Data to encrypt/decrypt |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function RC4($data) |
||||
|
{ |
||||
|
$len = strlen($data); |
||||
|
for ($c = 0; $c < $len; $c++) { |
||||
|
$this->i = ($this->i + 1) % 256; |
||||
|
$this->j = ($this->j + $this->s[$this->i]) % 256; |
||||
|
$t = $this->s[$this->i]; |
||||
|
$this->s[$this->i] = $this->s[$this->j]; |
||||
|
$this->s[$this->j] = $t; |
||||
|
|
||||
|
$t = ($this->s[$this->i] + $this->s[$this->j]) % 256; |
||||
|
|
||||
|
$data[$c] = chr(ord($data[$c]) ^ $this->s[$t]); |
||||
|
} |
||||
|
return $data; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
<?php |
||||
|
|
||||
|
class PHPExcel_Reader_Excel5_Style_Border |
||||
|
{ |
||||
|
protected static $map = array( |
||||
|
0x00 => PHPExcel_Style_Border::BORDER_NONE, |
||||
|
0x01 => PHPExcel_Style_Border::BORDER_THIN, |
||||
|
0x02 => PHPExcel_Style_Border::BORDER_MEDIUM, |
||||
|
0x03 => PHPExcel_Style_Border::BORDER_DASHED, |
||||
|
0x04 => PHPExcel_Style_Border::BORDER_DOTTED, |
||||
|
0x05 => PHPExcel_Style_Border::BORDER_THICK, |
||||
|
0x06 => PHPExcel_Style_Border::BORDER_DOUBLE, |
||||
|
0x07 => PHPExcel_Style_Border::BORDER_HAIR, |
||||
|
0x08 => PHPExcel_Style_Border::BORDER_MEDIUMDASHED, |
||||
|
0x09 => PHPExcel_Style_Border::BORDER_DASHDOT, |
||||
|
0x0A => PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT, |
||||
|
0x0B => PHPExcel_Style_Border::BORDER_DASHDOTDOT, |
||||
|
0x0C => PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT, |
||||
|
0x0D => PHPExcel_Style_Border::BORDER_SLANTDASHDOT, |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Map border style |
||||
|
* OpenOffice documentation: 2.5.11 |
||||
|
* |
||||
|
* @param int $index |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function lookup($index) |
||||
|
{ |
||||
|
if (isset(self::$map[$index])) { |
||||
|
return self::$map[$index]; |
||||
|
} |
||||
|
return PHPExcel_Style_Border::BORDER_NONE; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
<?php |
||||
|
|
||||
|
class PHPExcel_Reader_Excel5_Style_FillPattern |
||||
|
{ |
||||
|
protected static $map = array( |
||||
|
0x00 => PHPExcel_Style_Fill::FILL_NONE, |
||||
|
0x01 => PHPExcel_Style_Fill::FILL_SOLID, |
||||
|
0x02 => PHPExcel_Style_Fill::FILL_PATTERN_MEDIUMGRAY, |
||||
|
0x03 => PHPExcel_Style_Fill::FILL_PATTERN_DARKGRAY, |
||||
|
0x04 => PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRAY, |
||||
|
0x05 => PHPExcel_Style_Fill::FILL_PATTERN_DARKHORIZONTAL, |
||||
|
0x06 => PHPExcel_Style_Fill::FILL_PATTERN_DARKVERTICAL, |
||||
|
0x07 => PHPExcel_Style_Fill::FILL_PATTERN_DARKDOWN, |
||||
|
0x08 => PHPExcel_Style_Fill::FILL_PATTERN_DARKUP, |
||||
|
0x09 => PHPExcel_Style_Fill::FILL_PATTERN_DARKGRID, |
||||
|
0x0A => PHPExcel_Style_Fill::FILL_PATTERN_DARKTRELLIS, |
||||
|
0x0B => PHPExcel_Style_Fill::FILL_PATTERN_LIGHTHORIZONTAL, |
||||
|
0x0C => PHPExcel_Style_Fill::FILL_PATTERN_LIGHTVERTICAL, |
||||
|
0x0D => PHPExcel_Style_Fill::FILL_PATTERN_LIGHTDOWN, |
||||
|
0x0E => PHPExcel_Style_Fill::FILL_PATTERN_LIGHTUP, |
||||
|
0x0F => PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRID, |
||||
|
0x10 => PHPExcel_Style_Fill::FILL_PATTERN_LIGHTTRELLIS, |
||||
|
0x11 => PHPExcel_Style_Fill::FILL_PATTERN_GRAY125, |
||||
|
0x12 => PHPExcel_Style_Fill::FILL_PATTERN_GRAY0625, |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Get fill pattern from index |
||||
|
* OpenOffice documentation: 2.5.12 |
||||
|
* |
||||
|
* @param int $index |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function lookup($index) |
||||
|
{ |
||||
|
if (isset(self::$map[$index])) { |
||||
|
return self::$map[$index]; |
||||
|
} |
||||
|
return PHPExcel_Style_Fill::FILL_NONE; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_Exception |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Reader_Exception extends PHPExcel_Exception { |
||||
|
/** |
||||
|
* Error handler callback |
||||
|
* |
||||
|
* @param mixed $code |
||||
|
* @param mixed $string |
||||
|
* @param mixed $file |
||||
|
* @param mixed $line |
||||
|
* @param mixed $context |
||||
|
*/ |
||||
|
public static function errorHandlerCallback($code, $string, $file, $line, $context) { |
||||
|
$e = new self($string, $code); |
||||
|
$e->line = $line; |
||||
|
$e->file = $file; |
||||
|
throw $e; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,873 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** PHPExcel root directory */ |
||||
|
if (!defined('PHPEXCEL_ROOT')) { |
||||
|
/** |
||||
|
* @ignore |
||||
|
*/ |
||||
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
||||
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_Gnumeric |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader |
||||
|
{ |
||||
|
/** |
||||
|
* Formats |
||||
|
* |
||||
|
* @var array |
||||
|
*/ |
||||
|
private $_styles = array(); |
||||
|
|
||||
|
/** |
||||
|
* Shared Expressions |
||||
|
* |
||||
|
* @var array |
||||
|
*/ |
||||
|
private $_expressions = array(); |
||||
|
|
||||
|
private $_referenceHelper = null; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Reader_Gnumeric |
||||
|
*/ |
||||
|
public function __construct() { |
||||
|
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter(); |
||||
|
$this->_referenceHelper = PHPExcel_ReferenceHelper::getInstance(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Can the current PHPExcel_Reader_IReader read the file? |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @return boolean |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function canRead($pFilename) |
||||
|
{ |
||||
|
// Check if file exists |
||||
|
if (!file_exists($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
||||
|
} |
||||
|
|
||||
|
// Check if gzlib functions are available |
||||
|
if (!function_exists('gzread')) { |
||||
|
throw new PHPExcel_Reader_Exception("gzlib library is not enabled"); |
||||
|
} |
||||
|
|
||||
|
// Read signature data (first 3 bytes) |
||||
|
$fh = fopen($pFilename, 'r'); |
||||
|
$data = fread($fh, 2); |
||||
|
fclose($fh); |
||||
|
|
||||
|
if ($data != chr(0x1F).chr(0x8B)) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function listWorksheetNames($pFilename) |
||||
|
{ |
||||
|
// Check if file exists |
||||
|
if (!file_exists($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
||||
|
} |
||||
|
|
||||
|
$xml = new XMLReader(); |
||||
|
$xml->open( |
||||
|
'compress.zlib://'.realpath($pFilename) |
||||
|
); |
||||
|
$xml->setParserProperty(2,true); |
||||
|
|
||||
|
$worksheetNames = array(); |
||||
|
while ($xml->read()) { |
||||
|
if ($xml->name == 'gnm:SheetName' && $xml->nodeType == XMLReader::ELEMENT) { |
||||
|
$xml->read(); // Move onto the value node |
||||
|
$worksheetNames[] = (string) $xml->value; |
||||
|
} elseif ($xml->name == 'gnm:Sheets') { |
||||
|
// break out of the loop once we've got our sheet names rather than parse the entire file |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $worksheetNames; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function listWorksheetInfo($pFilename) |
||||
|
{ |
||||
|
// Check if file exists |
||||
|
if (!file_exists($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
||||
|
} |
||||
|
|
||||
|
$xml = new XMLReader(); |
||||
|
$xml->open( |
||||
|
'compress.zlib://'.realpath($pFilename) |
||||
|
); |
||||
|
$xml->setParserProperty(2,true); |
||||
|
|
||||
|
$worksheetInfo = array(); |
||||
|
while ($xml->read()) { |
||||
|
if ($xml->name == 'gnm:Sheet' && $xml->nodeType == XMLReader::ELEMENT) { |
||||
|
$tmpInfo = array( |
||||
|
'worksheetName' => '', |
||||
|
'lastColumnLetter' => 'A', |
||||
|
'lastColumnIndex' => 0, |
||||
|
'totalRows' => 0, |
||||
|
'totalColumns' => 0, |
||||
|
); |
||||
|
|
||||
|
while ($xml->read()) { |
||||
|
if ($xml->name == 'gnm:Name' && $xml->nodeType == XMLReader::ELEMENT) { |
||||
|
$xml->read(); // Move onto the value node |
||||
|
$tmpInfo['worksheetName'] = (string) $xml->value; |
||||
|
} elseif ($xml->name == 'gnm:MaxCol' && $xml->nodeType == XMLReader::ELEMENT) { |
||||
|
$xml->read(); // Move onto the value node |
||||
|
$tmpInfo['lastColumnIndex'] = (int) $xml->value; |
||||
|
$tmpInfo['totalColumns'] = (int) $xml->value + 1; |
||||
|
} elseif ($xml->name == 'gnm:MaxRow' && $xml->nodeType == XMLReader::ELEMENT) { |
||||
|
$xml->read(); // Move onto the value node |
||||
|
$tmpInfo['totalRows'] = (int) $xml->value + 1; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
$tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); |
||||
|
$worksheetInfo[] = $tmpInfo; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $worksheetInfo; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private function _gzfileGetContents($filename) { |
||||
|
$file = @gzopen($filename, 'rb'); |
||||
|
if ($file !== false) { |
||||
|
$data = ''; |
||||
|
while (!gzeof($file)) { |
||||
|
$data .= gzread($file, 1024); |
||||
|
} |
||||
|
gzclose($file); |
||||
|
} |
||||
|
return $data; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Loads PHPExcel from file |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @return PHPExcel |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function load($pFilename) |
||||
|
{ |
||||
|
// Create new PHPExcel |
||||
|
$objPHPExcel = new PHPExcel(); |
||||
|
|
||||
|
// Load into this instance |
||||
|
return $this->loadIntoExisting($pFilename, $objPHPExcel); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Loads PHPExcel from file into PHPExcel instance |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @param PHPExcel $objPHPExcel |
||||
|
* @return PHPExcel |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) |
||||
|
{ |
||||
|
// Check if file exists |
||||
|
if (!file_exists($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
||||
|
} |
||||
|
|
||||
|
$timezoneObj = new DateTimeZone('Europe/London'); |
||||
|
$GMT = new DateTimeZone('UTC'); |
||||
|
|
||||
|
$gFileData = $this->_gzfileGetContents($pFilename); |
||||
|
|
||||
|
// echo '<pre>'; |
||||
|
// echo htmlentities($gFileData,ENT_QUOTES,'UTF-8'); |
||||
|
// echo '</pre><hr />'; |
||||
|
// |
||||
|
$xml = simplexml_load_string($gFileData); |
||||
|
$namespacesMeta = $xml->getNamespaces(true); |
||||
|
|
||||
|
// var_dump($namespacesMeta); |
||||
|
// |
||||
|
$gnmXML = $xml->children($namespacesMeta['gnm']); |
||||
|
|
||||
|
$docProps = $objPHPExcel->getProperties(); |
||||
|
// Document Properties are held differently, depending on the version of Gnumeric |
||||
|
if (isset($namespacesMeta['office'])) { |
||||
|
$officeXML = $xml->children($namespacesMeta['office']); |
||||
|
$officeDocXML = $officeXML->{'document-meta'}; |
||||
|
$officeDocMetaXML = $officeDocXML->meta; |
||||
|
|
||||
|
foreach($officeDocMetaXML as $officePropertyData) { |
||||
|
|
||||
|
$officePropertyDC = array(); |
||||
|
if (isset($namespacesMeta['dc'])) { |
||||
|
$officePropertyDC = $officePropertyData->children($namespacesMeta['dc']); |
||||
|
} |
||||
|
foreach($officePropertyDC as $propertyName => $propertyValue) { |
||||
|
$propertyValue = (string) $propertyValue; |
||||
|
switch ($propertyName) { |
||||
|
case 'title' : |
||||
|
$docProps->setTitle(trim($propertyValue)); |
||||
|
break; |
||||
|
case 'subject' : |
||||
|
$docProps->setSubject(trim($propertyValue)); |
||||
|
break; |
||||
|
case 'creator' : |
||||
|
$docProps->setCreator(trim($propertyValue)); |
||||
|
$docProps->setLastModifiedBy(trim($propertyValue)); |
||||
|
break; |
||||
|
case 'date' : |
||||
|
$creationDate = strtotime(trim($propertyValue)); |
||||
|
$docProps->setCreated($creationDate); |
||||
|
$docProps->setModified($creationDate); |
||||
|
break; |
||||
|
case 'description' : |
||||
|
$docProps->setDescription(trim($propertyValue)); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
$officePropertyMeta = array(); |
||||
|
if (isset($namespacesMeta['meta'])) { |
||||
|
$officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']); |
||||
|
} |
||||
|
foreach($officePropertyMeta as $propertyName => $propertyValue) { |
||||
|
$attributes = $propertyValue->attributes($namespacesMeta['meta']); |
||||
|
$propertyValue = (string) $propertyValue; |
||||
|
switch ($propertyName) { |
||||
|
case 'keyword' : |
||||
|
$docProps->setKeywords(trim($propertyValue)); |
||||
|
break; |
||||
|
case 'initial-creator' : |
||||
|
$docProps->setCreator(trim($propertyValue)); |
||||
|
$docProps->setLastModifiedBy(trim($propertyValue)); |
||||
|
break; |
||||
|
case 'creation-date' : |
||||
|
$creationDate = strtotime(trim($propertyValue)); |
||||
|
$docProps->setCreated($creationDate); |
||||
|
$docProps->setModified($creationDate); |
||||
|
break; |
||||
|
case 'user-defined' : |
||||
|
list(,$attrName) = explode(':',$attributes['name']); |
||||
|
switch ($attrName) { |
||||
|
case 'publisher' : |
||||
|
$docProps->setCompany(trim($propertyValue)); |
||||
|
break; |
||||
|
case 'category' : |
||||
|
$docProps->setCategory(trim($propertyValue)); |
||||
|
break; |
||||
|
case 'manager' : |
||||
|
$docProps->setManager(trim($propertyValue)); |
||||
|
break; |
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} elseif (isset($gnmXML->Summary)) { |
||||
|
foreach($gnmXML->Summary->Item as $summaryItem) { |
||||
|
$propertyName = $summaryItem->name; |
||||
|
$propertyValue = $summaryItem->{'val-string'}; |
||||
|
switch ($propertyName) { |
||||
|
case 'title' : |
||||
|
$docProps->setTitle(trim($propertyValue)); |
||||
|
break; |
||||
|
case 'comments' : |
||||
|
$docProps->setDescription(trim($propertyValue)); |
||||
|
break; |
||||
|
case 'keywords' : |
||||
|
$docProps->setKeywords(trim($propertyValue)); |
||||
|
break; |
||||
|
case 'category' : |
||||
|
$docProps->setCategory(trim($propertyValue)); |
||||
|
break; |
||||
|
case 'manager' : |
||||
|
$docProps->setManager(trim($propertyValue)); |
||||
|
break; |
||||
|
case 'author' : |
||||
|
$docProps->setCreator(trim($propertyValue)); |
||||
|
$docProps->setLastModifiedBy(trim($propertyValue)); |
||||
|
break; |
||||
|
case 'company' : |
||||
|
$docProps->setCompany(trim($propertyValue)); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$worksheetID = 0; |
||||
|
foreach($gnmXML->Sheets->Sheet as $sheet) { |
||||
|
$worksheetName = (string) $sheet->Name; |
||||
|
// echo '<b>Worksheet: ',$worksheetName,'</b><br />'; |
||||
|
if ((isset($this->_loadSheetsOnly)) && (!in_array($worksheetName, $this->_loadSheetsOnly))) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
$maxRow = $maxCol = 0; |
||||
|
|
||||
|
// Create new Worksheet |
||||
|
$objPHPExcel->createSheet(); |
||||
|
$objPHPExcel->setActiveSheetIndex($worksheetID); |
||||
|
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in formula |
||||
|
// cells... during the load, all formulae should be correct, and we're simply bringing the worksheet |
||||
|
// name in line with the formula, not the reverse |
||||
|
$objPHPExcel->getActiveSheet()->setTitle($worksheetName,false); |
||||
|
|
||||
|
if ((!$this->_readDataOnly) && (isset($sheet->PrintInformation))) { |
||||
|
if (isset($sheet->PrintInformation->Margins)) { |
||||
|
foreach($sheet->PrintInformation->Margins->children('gnm',TRUE) as $key => $margin) { |
||||
|
$marginAttributes = $margin->attributes(); |
||||
|
$marginSize = 72 / 100; // Default |
||||
|
switch($marginAttributes['PrefUnit']) { |
||||
|
case 'mm' : |
||||
|
$marginSize = intval($marginAttributes['Points']) / 100; |
||||
|
break; |
||||
|
} |
||||
|
switch($key) { |
||||
|
case 'top' : |
||||
|
$objPHPExcel->getActiveSheet()->getPageMargins()->setTop($marginSize); |
||||
|
break; |
||||
|
case 'bottom' : |
||||
|
$objPHPExcel->getActiveSheet()->getPageMargins()->setBottom($marginSize); |
||||
|
break; |
||||
|
case 'left' : |
||||
|
$objPHPExcel->getActiveSheet()->getPageMargins()->setLeft($marginSize); |
||||
|
break; |
||||
|
case 'right' : |
||||
|
$objPHPExcel->getActiveSheet()->getPageMargins()->setRight($marginSize); |
||||
|
break; |
||||
|
case 'header' : |
||||
|
$objPHPExcel->getActiveSheet()->getPageMargins()->setHeader($marginSize); |
||||
|
break; |
||||
|
case 'footer' : |
||||
|
$objPHPExcel->getActiveSheet()->getPageMargins()->setFooter($marginSize); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
foreach($sheet->Cells->Cell as $cell) { |
||||
|
$cellAttributes = $cell->attributes(); |
||||
|
$row = (int) $cellAttributes->Row + 1; |
||||
|
$column = (int) $cellAttributes->Col; |
||||
|
|
||||
|
if ($row > $maxRow) $maxRow = $row; |
||||
|
if ($column > $maxCol) $maxCol = $column; |
||||
|
|
||||
|
$column = PHPExcel_Cell::stringFromColumnIndex($column); |
||||
|
|
||||
|
// Read cell? |
||||
|
if ($this->getReadFilter() !== NULL) { |
||||
|
if (!$this->getReadFilter()->readCell($column, $row, $worksheetName)) { |
||||
|
continue; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$ValueType = $cellAttributes->ValueType; |
||||
|
$ExprID = (string) $cellAttributes->ExprID; |
||||
|
// echo 'Cell ',$column,$row,'<br />'; |
||||
|
// echo 'Type is ',$ValueType,'<br />'; |
||||
|
// echo 'Value is ',$cell,'<br />'; |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_FORMULA; |
||||
|
if ($ExprID > '') { |
||||
|
if (((string) $cell) > '') { |
||||
|
|
||||
|
$this->_expressions[$ExprID] = array( 'column' => $cellAttributes->Col, |
||||
|
'row' => $cellAttributes->Row, |
||||
|
'formula' => (string) $cell |
||||
|
); |
||||
|
// echo 'NEW EXPRESSION ',$ExprID,'<br />'; |
||||
|
} else { |
||||
|
$expression = $this->_expressions[$ExprID]; |
||||
|
|
||||
|
$cell = $this->_referenceHelper->updateFormulaReferences( $expression['formula'], |
||||
|
'A1', |
||||
|
$cellAttributes->Col - $expression['column'], |
||||
|
$cellAttributes->Row - $expression['row'], |
||||
|
$worksheetName |
||||
|
); |
||||
|
// echo 'SHARED EXPRESSION ',$ExprID,'<br />'; |
||||
|
// echo 'New Value is ',$cell,'<br />'; |
||||
|
} |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_FORMULA; |
||||
|
} else { |
||||
|
switch($ValueType) { |
||||
|
case '10' : // NULL |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_NULL; |
||||
|
break; |
||||
|
case '20' : // Boolean |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_BOOL; |
||||
|
$cell = ($cell == 'TRUE') ? True : False; |
||||
|
break; |
||||
|
case '30' : // Integer |
||||
|
$cell = intval($cell); |
||||
|
case '40' : // Float |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC; |
||||
|
break; |
||||
|
case '50' : // Error |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_ERROR; |
||||
|
break; |
||||
|
case '60' : // String |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_STRING; |
||||
|
break; |
||||
|
case '70' : // Cell Range |
||||
|
case '80' : // Array |
||||
|
} |
||||
|
} |
||||
|
$objPHPExcel->getActiveSheet()->getCell($column.$row)->setValueExplicit($cell,$type); |
||||
|
} |
||||
|
|
||||
|
if ((!$this->_readDataOnly) && (isset($sheet->Objects))) { |
||||
|
foreach($sheet->Objects->children('gnm',TRUE) as $key => $comment) { |
||||
|
$commentAttributes = $comment->attributes(); |
||||
|
// Only comment objects are handled at the moment |
||||
|
if ($commentAttributes->Text) { |
||||
|
$objPHPExcel->getActiveSheet()->getComment( (string)$commentAttributes->ObjectBound ) |
||||
|
->setAuthor( (string)$commentAttributes->Author ) |
||||
|
->setText($this->_parseRichText((string)$commentAttributes->Text) ); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
// echo '$maxCol=',$maxCol,'; $maxRow=',$maxRow,'<br />'; |
||||
|
// |
||||
|
foreach($sheet->Styles->StyleRegion as $styleRegion) { |
||||
|
$styleAttributes = $styleRegion->attributes(); |
||||
|
if (($styleAttributes['startRow'] <= $maxRow) && |
||||
|
($styleAttributes['startCol'] <= $maxCol)) { |
||||
|
|
||||
|
$startColumn = PHPExcel_Cell::stringFromColumnIndex((int) $styleAttributes['startCol']); |
||||
|
$startRow = $styleAttributes['startRow'] + 1; |
||||
|
|
||||
|
$endColumn = ($styleAttributes['endCol'] > $maxCol) ? $maxCol : (int) $styleAttributes['endCol']; |
||||
|
$endColumn = PHPExcel_Cell::stringFromColumnIndex($endColumn); |
||||
|
$endRow = ($styleAttributes['endRow'] > $maxRow) ? $maxRow : $styleAttributes['endRow']; |
||||
|
$endRow += 1; |
||||
|
$cellRange = $startColumn.$startRow.':'.$endColumn.$endRow; |
||||
|
// echo $cellRange,'<br />'; |
||||
|
|
||||
|
$styleAttributes = $styleRegion->Style->attributes(); |
||||
|
// var_dump($styleAttributes); |
||||
|
// echo '<br />'; |
||||
|
|
||||
|
// We still set the number format mask for date/time values, even if _readDataOnly is true |
||||
|
if ((!$this->_readDataOnly) || |
||||
|
(PHPExcel_Shared_Date::isDateTimeFormatCode($styleArray['numberformat']['code']))) { |
||||
|
$styleArray = array(); |
||||
|
$styleArray['numberformat']['code'] = (string) $styleAttributes['Format']; |
||||
|
// If _readDataOnly is false, we set all formatting information |
||||
|
if (!$this->_readDataOnly) { |
||||
|
switch($styleAttributes['HAlign']) { |
||||
|
case '1' : |
||||
|
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL; |
||||
|
break; |
||||
|
case '2' : |
||||
|
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_LEFT; |
||||
|
break; |
||||
|
case '4' : |
||||
|
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_RIGHT; |
||||
|
break; |
||||
|
case '8' : |
||||
|
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_CENTER; |
||||
|
break; |
||||
|
case '16' : |
||||
|
case '64' : |
||||
|
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS; |
||||
|
break; |
||||
|
case '32' : |
||||
|
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY; |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
switch($styleAttributes['VAlign']) { |
||||
|
case '1' : |
||||
|
$styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_TOP; |
||||
|
break; |
||||
|
case '2' : |
||||
|
$styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_BOTTOM; |
||||
|
break; |
||||
|
case '4' : |
||||
|
$styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_CENTER; |
||||
|
break; |
||||
|
case '8' : |
||||
|
$styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_JUSTIFY; |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
$styleArray['alignment']['wrap'] = ($styleAttributes['WrapText'] == '1') ? True : False; |
||||
|
$styleArray['alignment']['shrinkToFit'] = ($styleAttributes['ShrinkToFit'] == '1') ? True : False; |
||||
|
$styleArray['alignment']['indent'] = (intval($styleAttributes["Indent"]) > 0) ? $styleAttributes["indent"] : 0; |
||||
|
|
||||
|
$RGB = self::_parseGnumericColour($styleAttributes["Fore"]); |
||||
|
$styleArray['font']['color']['rgb'] = $RGB; |
||||
|
$RGB = self::_parseGnumericColour($styleAttributes["Back"]); |
||||
|
$shade = $styleAttributes["Shade"]; |
||||
|
if (($RGB != '000000') || ($shade != '0')) { |
||||
|
$styleArray['fill']['color']['rgb'] = $styleArray['fill']['startcolor']['rgb'] = $RGB; |
||||
|
$RGB2 = self::_parseGnumericColour($styleAttributes["PatternColor"]); |
||||
|
$styleArray['fill']['endcolor']['rgb'] = $RGB2; |
||||
|
switch($shade) { |
||||
|
case '1' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_SOLID; |
||||
|
break; |
||||
|
case '2' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR; |
||||
|
break; |
||||
|
case '3' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_GRADIENT_PATH; |
||||
|
break; |
||||
|
case '4' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKDOWN; |
||||
|
break; |
||||
|
case '5' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKGRAY; |
||||
|
break; |
||||
|
case '6' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKGRID; |
||||
|
break; |
||||
|
case '7' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKHORIZONTAL; |
||||
|
break; |
||||
|
case '8' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKTRELLIS; |
||||
|
break; |
||||
|
case '9' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKUP; |
||||
|
break; |
||||
|
case '10' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKVERTICAL; |
||||
|
break; |
||||
|
case '11' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_GRAY0625; |
||||
|
break; |
||||
|
case '12' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_GRAY125; |
||||
|
break; |
||||
|
case '13' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTDOWN; |
||||
|
break; |
||||
|
case '14' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRAY; |
||||
|
break; |
||||
|
case '15' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRID; |
||||
|
break; |
||||
|
case '16' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTHORIZONTAL; |
||||
|
break; |
||||
|
case '17' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTTRELLIS; |
||||
|
break; |
||||
|
case '18' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTUP; |
||||
|
break; |
||||
|
case '19' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTVERTICAL; |
||||
|
break; |
||||
|
case '20' : |
||||
|
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_MEDIUMGRAY; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$fontAttributes = $styleRegion->Style->Font->attributes(); |
||||
|
// var_dump($fontAttributes); |
||||
|
// echo '<br />'; |
||||
|
$styleArray['font']['name'] = (string) $styleRegion->Style->Font; |
||||
|
$styleArray['font']['size'] = intval($fontAttributes['Unit']); |
||||
|
$styleArray['font']['bold'] = ($fontAttributes['Bold'] == '1') ? True : False; |
||||
|
$styleArray['font']['italic'] = ($fontAttributes['Italic'] == '1') ? True : False; |
||||
|
$styleArray['font']['strike'] = ($fontAttributes['StrikeThrough'] == '1') ? True : False; |
||||
|
switch($fontAttributes['Underline']) { |
||||
|
case '1' : |
||||
|
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_SINGLE; |
||||
|
break; |
||||
|
case '2' : |
||||
|
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_DOUBLE; |
||||
|
break; |
||||
|
case '3' : |
||||
|
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING; |
||||
|
break; |
||||
|
case '4' : |
||||
|
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING; |
||||
|
break; |
||||
|
default : |
||||
|
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_NONE; |
||||
|
break; |
||||
|
} |
||||
|
switch($fontAttributes['Script']) { |
||||
|
case '1' : |
||||
|
$styleArray['font']['superScript'] = True; |
||||
|
break; |
||||
|
case '-1' : |
||||
|
$styleArray['font']['subScript'] = True; |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
if (isset($styleRegion->Style->StyleBorder)) { |
||||
|
if (isset($styleRegion->Style->StyleBorder->Top)) { |
||||
|
$styleArray['borders']['top'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Top->attributes()); |
||||
|
} |
||||
|
if (isset($styleRegion->Style->StyleBorder->Bottom)) { |
||||
|
$styleArray['borders']['bottom'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Bottom->attributes()); |
||||
|
} |
||||
|
if (isset($styleRegion->Style->StyleBorder->Left)) { |
||||
|
$styleArray['borders']['left'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Left->attributes()); |
||||
|
} |
||||
|
if (isset($styleRegion->Style->StyleBorder->Right)) { |
||||
|
$styleArray['borders']['right'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Right->attributes()); |
||||
|
} |
||||
|
if ((isset($styleRegion->Style->StyleBorder->Diagonal)) && (isset($styleRegion->Style->StyleBorder->{'Rev-Diagonal'}))) { |
||||
|
$styleArray['borders']['diagonal'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Diagonal->attributes()); |
||||
|
$styleArray['borders']['diagonaldirection'] = PHPExcel_Style_Borders::DIAGONAL_BOTH; |
||||
|
} elseif (isset($styleRegion->Style->StyleBorder->Diagonal)) { |
||||
|
$styleArray['borders']['diagonal'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Diagonal->attributes()); |
||||
|
$styleArray['borders']['diagonaldirection'] = PHPExcel_Style_Borders::DIAGONAL_UP; |
||||
|
} elseif (isset($styleRegion->Style->StyleBorder->{'Rev-Diagonal'})) { |
||||
|
$styleArray['borders']['diagonal'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->{'Rev-Diagonal'}->attributes()); |
||||
|
$styleArray['borders']['diagonaldirection'] = PHPExcel_Style_Borders::DIAGONAL_DOWN; |
||||
|
} |
||||
|
} |
||||
|
if (isset($styleRegion->Style->HyperLink)) { |
||||
|
// TO DO |
||||
|
$hyperlink = $styleRegion->Style->HyperLink->attributes(); |
||||
|
} |
||||
|
} |
||||
|
// var_dump($styleArray); |
||||
|
// echo '<br />'; |
||||
|
$objPHPExcel->getActiveSheet()->getStyle($cellRange)->applyFromArray($styleArray); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if ((!$this->_readDataOnly) && (isset($sheet->Cols))) { |
||||
|
// Column Widths |
||||
|
$columnAttributes = $sheet->Cols->attributes(); |
||||
|
$defaultWidth = $columnAttributes['DefaultSizePts'] / 5.4; |
||||
|
$c = 0; |
||||
|
foreach($sheet->Cols->ColInfo as $columnOverride) { |
||||
|
$columnAttributes = $columnOverride->attributes(); |
||||
|
$column = $columnAttributes['No']; |
||||
|
$columnWidth = $columnAttributes['Unit'] / 5.4; |
||||
|
$hidden = ((isset($columnAttributes['Hidden'])) && ($columnAttributes['Hidden'] == '1')) ? true : false; |
||||
|
$columnCount = (isset($columnAttributes['Count'])) ? $columnAttributes['Count'] : 1; |
||||
|
while ($c < $column) { |
||||
|
$objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setWidth($defaultWidth); |
||||
|
++$c; |
||||
|
} |
||||
|
while (($c < ($column+$columnCount)) && ($c <= $maxCol)) { |
||||
|
$objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setWidth($columnWidth); |
||||
|
if ($hidden) { |
||||
|
$objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setVisible(false); |
||||
|
} |
||||
|
++$c; |
||||
|
} |
||||
|
} |
||||
|
while ($c <= $maxCol) { |
||||
|
$objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setWidth($defaultWidth); |
||||
|
++$c; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if ((!$this->_readDataOnly) && (isset($sheet->Rows))) { |
||||
|
// Row Heights |
||||
|
$rowAttributes = $sheet->Rows->attributes(); |
||||
|
$defaultHeight = $rowAttributes['DefaultSizePts']; |
||||
|
$r = 0; |
||||
|
|
||||
|
foreach($sheet->Rows->RowInfo as $rowOverride) { |
||||
|
$rowAttributes = $rowOverride->attributes(); |
||||
|
$row = $rowAttributes['No']; |
||||
|
$rowHeight = $rowAttributes['Unit']; |
||||
|
$hidden = ((isset($rowAttributes['Hidden'])) && ($rowAttributes['Hidden'] == '1')) ? true : false; |
||||
|
$rowCount = (isset($rowAttributes['Count'])) ? $rowAttributes['Count'] : 1; |
||||
|
while ($r < $row) { |
||||
|
++$r; |
||||
|
$objPHPExcel->getActiveSheet()->getRowDimension($r)->setRowHeight($defaultHeight); |
||||
|
} |
||||
|
while (($r < ($row+$rowCount)) && ($r < $maxRow)) { |
||||
|
++$r; |
||||
|
$objPHPExcel->getActiveSheet()->getRowDimension($r)->setRowHeight($rowHeight); |
||||
|
if ($hidden) { |
||||
|
$objPHPExcel->getActiveSheet()->getRowDimension($r)->setVisible(false); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
while ($r < $maxRow) { |
||||
|
++$r; |
||||
|
$objPHPExcel->getActiveSheet()->getRowDimension($r)->setRowHeight($defaultHeight); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Handle Merged Cells in this worksheet |
||||
|
if (isset($sheet->MergedRegions)) { |
||||
|
foreach($sheet->MergedRegions->Merge as $mergeCells) { |
||||
|
if (strpos($mergeCells,':') !== FALSE) { |
||||
|
$objPHPExcel->getActiveSheet()->mergeCells($mergeCells); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$worksheetID++; |
||||
|
} |
||||
|
|
||||
|
// Loop through definedNames (global named ranges) |
||||
|
if (isset($gnmXML->Names)) { |
||||
|
foreach($gnmXML->Names->Name as $namedRange) { |
||||
|
$name = (string) $namedRange->name; |
||||
|
$range = (string) $namedRange->value; |
||||
|
if (stripos($range, '#REF!') !== false) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
$range = explode('!',$range); |
||||
|
$range[0] = trim($range[0],"'");; |
||||
|
if ($worksheet = $objPHPExcel->getSheetByName($range[0])) { |
||||
|
$extractedRange = str_replace('$', '', $range[1]); |
||||
|
$objPHPExcel->addNamedRange( new PHPExcel_NamedRange($name, $worksheet, $extractedRange) ); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// Return |
||||
|
return $objPHPExcel; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private static function _parseBorderAttributes($borderAttributes) |
||||
|
{ |
||||
|
$styleArray = array(); |
||||
|
|
||||
|
if (isset($borderAttributes["Color"])) { |
||||
|
$RGB = self::_parseGnumericColour($borderAttributes["Color"]); |
||||
|
$styleArray['color']['rgb'] = $RGB; |
||||
|
} |
||||
|
|
||||
|
switch ($borderAttributes["Style"]) { |
||||
|
case '0' : |
||||
|
$styleArray['style'] = PHPExcel_Style_Border::BORDER_NONE; |
||||
|
break; |
||||
|
case '1' : |
||||
|
$styleArray['style'] = PHPExcel_Style_Border::BORDER_THIN; |
||||
|
break; |
||||
|
case '2' : |
||||
|
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUM; |
||||
|
break; |
||||
|
case '4' : |
||||
|
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DASHED; |
||||
|
break; |
||||
|
case '5' : |
||||
|
$styleArray['style'] = PHPExcel_Style_Border::BORDER_THICK; |
||||
|
break; |
||||
|
case '6' : |
||||
|
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DOUBLE; |
||||
|
break; |
||||
|
case '7' : |
||||
|
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DOTTED; |
||||
|
break; |
||||
|
case '9' : |
||||
|
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DASHDOT; |
||||
|
break; |
||||
|
case '10' : |
||||
|
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT; |
||||
|
break; |
||||
|
case '11' : |
||||
|
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DASHDOTDOT; |
||||
|
break; |
||||
|
case '12' : |
||||
|
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT; |
||||
|
break; |
||||
|
case '13' : |
||||
|
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT; |
||||
|
break; |
||||
|
case '3' : |
||||
|
$styleArray['style'] = PHPExcel_Style_Border::BORDER_SLANTDASHDOT; |
||||
|
break; |
||||
|
case '8' : |
||||
|
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUMDASHED; |
||||
|
break; |
||||
|
} |
||||
|
return $styleArray; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private function _parseRichText($is = '') { |
||||
|
$value = new PHPExcel_RichText(); |
||||
|
|
||||
|
$value->createText($is); |
||||
|
|
||||
|
return $value; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private static function _parseGnumericColour($gnmColour) { |
||||
|
list($gnmR,$gnmG,$gnmB) = explode(':',$gnmColour); |
||||
|
$gnmR = substr(str_pad($gnmR,4,'0',STR_PAD_RIGHT),0,2); |
||||
|
$gnmG = substr(str_pad($gnmG,4,'0',STR_PAD_RIGHT),0,2); |
||||
|
$gnmB = substr(str_pad($gnmB,4,'0',STR_PAD_RIGHT),0,2); |
||||
|
$RGB = $gnmR.$gnmG.$gnmB; |
||||
|
// echo 'Excel Colour: ',$RGB,'<br />'; |
||||
|
return $RGB; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,468 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** PHPExcel root directory */ |
||||
|
if (!defined('PHPEXCEL_ROOT')) { |
||||
|
/** |
||||
|
* @ignore |
||||
|
*/ |
||||
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
||||
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_HTML |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader |
||||
|
{ |
||||
|
/** |
||||
|
* Input encoding |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_inputEncoding = 'ANSI'; |
||||
|
|
||||
|
/** |
||||
|
* Sheet index to read |
||||
|
* |
||||
|
* @var int |
||||
|
*/ |
||||
|
private $_sheetIndex = 0; |
||||
|
|
||||
|
/** |
||||
|
* Formats |
||||
|
* |
||||
|
* @var array |
||||
|
*/ |
||||
|
private $_formats = array( 'h1' => array( 'font' => array( 'bold' => true, |
||||
|
'size' => 24, |
||||
|
), |
||||
|
), // Bold, 24pt |
||||
|
'h2' => array( 'font' => array( 'bold' => true, |
||||
|
'size' => 18, |
||||
|
), |
||||
|
), // Bold, 18pt |
||||
|
'h3' => array( 'font' => array( 'bold' => true, |
||||
|
'size' => 13.5, |
||||
|
), |
||||
|
), // Bold, 13.5pt |
||||
|
'h4' => array( 'font' => array( 'bold' => true, |
||||
|
'size' => 12, |
||||
|
), |
||||
|
), // Bold, 12pt |
||||
|
'h5' => array( 'font' => array( 'bold' => true, |
||||
|
'size' => 10, |
||||
|
), |
||||
|
), // Bold, 10pt |
||||
|
'h6' => array( 'font' => array( 'bold' => true, |
||||
|
'size' => 7.5, |
||||
|
), |
||||
|
), // Bold, 7.5pt |
||||
|
'a' => array( 'font' => array( 'underline' => true, |
||||
|
'color' => array( 'argb' => PHPExcel_Style_Color::COLOR_BLUE, |
||||
|
), |
||||
|
), |
||||
|
), // Blue underlined |
||||
|
'hr' => array( 'borders' => array( 'bottom' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN, |
||||
|
'color' => array( PHPExcel_Style_Color::COLOR_BLACK, |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
), // Bottom border |
||||
|
); |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Reader_HTML |
||||
|
*/ |
||||
|
public function __construct() { |
||||
|
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Validate that the current file is an HTML file |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
protected function _isValidFormat() |
||||
|
{ |
||||
|
// Reading 2048 bytes should be enough to validate that the format is HTML |
||||
|
$data = fread($this->_fileHandle, 2048); |
||||
|
if ((strpos('<',$data) !== FALSE) && |
||||
|
(strlen($data) !== strlen(strip_tags($data)))) { |
||||
|
return TRUE; |
||||
|
} |
||||
|
|
||||
|
return FALSE; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Loads PHPExcel from file |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @return PHPExcel |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function load($pFilename) |
||||
|
{ |
||||
|
// Create new PHPExcel |
||||
|
$objPHPExcel = new PHPExcel(); |
||||
|
|
||||
|
// Load into this instance |
||||
|
return $this->loadIntoExisting($pFilename, $objPHPExcel); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set input encoding |
||||
|
* |
||||
|
* @param string $pValue Input encoding |
||||
|
*/ |
||||
|
public function setInputEncoding($pValue = 'ANSI') |
||||
|
{ |
||||
|
$this->_inputEncoding = $pValue; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get input encoding |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getInputEncoding() |
||||
|
{ |
||||
|
return $this->_inputEncoding; |
||||
|
} |
||||
|
|
||||
|
// Data Array used for testing only, should write to PHPExcel object on completion of tests |
||||
|
private $_dataArray = array(); |
||||
|
|
||||
|
private $_tableLevel = 0; |
||||
|
private $_nestedColumn = array('A'); |
||||
|
|
||||
|
private function _setTableStartColumn($column) { |
||||
|
if ($this->_tableLevel == 0) |
||||
|
$column = 'A'; |
||||
|
++$this->_tableLevel; |
||||
|
$this->_nestedColumn[$this->_tableLevel] = $column; |
||||
|
|
||||
|
return $this->_nestedColumn[$this->_tableLevel]; |
||||
|
} |
||||
|
|
||||
|
private function _getTableStartColumn() { |
||||
|
return $this->_nestedColumn[$this->_tableLevel]; |
||||
|
} |
||||
|
|
||||
|
private function _releaseTableStartColumn() { |
||||
|
--$this->_tableLevel; |
||||
|
return array_pop($this->_nestedColumn); |
||||
|
} |
||||
|
|
||||
|
private function _flushCell($sheet,$column,$row,&$cellContent) { |
||||
|
if (is_string($cellContent)) { |
||||
|
// Simple String content |
||||
|
if (trim($cellContent) > '') { |
||||
|
// Only actually write it if there's content in the string |
||||
|
// echo 'FLUSH CELL: ' , $column , $row , ' => ' , $cellContent , '<br />'; |
||||
|
// Write to worksheet to be done here... |
||||
|
// ... we return the cell so we can mess about with styles more easily |
||||
|
$cell = $sheet->setCellValue($column.$row,$cellContent,true); |
||||
|
$this->_dataArray[$row][$column] = $cellContent; |
||||
|
} |
||||
|
} else { |
||||
|
// We have a Rich Text run |
||||
|
// TODO |
||||
|
$this->_dataArray[$row][$column] = 'RICH TEXT: ' . $cellContent; |
||||
|
} |
||||
|
$cellContent = (string) ''; |
||||
|
} |
||||
|
|
||||
|
private function _processDomElement(DOMNode $element, $sheet, &$row, &$column, &$cellContent){ |
||||
|
foreach($element->childNodes as $child){ |
||||
|
if ($child instanceof DOMText) { |
||||
|
$domText = preg_replace('/\s+/',' ',trim($child->nodeValue)); |
||||
|
if (is_string($cellContent)) { |
||||
|
// simply append the text if the cell content is a plain text string |
||||
|
$cellContent .= $domText; |
||||
|
} else { |
||||
|
// but if we have a rich text run instead, we need to append it correctly |
||||
|
// TODO |
||||
|
} |
||||
|
} elseif($child instanceof DOMElement) { |
||||
|
// echo '<b>DOM ELEMENT: </b>' , strtoupper($child->nodeName) , '<br />'; |
||||
|
|
||||
|
$attributeArray = array(); |
||||
|
foreach($child->attributes as $attribute) { |
||||
|
// echo '<b>ATTRIBUTE: </b>' , $attribute->name , ' => ' , $attribute->value , '<br />'; |
||||
|
$attributeArray[$attribute->name] = $attribute->value; |
||||
|
} |
||||
|
|
||||
|
switch($child->nodeName) { |
||||
|
case 'meta' : |
||||
|
foreach($attributeArray as $attributeName => $attributeValue) { |
||||
|
switch($attributeName) { |
||||
|
case 'content': |
||||
|
// TODO |
||||
|
// Extract character set, so we can convert to UTF-8 if required |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
$this->_processDomElement($child,$sheet,$row,$column,$cellContent); |
||||
|
break; |
||||
|
case 'title' : |
||||
|
$this->_processDomElement($child,$sheet,$row,$column,$cellContent); |
||||
|
$sheet->setTitle($cellContent); |
||||
|
$cellContent = ''; |
||||
|
break; |
||||
|
case 'span' : |
||||
|
case 'div' : |
||||
|
case 'font' : |
||||
|
case 'i' : |
||||
|
case 'em' : |
||||
|
case 'strong': |
||||
|
case 'b' : |
||||
|
// echo 'STYLING, SPAN OR DIV<br />'; |
||||
|
if ($cellContent > '') |
||||
|
$cellContent .= ' '; |
||||
|
$this->_processDomElement($child,$sheet,$row,$column,$cellContent); |
||||
|
if ($cellContent > '') |
||||
|
$cellContent .= ' '; |
||||
|
// echo 'END OF STYLING, SPAN OR DIV<br />'; |
||||
|
break; |
||||
|
case 'hr' : |
||||
|
$this->_flushCell($sheet,$column,$row,$cellContent); |
||||
|
++$row; |
||||
|
if (isset($this->_formats[$child->nodeName])) { |
||||
|
$sheet->getStyle($column.$row)->applyFromArray($this->_formats[$child->nodeName]); |
||||
|
} else { |
||||
|
$cellContent = '----------'; |
||||
|
$this->_flushCell($sheet,$column,$row,$cellContent); |
||||
|
} |
||||
|
++$row; |
||||
|
case 'br' : |
||||
|
if ($this->_tableLevel > 0) { |
||||
|
// If we're inside a table, replace with a \n |
||||
|
$cellContent .= "\n"; |
||||
|
} else { |
||||
|
// Otherwise flush our existing content and move the row cursor on |
||||
|
$this->_flushCell($sheet,$column,$row,$cellContent); |
||||
|
++$row; |
||||
|
} |
||||
|
// echo 'HARD LINE BREAK: ' , '<br />'; |
||||
|
break; |
||||
|
case 'a' : |
||||
|
// echo 'START OF HYPERLINK: ' , '<br />'; |
||||
|
foreach($attributeArray as $attributeName => $attributeValue) { |
||||
|
switch($attributeName) { |
||||
|
case 'href': |
||||
|
// echo 'Link to ' , $attributeValue , '<br />'; |
||||
|
$sheet->getCell($column.$row)->getHyperlink()->setUrl($attributeValue); |
||||
|
if (isset($this->_formats[$child->nodeName])) { |
||||
|
$sheet->getStyle($column.$row)->applyFromArray($this->_formats[$child->nodeName]); |
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
$cellContent .= ' '; |
||||
|
$this->_processDomElement($child,$sheet,$row,$column,$cellContent); |
||||
|
// echo 'END OF HYPERLINK:' , '<br />'; |
||||
|
break; |
||||
|
case 'h1' : |
||||
|
case 'h2' : |
||||
|
case 'h3' : |
||||
|
case 'h4' : |
||||
|
case 'h5' : |
||||
|
case 'h6' : |
||||
|
case 'ol' : |
||||
|
case 'ul' : |
||||
|
case 'p' : |
||||
|
if ($this->_tableLevel > 0) { |
||||
|
// If we're inside a table, replace with a \n |
||||
|
$cellContent .= "\n"; |
||||
|
// echo 'LIST ENTRY: ' , '<br />'; |
||||
|
$this->_processDomElement($child,$sheet,$row,$column,$cellContent); |
||||
|
// echo 'END OF LIST ENTRY:' , '<br />'; |
||||
|
} else { |
||||
|
if ($cellContent > '') { |
||||
|
$this->_flushCell($sheet,$column,$row,$cellContent); |
||||
|
$row += 2; |
||||
|
} |
||||
|
// echo 'START OF PARAGRAPH: ' , '<br />'; |
||||
|
$this->_processDomElement($child,$sheet,$row,$column,$cellContent); |
||||
|
// echo 'END OF PARAGRAPH:' , '<br />'; |
||||
|
$this->_flushCell($sheet,$column,$row,$cellContent); |
||||
|
|
||||
|
if (isset($this->_formats[$child->nodeName])) { |
||||
|
$sheet->getStyle($column.$row)->applyFromArray($this->_formats[$child->nodeName]); |
||||
|
} |
||||
|
|
||||
|
$row += 2; |
||||
|
$column = 'A'; |
||||
|
} |
||||
|
break; |
||||
|
case 'li' : |
||||
|
if ($this->_tableLevel > 0) { |
||||
|
// If we're inside a table, replace with a \n |
||||
|
$cellContent .= "\n"; |
||||
|
// echo 'LIST ENTRY: ' , '<br />'; |
||||
|
$this->_processDomElement($child,$sheet,$row,$column,$cellContent); |
||||
|
// echo 'END OF LIST ENTRY:' , '<br />'; |
||||
|
} else { |
||||
|
if ($cellContent > '') { |
||||
|
$this->_flushCell($sheet,$column,$row,$cellContent); |
||||
|
} |
||||
|
++$row; |
||||
|
// echo 'LIST ENTRY: ' , '<br />'; |
||||
|
$this->_processDomElement($child,$sheet,$row,$column,$cellContent); |
||||
|
// echo 'END OF LIST ENTRY:' , '<br />'; |
||||
|
$this->_flushCell($sheet,$column,$row,$cellContent); |
||||
|
$column = 'A'; |
||||
|
} |
||||
|
break; |
||||
|
case 'table' : |
||||
|
$this->_flushCell($sheet,$column,$row,$cellContent); |
||||
|
$column = $this->_setTableStartColumn($column); |
||||
|
// echo 'START OF TABLE LEVEL ' , $this->_tableLevel , '<br />'; |
||||
|
if ($this->_tableLevel > 1) |
||||
|
--$row; |
||||
|
$this->_processDomElement($child,$sheet,$row,$column,$cellContent); |
||||
|
// echo 'END OF TABLE LEVEL ' , $this->_tableLevel , '<br />'; |
||||
|
$column = $this->_releaseTableStartColumn(); |
||||
|
if ($this->_tableLevel > 1) { |
||||
|
++$column; |
||||
|
} else { |
||||
|
++$row; |
||||
|
} |
||||
|
break; |
||||
|
case 'thead' : |
||||
|
case 'tbody' : |
||||
|
$this->_processDomElement($child,$sheet,$row,$column,$cellContent); |
||||
|
break; |
||||
|
case 'tr' : |
||||
|
++$row; |
||||
|
$column = $this->_getTableStartColumn(); |
||||
|
$cellContent = ''; |
||||
|
// echo 'START OF TABLE ' , $this->_tableLevel , ' ROW<br />'; |
||||
|
$this->_processDomElement($child,$sheet,$row,$column,$cellContent); |
||||
|
// echo 'END OF TABLE ' , $this->_tableLevel , ' ROW<br />'; |
||||
|
break; |
||||
|
case 'th' : |
||||
|
case 'td' : |
||||
|
// echo 'START OF TABLE ' , $this->_tableLevel , ' CELL<br />'; |
||||
|
$this->_processDomElement($child,$sheet,$row,$column,$cellContent); |
||||
|
// echo 'END OF TABLE ' , $this->_tableLevel , ' CELL<br />'; |
||||
|
$this->_flushCell($sheet,$column,$row,$cellContent); |
||||
|
++$column; |
||||
|
break; |
||||
|
case 'body' : |
||||
|
$row = 1; |
||||
|
$column = 'A'; |
||||
|
$content = ''; |
||||
|
$this->_tableLevel = 0; |
||||
|
$this->_processDomElement($child,$sheet,$row,$column,$cellContent); |
||||
|
break; |
||||
|
default: |
||||
|
$this->_processDomElement($child,$sheet,$row,$column,$cellContent); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Loads PHPExcel from file into PHPExcel instance |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @param PHPExcel $objPHPExcel |
||||
|
* @return PHPExcel |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) |
||||
|
{ |
||||
|
// Open file to validate |
||||
|
$this->_openFile($pFilename); |
||||
|
if (!$this->_isValidFormat()) { |
||||
|
fclose ($this->_fileHandle); |
||||
|
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid HTML file."); |
||||
|
} |
||||
|
// Close after validating |
||||
|
fclose ($this->_fileHandle); |
||||
|
|
||||
|
// Create new PHPExcel |
||||
|
while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) { |
||||
|
$objPHPExcel->createSheet(); |
||||
|
} |
||||
|
$objPHPExcel->setActiveSheetIndex( $this->_sheetIndex ); |
||||
|
|
||||
|
// Create a new DOM object |
||||
|
$dom = new domDocument; |
||||
|
// Reload the HTML file into the DOM object |
||||
|
$loaded = $dom->loadHTMLFile($pFilename); |
||||
|
if ($loaded === FALSE) { |
||||
|
throw new PHPExcel_Reader_Exception('Failed to load ',$pFilename,' as a DOM Document'); |
||||
|
} |
||||
|
|
||||
|
// Discard white space |
||||
|
$dom->preserveWhiteSpace = false; |
||||
|
|
||||
|
|
||||
|
$row = 0; |
||||
|
$column = 'A'; |
||||
|
$content = ''; |
||||
|
$this->_processDomElement($dom,$objPHPExcel->getActiveSheet(),$row,$column,$content); |
||||
|
|
||||
|
// echo '<hr />'; |
||||
|
// var_dump($this->_dataArray); |
||||
|
|
||||
|
// Return |
||||
|
return $objPHPExcel; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get sheet index |
||||
|
* |
||||
|
* @return int |
||||
|
*/ |
||||
|
public function getSheetIndex() { |
||||
|
return $this->_sheetIndex; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set sheet index |
||||
|
* |
||||
|
* @param int $pValue Sheet index |
||||
|
* @return PHPExcel_Reader_HTML |
||||
|
*/ |
||||
|
public function setSheetIndex($pValue = 0) { |
||||
|
$this->_sheetIndex = $pValue; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_IReadFilter |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
interface PHPExcel_Reader_IReadFilter |
||||
|
{ |
||||
|
/** |
||||
|
* Should this cell be read? |
||||
|
* |
||||
|
* @param $column String column index |
||||
|
* @param $row Row index |
||||
|
* @param $worksheetName Optional worksheet name |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function readCell($column, $row, $worksheetName = ''); |
||||
|
} |
||||
@ -0,0 +1,53 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_IReader |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
interface PHPExcel_Reader_IReader |
||||
|
{ |
||||
|
/** |
||||
|
* Can the current PHPExcel_Reader_IReader read the file? |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public function canRead($pFilename); |
||||
|
|
||||
|
/** |
||||
|
* Loads PHPExcel from file |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function load($pFilename); |
||||
|
} |
||||
@ -0,0 +1,695 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** PHPExcel root directory */ |
||||
|
if (!defined('PHPEXCEL_ROOT')) { |
||||
|
/** |
||||
|
* @ignore |
||||
|
*/ |
||||
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
||||
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_OOCalc |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader |
||||
|
{ |
||||
|
/** |
||||
|
* Formats |
||||
|
* |
||||
|
* @var array |
||||
|
*/ |
||||
|
private $_styles = array(); |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Reader_OOCalc |
||||
|
*/ |
||||
|
public function __construct() { |
||||
|
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Can the current PHPExcel_Reader_IReader read the file? |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @return boolean |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function canRead($pFilename) |
||||
|
{ |
||||
|
// Check if file exists |
||||
|
if (!file_exists($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
||||
|
} |
||||
|
|
||||
|
// Check if zip class exists |
||||
|
if (!class_exists('ZipArchive',FALSE)) { |
||||
|
throw new PHPExcel_Reader_Exception("ZipArchive library is not enabled"); |
||||
|
} |
||||
|
|
||||
|
$mimeType = 'UNKNOWN'; |
||||
|
// Load file |
||||
|
$zip = new ZipArchive; |
||||
|
if ($zip->open($pFilename) === true) { |
||||
|
// check if it is an OOXML archive |
||||
|
$stat = $zip->statName('mimetype'); |
||||
|
if ($stat && ($stat['size'] <= 255)) { |
||||
|
$mimeType = $zip->getFromName($stat['name']); |
||||
|
} elseif($stat = $zip->statName('META-INF/manifest.xml')) { |
||||
|
$xml = simplexml_load_string($zip->getFromName('META-INF/manifest.xml')); |
||||
|
$namespacesContent = $xml->getNamespaces(true); |
||||
|
if (isset($namespacesContent['manifest'])) { |
||||
|
$manifest = $xml->children($namespacesContent['manifest']); |
||||
|
foreach($manifest as $manifestDataSet) { |
||||
|
$manifestAttributes = $manifestDataSet->attributes($namespacesContent['manifest']); |
||||
|
if ($manifestAttributes->{'full-path'} == '/') { |
||||
|
$mimeType = (string) $manifestAttributes->{'media-type'}; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$zip->close(); |
||||
|
|
||||
|
return ($mimeType === 'application/vnd.oasis.opendocument.spreadsheet'); |
||||
|
} |
||||
|
|
||||
|
return FALSE; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function listWorksheetNames($pFilename) |
||||
|
{ |
||||
|
// Check if file exists |
||||
|
if (!file_exists($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
||||
|
} |
||||
|
|
||||
|
$zip = new ZipArchive; |
||||
|
if (!$zip->open($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! Error opening file."); |
||||
|
} |
||||
|
|
||||
|
$worksheetNames = array(); |
||||
|
|
||||
|
$xml = new XMLReader(); |
||||
|
$res = $xml->open('zip://'.realpath($pFilename).'#content.xml'); |
||||
|
$xml->setParserProperty(2,true); |
||||
|
|
||||
|
// Step into the first level of content of the XML |
||||
|
$xml->read(); |
||||
|
while ($xml->read()) { |
||||
|
// Quickly jump through to the office:body node |
||||
|
while ($xml->name !== 'office:body') { |
||||
|
if ($xml->isEmptyElement) |
||||
|
$xml->read(); |
||||
|
else |
||||
|
$xml->next(); |
||||
|
} |
||||
|
// Now read each node until we find our first table:table node |
||||
|
while ($xml->read()) { |
||||
|
if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) { |
||||
|
// Loop through each table:table node reading the table:name attribute for each worksheet name |
||||
|
do { |
||||
|
$worksheetNames[] = $xml->getAttribute('table:name'); |
||||
|
$xml->next(); |
||||
|
} while ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $worksheetNames; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function listWorksheetInfo($pFilename) |
||||
|
{ |
||||
|
// Check if file exists |
||||
|
if (!file_exists($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
||||
|
} |
||||
|
|
||||
|
$worksheetInfo = array(); |
||||
|
|
||||
|
$zip = new ZipArchive; |
||||
|
if (!$zip->open($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! Error opening file."); |
||||
|
} |
||||
|
|
||||
|
$xml = new XMLReader(); |
||||
|
$res = $xml->open('zip://'.realpath($pFilename).'#content.xml'); |
||||
|
$xml->setParserProperty(2,true); |
||||
|
|
||||
|
// Step into the first level of content of the XML |
||||
|
$xml->read(); |
||||
|
while ($xml->read()) { |
||||
|
// Quickly jump through to the office:body node |
||||
|
while ($xml->name !== 'office:body') { |
||||
|
if ($xml->isEmptyElement) |
||||
|
$xml->read(); |
||||
|
else |
||||
|
$xml->next(); |
||||
|
} |
||||
|
// Now read each node until we find our first table:table node |
||||
|
while ($xml->read()) { |
||||
|
if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) { |
||||
|
$worksheetNames[] = $xml->getAttribute('table:name'); |
||||
|
|
||||
|
$tmpInfo = array( |
||||
|
'worksheetName' => $xml->getAttribute('table:name'), |
||||
|
'lastColumnLetter' => 'A', |
||||
|
'lastColumnIndex' => 0, |
||||
|
'totalRows' => 0, |
||||
|
'totalColumns' => 0, |
||||
|
); |
||||
|
|
||||
|
// Loop through each child node of the table:table element reading |
||||
|
$currCells = 0; |
||||
|
do { |
||||
|
$xml->read(); |
||||
|
if ($xml->name == 'table:table-row' && $xml->nodeType == XMLReader::ELEMENT) { |
||||
|
$rowspan = $xml->getAttribute('table:number-rows-repeated'); |
||||
|
$rowspan = empty($rowspan) ? 1 : $rowspan; |
||||
|
$tmpInfo['totalRows'] += $rowspan; |
||||
|
$tmpInfo['totalColumns'] = max($tmpInfo['totalColumns'],$currCells); |
||||
|
$currCells = 0; |
||||
|
// Step into the row |
||||
|
$xml->read(); |
||||
|
do { |
||||
|
if ($xml->name == 'table:table-cell' && $xml->nodeType == XMLReader::ELEMENT) { |
||||
|
if (!$xml->isEmptyElement) { |
||||
|
$currCells++; |
||||
|
$xml->next(); |
||||
|
} else { |
||||
|
$xml->read(); |
||||
|
} |
||||
|
} elseif ($xml->name == 'table:covered-table-cell' && $xml->nodeType == XMLReader::ELEMENT) { |
||||
|
$mergeSize = $xml->getAttribute('table:number-columns-repeated'); |
||||
|
$currCells += $mergeSize; |
||||
|
$xml->read(); |
||||
|
} |
||||
|
} while ($xml->name != 'table:table-row'); |
||||
|
} |
||||
|
} while ($xml->name != 'table:table'); |
||||
|
|
||||
|
$tmpInfo['totalColumns'] = max($tmpInfo['totalColumns'],$currCells); |
||||
|
$tmpInfo['lastColumnIndex'] = $tmpInfo['totalColumns'] - 1; |
||||
|
$tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); |
||||
|
$worksheetInfo[] = $tmpInfo; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// foreach($workbookData->table as $worksheetDataSet) { |
||||
|
// $worksheetData = $worksheetDataSet->children($namespacesContent['table']); |
||||
|
// $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']); |
||||
|
// |
||||
|
// $rowIndex = 0; |
||||
|
// foreach ($worksheetData as $key => $rowData) { |
||||
|
// switch ($key) { |
||||
|
// case 'table-row' : |
||||
|
// $rowDataTableAttributes = $rowData->attributes($namespacesContent['table']); |
||||
|
// $rowRepeats = (isset($rowDataTableAttributes['number-rows-repeated'])) ? |
||||
|
// $rowDataTableAttributes['number-rows-repeated'] : 1; |
||||
|
// $columnIndex = 0; |
||||
|
// |
||||
|
// foreach ($rowData as $key => $cellData) { |
||||
|
// $cellDataTableAttributes = $cellData->attributes($namespacesContent['table']); |
||||
|
// $colRepeats = (isset($cellDataTableAttributes['number-columns-repeated'])) ? |
||||
|
// $cellDataTableAttributes['number-columns-repeated'] : 1; |
||||
|
// $cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']); |
||||
|
// if (isset($cellDataOfficeAttributes['value-type'])) { |
||||
|
// $tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex + $colRepeats - 1); |
||||
|
// $tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex + $rowRepeats); |
||||
|
// } |
||||
|
// $columnIndex += $colRepeats; |
||||
|
// } |
||||
|
// $rowIndex += $rowRepeats; |
||||
|
// break; |
||||
|
// } |
||||
|
// } |
||||
|
// |
||||
|
// $tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); |
||||
|
// $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1; |
||||
|
// |
||||
|
// } |
||||
|
// } |
||||
|
} |
||||
|
|
||||
|
return $worksheetInfo; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Loads PHPExcel from file |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @return PHPExcel |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function load($pFilename) |
||||
|
{ |
||||
|
// Create new PHPExcel |
||||
|
$objPHPExcel = new PHPExcel(); |
||||
|
|
||||
|
// Load into this instance |
||||
|
return $this->loadIntoExisting($pFilename, $objPHPExcel); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private static function identifyFixedStyleValue($styleList,&$styleAttributeValue) { |
||||
|
$styleAttributeValue = strtolower($styleAttributeValue); |
||||
|
foreach($styleList as $style) { |
||||
|
if ($styleAttributeValue == strtolower($style)) { |
||||
|
$styleAttributeValue = $style; |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Loads PHPExcel from file into PHPExcel instance |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @param PHPExcel $objPHPExcel |
||||
|
* @return PHPExcel |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) |
||||
|
{ |
||||
|
// Check if file exists |
||||
|
if (!file_exists($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
||||
|
} |
||||
|
|
||||
|
$timezoneObj = new DateTimeZone('Europe/London'); |
||||
|
$GMT = new DateTimeZone('UTC'); |
||||
|
|
||||
|
$zip = new ZipArchive; |
||||
|
if (!$zip->open($pFilename)) { |
||||
|
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! Error opening file."); |
||||
|
} |
||||
|
|
||||
|
// echo '<h1>Meta Information</h1>'; |
||||
|
$xml = simplexml_load_string($zip->getFromName("meta.xml")); |
||||
|
$namespacesMeta = $xml->getNamespaces(true); |
||||
|
// echo '<pre>'; |
||||
|
// print_r($namespacesMeta); |
||||
|
// echo '</pre><hr />'; |
||||
|
|
||||
|
$docProps = $objPHPExcel->getProperties(); |
||||
|
$officeProperty = $xml->children($namespacesMeta['office']); |
||||
|
foreach($officeProperty as $officePropertyData) { |
||||
|
$officePropertyDC = array(); |
||||
|
if (isset($namespacesMeta['dc'])) { |
||||
|
$officePropertyDC = $officePropertyData->children($namespacesMeta['dc']); |
||||
|
} |
||||
|
foreach($officePropertyDC as $propertyName => $propertyValue) { |
||||
|
switch ($propertyName) { |
||||
|
case 'title' : |
||||
|
$docProps->setTitle($propertyValue); |
||||
|
break; |
||||
|
case 'subject' : |
||||
|
$docProps->setSubject($propertyValue); |
||||
|
break; |
||||
|
case 'creator' : |
||||
|
$docProps->setCreator($propertyValue); |
||||
|
$docProps->setLastModifiedBy($propertyValue); |
||||
|
break; |
||||
|
case 'date' : |
||||
|
$creationDate = strtotime($propertyValue); |
||||
|
$docProps->setCreated($creationDate); |
||||
|
$docProps->setModified($creationDate); |
||||
|
break; |
||||
|
case 'description' : |
||||
|
$docProps->setDescription($propertyValue); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
$officePropertyMeta = array(); |
||||
|
if (isset($namespacesMeta['dc'])) { |
||||
|
$officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']); |
||||
|
} |
||||
|
foreach($officePropertyMeta as $propertyName => $propertyValue) { |
||||
|
$propertyValueAttributes = $propertyValue->attributes($namespacesMeta['meta']); |
||||
|
switch ($propertyName) { |
||||
|
case 'initial-creator' : |
||||
|
$docProps->setCreator($propertyValue); |
||||
|
break; |
||||
|
case 'keyword' : |
||||
|
$docProps->setKeywords($propertyValue); |
||||
|
break; |
||||
|
case 'creation-date' : |
||||
|
$creationDate = strtotime($propertyValue); |
||||
|
$docProps->setCreated($creationDate); |
||||
|
break; |
||||
|
case 'user-defined' : |
||||
|
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING; |
||||
|
foreach ($propertyValueAttributes as $key => $value) { |
||||
|
if ($key == 'name') { |
||||
|
$propertyValueName = (string) $value; |
||||
|
} elseif($key == 'value-type') { |
||||
|
switch ($value) { |
||||
|
case 'date' : |
||||
|
$propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'date'); |
||||
|
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE; |
||||
|
break; |
||||
|
case 'boolean' : |
||||
|
$propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'bool'); |
||||
|
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN; |
||||
|
break; |
||||
|
case 'float' : |
||||
|
$propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'r4'); |
||||
|
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_FLOAT; |
||||
|
break; |
||||
|
default : |
||||
|
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$docProps->setCustomProperty($propertyValueName,$propertyValue,$propertyValueType); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// echo '<h1>Workbook Content</h1>'; |
||||
|
$xml = simplexml_load_string($zip->getFromName("content.xml")); |
||||
|
$namespacesContent = $xml->getNamespaces(true); |
||||
|
// echo '<pre>'; |
||||
|
// print_r($namespacesContent); |
||||
|
// echo '</pre><hr />'; |
||||
|
|
||||
|
$workbook = $xml->children($namespacesContent['office']); |
||||
|
foreach($workbook->body->spreadsheet as $workbookData) { |
||||
|
$workbookData = $workbookData->children($namespacesContent['table']); |
||||
|
$worksheetID = 0; |
||||
|
foreach($workbookData->table as $worksheetDataSet) { |
||||
|
$worksheetData = $worksheetDataSet->children($namespacesContent['table']); |
||||
|
// print_r($worksheetData); |
||||
|
// echo '<br />'; |
||||
|
$worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']); |
||||
|
// print_r($worksheetDataAttributes); |
||||
|
// echo '<br />'; |
||||
|
if ((isset($this->_loadSheetsOnly)) && (isset($worksheetDataAttributes['name'])) && |
||||
|
(!in_array($worksheetDataAttributes['name'], $this->_loadSheetsOnly))) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// echo '<h2>Worksheet '.$worksheetDataAttributes['name'].'</h2>'; |
||||
|
// Create new Worksheet |
||||
|
$objPHPExcel->createSheet(); |
||||
|
$objPHPExcel->setActiveSheetIndex($worksheetID); |
||||
|
if (isset($worksheetDataAttributes['name'])) { |
||||
|
$worksheetName = (string) $worksheetDataAttributes['name']; |
||||
|
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in |
||||
|
// formula cells... during the load, all formulae should be correct, and we're simply |
||||
|
// bringing the worksheet name in line with the formula, not the reverse |
||||
|
$objPHPExcel->getActiveSheet()->setTitle($worksheetName,false); |
||||
|
} |
||||
|
|
||||
|
$rowID = 1; |
||||
|
foreach($worksheetData as $key => $rowData) { |
||||
|
// echo '<b>'.$key.'</b><br />'; |
||||
|
switch ($key) { |
||||
|
case 'table-header-rows': |
||||
|
foreach ($rowData as $key=>$cellData) { |
||||
|
$rowData = $cellData; |
||||
|
break; |
||||
|
} |
||||
|
case 'table-row' : |
||||
|
$rowDataTableAttributes = $rowData->attributes($namespacesContent['table']); |
||||
|
$rowRepeats = (isset($rowDataTableAttributes['number-rows-repeated'])) ? |
||||
|
$rowDataTableAttributes['number-rows-repeated'] : 1; |
||||
|
$columnID = 'A'; |
||||
|
foreach($rowData as $key => $cellData) { |
||||
|
if ($this->getReadFilter() !== NULL) { |
||||
|
if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) { |
||||
|
continue; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// echo '<b>'.$columnID.$rowID.'</b><br />'; |
||||
|
$cellDataText = (isset($namespacesContent['text'])) ? |
||||
|
$cellData->children($namespacesContent['text']) : |
||||
|
''; |
||||
|
$cellDataOffice = $cellData->children($namespacesContent['office']); |
||||
|
$cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']); |
||||
|
$cellDataTableAttributes = $cellData->attributes($namespacesContent['table']); |
||||
|
|
||||
|
// echo 'Office Attributes: '; |
||||
|
// print_r($cellDataOfficeAttributes); |
||||
|
// echo '<br />Table Attributes: '; |
||||
|
// print_r($cellDataTableAttributes); |
||||
|
// echo '<br />Cell Data Text'; |
||||
|
// print_r($cellDataText); |
||||
|
// echo '<br />'; |
||||
|
// |
||||
|
$type = $formatting = $hyperlink = null; |
||||
|
$hasCalculatedValue = false; |
||||
|
$cellDataFormula = ''; |
||||
|
if (isset($cellDataTableAttributes['formula'])) { |
||||
|
$cellDataFormula = $cellDataTableAttributes['formula']; |
||||
|
$hasCalculatedValue = true; |
||||
|
} |
||||
|
|
||||
|
if (isset($cellDataOffice->annotation)) { |
||||
|
// echo 'Cell has comment<br />'; |
||||
|
$annotationText = $cellDataOffice->annotation->children($namespacesContent['text']); |
||||
|
$textArray = array(); |
||||
|
foreach($annotationText as $t) { |
||||
|
foreach($t->span as $text) { |
||||
|
$textArray[] = (string)$text; |
||||
|
} |
||||
|
} |
||||
|
$text = implode("\n",$textArray); |
||||
|
// echo $text,'<br />'; |
||||
|
$objPHPExcel->getActiveSheet()->getComment( $columnID.$rowID ) |
||||
|
// ->setAuthor( $author ) |
||||
|
->setText($this->_parseRichText($text) ); |
||||
|
} |
||||
|
|
||||
|
if (isset($cellDataText->p)) { |
||||
|
// Consolidate if there are multiple p records (maybe with spans as well) |
||||
|
$dataArray = array(); |
||||
|
// Text can have multiple text:p and within those, multiple text:span. |
||||
|
// text:p newlines, but text:span does not. |
||||
|
// Also, here we assume there is no text data is span fields are specified, since |
||||
|
// we have no way of knowing proper positioning anyway. |
||||
|
foreach ($cellDataText->p as $pData) { |
||||
|
if (isset($pData->span)) { |
||||
|
// span sections do not newline, so we just create one large string here |
||||
|
$spanSection = ""; |
||||
|
foreach ($pData->span as $spanData) { |
||||
|
$spanSection .= $spanData; |
||||
|
} |
||||
|
array_push($dataArray, $spanSection); |
||||
|
} else { |
||||
|
array_push($dataArray, $pData); |
||||
|
} |
||||
|
} |
||||
|
$allCellDataText = implode($dataArray, "\n"); |
||||
|
|
||||
|
// echo 'Value Type is '.$cellDataOfficeAttributes['value-type'].'<br />'; |
||||
|
switch ($cellDataOfficeAttributes['value-type']) { |
||||
|
case 'string' : |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_STRING; |
||||
|
$dataValue = $allCellDataText; |
||||
|
if (isset($dataValue->a)) { |
||||
|
$dataValue = $dataValue->a; |
||||
|
$cellXLinkAttributes = $dataValue->attributes($namespacesContent['xlink']); |
||||
|
$hyperlink = $cellXLinkAttributes['href']; |
||||
|
} |
||||
|
break; |
||||
|
case 'boolean' : |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_BOOL; |
||||
|
$dataValue = ($allCellDataText == 'TRUE') ? True : False; |
||||
|
break; |
||||
|
case 'percentage' : |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC; |
||||
|
$dataValue = (float) $cellDataOfficeAttributes['value']; |
||||
|
if (floor($dataValue) == $dataValue) { |
||||
|
$dataValue = (integer) $dataValue; |
||||
|
} |
||||
|
$formatting = PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00; |
||||
|
break; |
||||
|
case 'currency' : |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC; |
||||
|
$dataValue = (float) $cellDataOfficeAttributes['value']; |
||||
|
if (floor($dataValue) == $dataValue) { |
||||
|
$dataValue = (integer) $dataValue; |
||||
|
} |
||||
|
$formatting = PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE; |
||||
|
break; |
||||
|
case 'float' : |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC; |
||||
|
$dataValue = (float) $cellDataOfficeAttributes['value']; |
||||
|
if (floor($dataValue) == $dataValue) { |
||||
|
if ($dataValue = (integer) $dataValue) |
||||
|
$dataValue = (integer) $dataValue; |
||||
|
else |
||||
|
$dataValue = (float) $dataValue; |
||||
|
} |
||||
|
break; |
||||
|
case 'date' : |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC; |
||||
|
$dateObj = new DateTime($cellDataOfficeAttributes['date-value'], $GMT); |
||||
|
$dateObj->setTimeZone($timezoneObj); |
||||
|
list($year,$month,$day,$hour,$minute,$second) = explode(' ',$dateObj->format('Y m d H i s')); |
||||
|
$dataValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year,$month,$day,$hour,$minute,$second); |
||||
|
if ($dataValue != floor($dataValue)) { |
||||
|
$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15.' '.PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4; |
||||
|
} else { |
||||
|
$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15; |
||||
|
} |
||||
|
break; |
||||
|
case 'time' : |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC; |
||||
|
$dataValue = PHPExcel_Shared_Date::PHPToExcel(strtotime('01-01-1970 '.implode(':',sscanf($cellDataOfficeAttributes['time-value'],'PT%dH%dM%dS')))); |
||||
|
$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4; |
||||
|
break; |
||||
|
} |
||||
|
// echo 'Data value is '.$dataValue.'<br />'; |
||||
|
// if ($hyperlink !== NULL) { |
||||
|
// echo 'Hyperlink is '.$hyperlink.'<br />'; |
||||
|
// } |
||||
|
} else { |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_NULL; |
||||
|
$dataValue = NULL; |
||||
|
} |
||||
|
|
||||
|
if ($hasCalculatedValue) { |
||||
|
$type = PHPExcel_Cell_DataType::TYPE_FORMULA; |
||||
|
// echo 'Formula: '.$cellDataFormula.'<br />'; |
||||
|
$cellDataFormula = substr($cellDataFormula,strpos($cellDataFormula,':=')+1); |
||||
|
$temp = explode('"',$cellDataFormula); |
||||
|
$tKey = false; |
||||
|
foreach($temp as &$value) { |
||||
|
// Only replace in alternate array entries (i.e. non-quoted blocks) |
||||
|
if ($tKey = !$tKey) { |
||||
|
$value = preg_replace('/\[\.(.*):\.(.*)\]/Ui','$1:$2',$value); |
||||
|
$value = preg_replace('/\[\.(.*)\]/Ui','$1',$value); |
||||
|
$value = PHPExcel_Calculation::_translateSeparator(';',',',$value,$inBraces); |
||||
|
} |
||||
|
} |
||||
|
unset($value); |
||||
|
// Then rebuild the formula string |
||||
|
$cellDataFormula = implode('"',$temp); |
||||
|
// echo 'Adjusted Formula: '.$cellDataFormula.'<br />'; |
||||
|
} |
||||
|
|
||||
|
$colRepeats = (isset($cellDataTableAttributes['number-columns-repeated'])) ? |
||||
|
$cellDataTableAttributes['number-columns-repeated'] : 1; |
||||
|
if ($type !== NULL) { |
||||
|
for ($i = 0; $i < $colRepeats; ++$i) { |
||||
|
if ($i > 0) { |
||||
|
++$columnID; |
||||
|
} |
||||
|
if ($type !== PHPExcel_Cell_DataType::TYPE_NULL) { |
||||
|
for ($rowAdjust = 0; $rowAdjust < $rowRepeats; ++$rowAdjust) { |
||||
|
$rID = $rowID + $rowAdjust; |
||||
|
$objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $dataValue),$type); |
||||
|
if ($hasCalculatedValue) { |
||||
|
// echo 'Forumla result is '.$dataValue.'<br />'; |
||||
|
$objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->setCalculatedValue($dataValue); |
||||
|
} |
||||
|
if ($formatting !== NULL) { |
||||
|
$objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode($formatting); |
||||
|
} else { |
||||
|
$objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_GENERAL); |
||||
|
} |
||||
|
if ($hyperlink !== NULL) { |
||||
|
$objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->getHyperlink()->setUrl($hyperlink); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Merged cells |
||||
|
if ((isset($cellDataTableAttributes['number-columns-spanned'])) || (isset($cellDataTableAttributes['number-rows-spanned']))) { |
||||
|
if (($type !== PHPExcel_Cell_DataType::TYPE_NULL) || (!$this->_readDataOnly)) { |
||||
|
$columnTo = $columnID; |
||||
|
if (isset($cellDataTableAttributes['number-columns-spanned'])) { |
||||
|
$columnTo = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cellDataTableAttributes['number-columns-spanned'] -2); |
||||
|
} |
||||
|
$rowTo = $rowID; |
||||
|
if (isset($cellDataTableAttributes['number-rows-spanned'])) { |
||||
|
$rowTo = $rowTo + $cellDataTableAttributes['number-rows-spanned'] - 1; |
||||
|
} |
||||
|
$cellRange = $columnID.$rowID.':'.$columnTo.$rowTo; |
||||
|
$objPHPExcel->getActiveSheet()->mergeCells($cellRange); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
++$columnID; |
||||
|
} |
||||
|
$rowID += $rowRepeats; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
++$worksheetID; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Return |
||||
|
return $objPHPExcel; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private function _parseRichText($is = '') { |
||||
|
$value = new PHPExcel_RichText(); |
||||
|
|
||||
|
$value->createText($is); |
||||
|
|
||||
|
return $value; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,450 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** PHPExcel root directory */ |
||||
|
if (!defined('PHPEXCEL_ROOT')) { |
||||
|
/** |
||||
|
* @ignore |
||||
|
*/ |
||||
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
||||
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Reader_SYLK |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Reader |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Reader_SYLK extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader |
||||
|
{ |
||||
|
/** |
||||
|
* Input encoding |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_inputEncoding = 'ANSI'; |
||||
|
|
||||
|
/** |
||||
|
* Sheet index to read |
||||
|
* |
||||
|
* @var int |
||||
|
*/ |
||||
|
private $_sheetIndex = 0; |
||||
|
|
||||
|
/** |
||||
|
* Formats |
||||
|
* |
||||
|
* @var array |
||||
|
*/ |
||||
|
private $_formats = array(); |
||||
|
|
||||
|
/** |
||||
|
* Format Count |
||||
|
* |
||||
|
* @var int |
||||
|
*/ |
||||
|
private $_format = 0; |
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_Reader_SYLK |
||||
|
*/ |
||||
|
public function __construct() { |
||||
|
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Validate that the current file is a SYLK file |
||||
|
* |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
protected function _isValidFormat() |
||||
|
{ |
||||
|
// Read sample data (first 2 KB will do) |
||||
|
$data = fread($this->_fileHandle, 2048); |
||||
|
|
||||
|
// Count delimiters in file |
||||
|
$delimiterCount = substr_count($data, ';'); |
||||
|
if ($delimiterCount < 1) { |
||||
|
return FALSE; |
||||
|
} |
||||
|
|
||||
|
// Analyze first line looking for ID; signature |
||||
|
$lines = explode("\n", $data); |
||||
|
if (substr($lines[0],0,4) != 'ID;P') { |
||||
|
return FALSE; |
||||
|
} |
||||
|
|
||||
|
return TRUE; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set input encoding |
||||
|
* |
||||
|
* @param string $pValue Input encoding |
||||
|
*/ |
||||
|
public function setInputEncoding($pValue = 'ANSI') |
||||
|
{ |
||||
|
$this->_inputEncoding = $pValue; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get input encoding |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function getInputEncoding() |
||||
|
{ |
||||
|
return $this->_inputEncoding; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function listWorksheetInfo($pFilename) |
||||
|
{ |
||||
|
// Open file |
||||
|
$this->_openFile($pFilename); |
||||
|
if (!$this->_isValidFormat()) { |
||||
|
fclose ($this->_fileHandle); |
||||
|
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file."); |
||||
|
} |
||||
|
$fileHandle = $this->_fileHandle; |
||||
|
rewind($fileHandle); |
||||
|
|
||||
|
$worksheetInfo = array(); |
||||
|
$worksheetInfo[0]['worksheetName'] = 'Worksheet'; |
||||
|
$worksheetInfo[0]['lastColumnLetter'] = 'A'; |
||||
|
$worksheetInfo[0]['lastColumnIndex'] = 0; |
||||
|
$worksheetInfo[0]['totalRows'] = 0; |
||||
|
$worksheetInfo[0]['totalColumns'] = 0; |
||||
|
|
||||
|
// Loop through file |
||||
|
$rowData = array(); |
||||
|
|
||||
|
// loop through one row (line) at a time in the file |
||||
|
$rowIndex = 0; |
||||
|
while (($rowData = fgets($fileHandle)) !== FALSE) { |
||||
|
$columnIndex = 0; |
||||
|
|
||||
|
// convert SYLK encoded $rowData to UTF-8 |
||||
|
$rowData = PHPExcel_Shared_String::SYLKtoUTF8($rowData); |
||||
|
|
||||
|
// explode each row at semicolons while taking into account that literal semicolon (;) |
||||
|
// is escaped like this (;;) |
||||
|
$rowData = explode("\t",str_replace('¤',';',str_replace(';',"\t",str_replace(';;','¤',rtrim($rowData))))); |
||||
|
|
||||
|
$dataType = array_shift($rowData); |
||||
|
if ($dataType == 'C') { |
||||
|
// Read cell value data |
||||
|
foreach($rowData as $rowDatum) { |
||||
|
switch($rowDatum{0}) { |
||||
|
case 'C' : |
||||
|
case 'X' : |
||||
|
$columnIndex = substr($rowDatum,1) - 1; |
||||
|
break; |
||||
|
case 'R' : |
||||
|
case 'Y' : |
||||
|
$rowIndex = substr($rowDatum,1); |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
$worksheetInfo[0]['totalRows'] = max($worksheetInfo[0]['totalRows'], $rowIndex); |
||||
|
$worksheetInfo[0]['lastColumnIndex'] = max($worksheetInfo[0]['lastColumnIndex'], $columnIndex); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$worksheetInfo[0]['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']); |
||||
|
$worksheetInfo[0]['totalColumns'] = $worksheetInfo[0]['lastColumnIndex'] + 1; |
||||
|
|
||||
|
// Close file |
||||
|
fclose($fileHandle); |
||||
|
|
||||
|
return $worksheetInfo; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Loads PHPExcel from file |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @return PHPExcel |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function load($pFilename) |
||||
|
{ |
||||
|
// Create new PHPExcel |
||||
|
$objPHPExcel = new PHPExcel(); |
||||
|
|
||||
|
// Load into this instance |
||||
|
return $this->loadIntoExisting($pFilename, $objPHPExcel); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Loads PHPExcel from file into PHPExcel instance |
||||
|
* |
||||
|
* @param string $pFilename |
||||
|
* @param PHPExcel $objPHPExcel |
||||
|
* @return PHPExcel |
||||
|
* @throws PHPExcel_Reader_Exception |
||||
|
*/ |
||||
|
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) |
||||
|
{ |
||||
|
// Open file |
||||
|
$this->_openFile($pFilename); |
||||
|
if (!$this->_isValidFormat()) { |
||||
|
fclose ($this->_fileHandle); |
||||
|
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file."); |
||||
|
} |
||||
|
$fileHandle = $this->_fileHandle; |
||||
|
rewind($fileHandle); |
||||
|
|
||||
|
// Create new PHPExcel |
||||
|
while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) { |
||||
|
$objPHPExcel->createSheet(); |
||||
|
} |
||||
|
$objPHPExcel->setActiveSheetIndex( $this->_sheetIndex ); |
||||
|
|
||||
|
$fromFormats = array('\-', '\ '); |
||||
|
$toFormats = array('-', ' '); |
||||
|
|
||||
|
// Loop through file |
||||
|
$rowData = array(); |
||||
|
$column = $row = ''; |
||||
|
|
||||
|
// loop through one row (line) at a time in the file |
||||
|
while (($rowData = fgets($fileHandle)) !== FALSE) { |
||||
|
|
||||
|
// convert SYLK encoded $rowData to UTF-8 |
||||
|
$rowData = PHPExcel_Shared_String::SYLKtoUTF8($rowData); |
||||
|
|
||||
|
// explode each row at semicolons while taking into account that literal semicolon (;) |
||||
|
// is escaped like this (;;) |
||||
|
$rowData = explode("\t",str_replace('¤',';',str_replace(';',"\t",str_replace(';;','¤',rtrim($rowData))))); |
||||
|
|
||||
|
$dataType = array_shift($rowData); |
||||
|
// Read shared styles |
||||
|
if ($dataType == 'P') { |
||||
|
$formatArray = array(); |
||||
|
foreach($rowData as $rowDatum) { |
||||
|
switch($rowDatum{0}) { |
||||
|
case 'P' : $formatArray['numberformat']['code'] = str_replace($fromFormats,$toFormats,substr($rowDatum,1)); |
||||
|
break; |
||||
|
case 'E' : |
||||
|
case 'F' : $formatArray['font']['name'] = substr($rowDatum,1); |
||||
|
break; |
||||
|
case 'L' : $formatArray['font']['size'] = substr($rowDatum,1); |
||||
|
break; |
||||
|
case 'S' : $styleSettings = substr($rowDatum,1); |
||||
|
for ($i=0;$i<strlen($styleSettings);++$i) { |
||||
|
switch ($styleSettings{$i}) { |
||||
|
case 'I' : $formatArray['font']['italic'] = true; |
||||
|
break; |
||||
|
case 'D' : $formatArray['font']['bold'] = true; |
||||
|
break; |
||||
|
case 'T' : $formatArray['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_THIN; |
||||
|
break; |
||||
|
case 'B' : $formatArray['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_THIN; |
||||
|
break; |
||||
|
case 'L' : $formatArray['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_THIN; |
||||
|
break; |
||||
|
case 'R' : $formatArray['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_THIN; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
$this->_formats['P'.$this->_format++] = $formatArray; |
||||
|
// Read cell value data |
||||
|
} elseif ($dataType == 'C') { |
||||
|
$hasCalculatedValue = false; |
||||
|
$cellData = $cellDataFormula = ''; |
||||
|
foreach($rowData as $rowDatum) { |
||||
|
switch($rowDatum{0}) { |
||||
|
case 'C' : |
||||
|
case 'X' : $column = substr($rowDatum,1); |
||||
|
break; |
||||
|
case 'R' : |
||||
|
case 'Y' : $row = substr($rowDatum,1); |
||||
|
break; |
||||
|
case 'K' : $cellData = substr($rowDatum,1); |
||||
|
break; |
||||
|
case 'E' : $cellDataFormula = '='.substr($rowDatum,1); |
||||
|
// Convert R1C1 style references to A1 style references (but only when not quoted) |
||||
|
$temp = explode('"',$cellDataFormula); |
||||
|
$key = false; |
||||
|
foreach($temp as &$value) { |
||||
|
// Only count/replace in alternate array entries |
||||
|
if ($key = !$key) { |
||||
|
preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE); |
||||
|
// Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way |
||||
|
// through the formula from left to right. Reversing means that we work right to left.through |
||||
|
// the formula |
||||
|
$cellReferences = array_reverse($cellReferences); |
||||
|
// Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent, |
||||
|
// then modify the formula to use that new reference |
||||
|
foreach($cellReferences as $cellReference) { |
||||
|
$rowReference = $cellReference[2][0]; |
||||
|
// Empty R reference is the current row |
||||
|
if ($rowReference == '') $rowReference = $row; |
||||
|
// Bracketed R references are relative to the current row |
||||
|
if ($rowReference{0} == '[') $rowReference = $row + trim($rowReference,'[]'); |
||||
|
$columnReference = $cellReference[4][0]; |
||||
|
// Empty C reference is the current column |
||||
|
if ($columnReference == '') $columnReference = $column; |
||||
|
// Bracketed C references are relative to the current column |
||||
|
if ($columnReference{0} == '[') $columnReference = $column + trim($columnReference,'[]'); |
||||
|
$A1CellReference = PHPExcel_Cell::stringFromColumnIndex($columnReference-1).$rowReference; |
||||
|
|
||||
|
$value = substr_replace($value,$A1CellReference,$cellReference[0][1],strlen($cellReference[0][0])); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
unset($value); |
||||
|
// Then rebuild the formula string |
||||
|
$cellDataFormula = implode('"',$temp); |
||||
|
$hasCalculatedValue = true; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1); |
||||
|
$cellData = PHPExcel_Calculation::_unwrapResult($cellData); |
||||
|
|
||||
|
// Set cell value |
||||
|
$objPHPExcel->getActiveSheet()->getCell($columnLetter.$row)->setValue(($hasCalculatedValue) ? $cellDataFormula : $cellData); |
||||
|
if ($hasCalculatedValue) { |
||||
|
$cellData = PHPExcel_Calculation::_unwrapResult($cellData); |
||||
|
$objPHPExcel->getActiveSheet()->getCell($columnLetter.$row)->setCalculatedValue($cellData); |
||||
|
} |
||||
|
// Read cell formatting |
||||
|
} elseif ($dataType == 'F') { |
||||
|
$formatStyle = $columnWidth = $styleSettings = ''; |
||||
|
$styleData = array(); |
||||
|
foreach($rowData as $rowDatum) { |
||||
|
switch($rowDatum{0}) { |
||||
|
case 'C' : |
||||
|
case 'X' : $column = substr($rowDatum,1); |
||||
|
break; |
||||
|
case 'R' : |
||||
|
case 'Y' : $row = substr($rowDatum,1); |
||||
|
break; |
||||
|
case 'P' : $formatStyle = $rowDatum; |
||||
|
break; |
||||
|
case 'W' : list($startCol,$endCol,$columnWidth) = explode(' ',substr($rowDatum,1)); |
||||
|
break; |
||||
|
case 'S' : $styleSettings = substr($rowDatum,1); |
||||
|
for ($i=0;$i<strlen($styleSettings);++$i) { |
||||
|
switch ($styleSettings{$i}) { |
||||
|
case 'I' : $styleData['font']['italic'] = true; |
||||
|
break; |
||||
|
case 'D' : $styleData['font']['bold'] = true; |
||||
|
break; |
||||
|
case 'T' : $styleData['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_THIN; |
||||
|
break; |
||||
|
case 'B' : $styleData['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_THIN; |
||||
|
break; |
||||
|
case 'L' : $styleData['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_THIN; |
||||
|
break; |
||||
|
case 'R' : $styleData['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_THIN; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
if (($formatStyle > '') && ($column > '') && ($row > '')) { |
||||
|
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1); |
||||
|
if (isset($this->_formats[$formatStyle])) { |
||||
|
$objPHPExcel->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($this->_formats[$formatStyle]); |
||||
|
} |
||||
|
} |
||||
|
if ((!empty($styleData)) && ($column > '') && ($row > '')) { |
||||
|
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1); |
||||
|
$objPHPExcel->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($styleData); |
||||
|
} |
||||
|
if ($columnWidth > '') { |
||||
|
if ($startCol == $endCol) { |
||||
|
$startCol = PHPExcel_Cell::stringFromColumnIndex($startCol-1); |
||||
|
$objPHPExcel->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth); |
||||
|
} else { |
||||
|
$startCol = PHPExcel_Cell::stringFromColumnIndex($startCol-1); |
||||
|
$endCol = PHPExcel_Cell::stringFromColumnIndex($endCol-1); |
||||
|
$objPHPExcel->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth); |
||||
|
do { |
||||
|
$objPHPExcel->getActiveSheet()->getColumnDimension(++$startCol)->setWidth($columnWidth); |
||||
|
} while ($startCol != $endCol); |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
foreach($rowData as $rowDatum) { |
||||
|
switch($rowDatum{0}) { |
||||
|
case 'C' : |
||||
|
case 'X' : $column = substr($rowDatum,1); |
||||
|
break; |
||||
|
case 'R' : |
||||
|
case 'Y' : $row = substr($rowDatum,1); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Close file |
||||
|
fclose($fileHandle); |
||||
|
|
||||
|
// Return |
||||
|
return $objPHPExcel; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get sheet index |
||||
|
* |
||||
|
* @return int |
||||
|
*/ |
||||
|
public function getSheetIndex() { |
||||
|
return $this->_sheetIndex; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set sheet index |
||||
|
* |
||||
|
* @param int $pValue Sheet index |
||||
|
* @return PHPExcel_Reader_SYLK |
||||
|
*/ |
||||
|
public function setSheetIndex($pValue = 0) { |
||||
|
$this->_sheetIndex = $pValue; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,64 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_RichText |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_RichText_ITextElement |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_RichText |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
interface PHPExcel_RichText_ITextElement |
||||
|
{ |
||||
|
/** |
||||
|
* Get text |
||||
|
* |
||||
|
* @return string Text |
||||
|
*/ |
||||
|
public function getText(); |
||||
|
|
||||
|
/** |
||||
|
* Set text |
||||
|
* |
||||
|
* @param $pText string Text |
||||
|
* @return PHPExcel_RichText_ITextElement |
||||
|
*/ |
||||
|
public function setText($pText = ''); |
||||
|
|
||||
|
/** |
||||
|
* Get font |
||||
|
* |
||||
|
* @return PHPExcel_Style_Font |
||||
|
*/ |
||||
|
public function getFont(); |
||||
|
|
||||
|
/** |
||||
|
* Get hash code |
||||
|
* |
||||
|
* @return string Hash code |
||||
|
*/ |
||||
|
public function getHashCode(); |
||||
|
} |
||||
@ -0,0 +1,102 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_RichText |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_RichText_Run |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_RichText |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_RichText_Run extends PHPExcel_RichText_TextElement implements PHPExcel_RichText_ITextElement |
||||
|
{ |
||||
|
/** |
||||
|
* Font |
||||
|
* |
||||
|
* @var PHPExcel_Style_Font |
||||
|
*/ |
||||
|
private $_font; |
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_RichText_Run instance |
||||
|
* |
||||
|
* @param string $pText Text |
||||
|
*/ |
||||
|
public function __construct($pText = '') |
||||
|
{ |
||||
|
// Initialise variables |
||||
|
$this->setText($pText); |
||||
|
$this->_font = new PHPExcel_Style_Font(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get font |
||||
|
* |
||||
|
* @return PHPExcel_Style_Font |
||||
|
*/ |
||||
|
public function getFont() { |
||||
|
return $this->_font; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set font |
||||
|
* |
||||
|
* @param PHPExcel_Style_Font $pFont Font |
||||
|
* @throws PHPExcel_Exception |
||||
|
* @return PHPExcel_RichText_ITextElement |
||||
|
*/ |
||||
|
public function setFont(PHPExcel_Style_Font $pFont = null) { |
||||
|
$this->_font = $pFont; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get hash code |
||||
|
* |
||||
|
* @return string Hash code |
||||
|
*/ |
||||
|
public function getHashCode() { |
||||
|
return md5( |
||||
|
$this->getText() |
||||
|
. $this->_font->getHashCode() |
||||
|
. __CLASS__ |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
||||
|
*/ |
||||
|
public function __clone() { |
||||
|
$vars = get_object_vars($this); |
||||
|
foreach ($vars as $key => $value) { |
||||
|
if (is_object($value)) { |
||||
|
$this->$key = clone $value; |
||||
|
} else { |
||||
|
$this->$key = $value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,108 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_RichText |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_RichText_TextElement |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_RichText |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_RichText_TextElement implements PHPExcel_RichText_ITextElement |
||||
|
{ |
||||
|
/** |
||||
|
* Text |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_text; |
||||
|
|
||||
|
/** |
||||
|
* Create a new PHPExcel_RichText_TextElement instance |
||||
|
* |
||||
|
* @param string $pText Text |
||||
|
*/ |
||||
|
public function __construct($pText = '') |
||||
|
{ |
||||
|
// Initialise variables |
||||
|
$this->_text = $pText; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get text |
||||
|
* |
||||
|
* @return string Text |
||||
|
*/ |
||||
|
public function getText() { |
||||
|
return $this->_text; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set text |
||||
|
* |
||||
|
* @param $pText string Text |
||||
|
* @return PHPExcel_RichText_ITextElement |
||||
|
*/ |
||||
|
public function setText($pText = '') { |
||||
|
$this->_text = $pText; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get font |
||||
|
* |
||||
|
* @return PHPExcel_Style_Font |
||||
|
*/ |
||||
|
public function getFont() { |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get hash code |
||||
|
* |
||||
|
* @return string Hash code |
||||
|
*/ |
||||
|
public function getHashCode() { |
||||
|
return md5( |
||||
|
$this->_text |
||||
|
. __CLASS__ |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
||||
|
*/ |
||||
|
public function __clone() { |
||||
|
$vars = get_object_vars($this); |
||||
|
foreach ($vars as $key => $value) { |
||||
|
if (is_object($value)) { |
||||
|
$this->$key = clone $value; |
||||
|
} else { |
||||
|
$this->$key = $value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,101 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Shared_CodePage |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared |
||||
|
* @copyright Copyright (c) 2006 - 2013 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 10006: return 'MACGREEK'; break; // Macintosh Greek |
||||
|
case 10007: return 'MACCYRILLIC'; break; // Macintosh Cyrillic |
||||
|
case 10029: return 'MACCENTRALEUROPE'; break; // Macintosh Central Europe |
||||
|
case 10079: return 'MACICELAND'; break; // Macintosh Icelandic |
||||
|
case 10081: return 'MACTURKISH'; break; // Macintosh Turkish |
||||
|
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); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,390 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Shared_Date |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
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 |
||||
|
|
||||
|
/* |
||||
|
* 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', |
||||
|
); |
||||
|
|
||||
|
/* |
||||
|
* 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() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 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() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
// 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); |
||||
|
} |
||||
|
|
||||
|
$timezoneAdjustment = ($adjustToTimezone) ? |
||||
|
PHPExcel_Shared_TimeZone::getTimezoneAdjustment($timezone, $returnValue) : |
||||
|
0; |
||||
|
|
||||
|
// Return |
||||
|
return $returnValue + $timezoneAdjustment; |
||||
|
} // function ExcelToPHP() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Convert a date from Excel to a PHP Date/Time object |
||||
|
* |
||||
|
* @param integer $dateValue Excel date/time value |
||||
|
* @return integer 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); |
||||
|
|
||||
|
return $dateObj; |
||||
|
} // function ExcelToPHPObject() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Convert a date from PHP to Excel |
||||
|
* |
||||
|
* @param mixed $dateValue PHP serialized date/time or date object |
||||
|
* @param boolean $adjustToTimezone Flag indicating whether $dateValue should be treated as |
||||
|
* a UST timestamp, or adjusted to UST |
||||
|
* @param string $timezone The timezone for finding the adjustment from UST |
||||
|
* @return mixed Excel date/time value |
||||
|
* or boolean FALSE on failure |
||||
|
*/ |
||||
|
public static function PHPToExcel($dateValue = 0, $adjustToTimezone = FALSE, $timezone = NULL) { |
||||
|
$saveTimeZone = date_default_timezone_get(); |
||||
|
date_default_timezone_set('UTC'); |
||||
|
$retValue = FALSE; |
||||
|
if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) { |
||||
|
$retValue = self::FormattedPHPToExcel( $dateValue->format('Y'), $dateValue->format('m'), $dateValue->format('d'), |
||||
|
$dateValue->format('H'), $dateValue->format('i'), $dateValue->format('s') |
||||
|
); |
||||
|
} elseif (is_numeric($dateValue)) { |
||||
|
$retValue = self::FormattedPHPToExcel( date('Y',$dateValue), date('m',$dateValue), date('d',$dateValue), |
||||
|
date('H',$dateValue), date('i',$dateValue), date('s',$dateValue) |
||||
|
); |
||||
|
} |
||||
|
date_default_timezone_set($saveTimeZone); |
||||
|
|
||||
|
return $retValue; |
||||
|
} // function PHPToExcel() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
// 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; |
||||
|
|
||||
|
$excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400; |
||||
|
|
||||
|
return (float) $excelDate + $excelTime; |
||||
|
} // function FormattedPHPToExcel() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 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 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() |
||||
|
|
||||
|
|
||||
|
private static $possibleDateFormatCharacters = 'eymdHs'; |
||||
|
|
||||
|
/** |
||||
|
* Is a given number format code a date/time? |
||||
|
* |
||||
|
* @param string $pFormatCode |
||||
|
* @return boolean |
||||
|
*/ |
||||
|
public static function isDateTimeFormatCode($pFormatCode = '') { |
||||
|
// Switch on formatcode |
||||
|
switch ($pFormatCode) { |
||||
|
// General contains an epoch letter 'e', so we trap for it explicitly here |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_GENERAL: |
||||
|
return FALSE; |
||||
|
// Explicitly defined date formats |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYMINUS: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMMINUS: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_MYMINUS: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME1: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME2: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME5: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME6: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME7: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME8: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX14: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX16: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX17: |
||||
|
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22: |
||||
|
return TRUE; |
||||
|
} |
||||
|
|
||||
|
// Typically number, currency or accounting (or occasionally fraction) formats |
||||
|
if ((substr($pFormatCode,0,1) == '_') || (substr($pFormatCode,0,2) == '0 ')) { |
||||
|
return FALSE; |
||||
|
} |
||||
|
// Try checking for any of the date formatting characters that don't appear within square braces |
||||
|
if (preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i',$pFormatCode)) { |
||||
|
// We might also have a format mask containing quoted strings... |
||||
|
// we don't want to test for any of our characters within the quoted blocks |
||||
|
if (strpos($pFormatCode,'"') !== FALSE) { |
||||
|
$segMatcher = FALSE; |
||||
|
foreach(explode('"',$pFormatCode) as $subVal) { |
||||
|
// Only test in alternate array entries (the non-quoted blocks) |
||||
|
if (($segMatcher = !$segMatcher) && |
||||
|
(preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i',$subVal))) { |
||||
|
return TRUE; |
||||
|
} |
||||
|
} |
||||
|
return FALSE; |
||||
|
} |
||||
|
return TRUE; |
||||
|
} |
||||
|
|
||||
|
// No date... |
||||
|
return FALSE; |
||||
|
} // function isDateTimeFormatCode() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 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); |
||||
|
|
||||
|
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; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
public static function monthStringToNumber($month) { |
||||
|
$monthIndex = 1; |
||||
|
foreach(self::$_monthNames as $shortMonthName => $longMonthName) { |
||||
|
if (($month === $longMonthName) || ($month === $shortMonthName)) { |
||||
|
return $monthIndex; |
||||
|
} |
||||
|
++$monthIndex; |
||||
|
} |
||||
|
return $month; |
||||
|
} |
||||
|
|
||||
|
public static function dayStringToNumber($day) { |
||||
|
$strippedDayValue = (str_replace(self::$_numberSuffixes,'',$day)); |
||||
|
if (is_numeric($strippedDayValue)) { |
||||
|
return $strippedDayValue; |
||||
|
} |
||||
|
return $day; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,272 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Shared_Drawing |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared |
||||
|
* @copyright Copyright (c) 2006 - 2013 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 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(); |
||||
|
|
||||
|
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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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']; |
||||
|
|
||||
|
} 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); |
||||
|
|
||||
|
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 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 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) |
||||
|
{ |
||||
|
// Load the image into a string |
||||
|
$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); |
||||
|
|
||||
|
// Process the header |
||||
|
// Structure: http://www.fastgraph.com/help/bmp_header_format.html |
||||
|
if (substr($header,0,4)=="424d") |
||||
|
{ |
||||
|
// Cut it in parts of 2 bytes |
||||
|
$header_parts = str_split($header,2); |
||||
|
|
||||
|
// Get the width 4 bytes |
||||
|
$width = hexdec($header_parts[19].$header_parts[18]); |
||||
|
|
||||
|
// Get the height 4 bytes |
||||
|
$height = hexdec($header_parts[23].$header_parts[22]); |
||||
|
|
||||
|
// Unset the header params |
||||
|
unset($header_parts); |
||||
|
} |
||||
|
|
||||
|
// Define starting X and Y |
||||
|
$x = 0; |
||||
|
$y = 1; |
||||
|
|
||||
|
// Create newimage |
||||
|
$image = imagecreatetruecolor($width,$height); |
||||
|
|
||||
|
// Grab the body from the image |
||||
|
$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); |
||||
|
|
||||
|
// Use end-line padding? Only when needed |
||||
|
$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) |
||||
|
{ |
||||
|
// 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; |
||||
|
|
||||
|
// Reset horizontal position |
||||
|
$x = 0; |
||||
|
|
||||
|
// Raise the height-position (bottom-up) |
||||
|
$y++; |
||||
|
|
||||
|
// Reached the image-height? Break the for-loop |
||||
|
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]); |
||||
|
|
||||
|
// Calculate and draw the pixel |
||||
|
$color = imagecolorallocate($image,$r,$g,$b); |
||||
|
imagesetpixel($image,$x,$height-$y,$color); |
||||
|
|
||||
|
// Raise the horizontal position |
||||
|
$x++; |
||||
|
} |
||||
|
|
||||
|
// Unset the body / free the memory |
||||
|
unset($body); |
||||
|
|
||||
|
// Return image-object |
||||
|
return $image; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,91 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Shared_Escher |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Shared_Escher |
||||
|
{ |
||||
|
/** |
||||
|
* Drawing Group Container |
||||
|
* |
||||
|
* @var PHPExcel_Shared_Escher_DggContainer |
||||
|
*/ |
||||
|
private $_dggContainer; |
||||
|
|
||||
|
/** |
||||
|
* Drawing Container |
||||
|
* |
||||
|
* @var PHPExcel_Shared_Escher_DgContainer |
||||
|
*/ |
||||
|
private $_dgContainer; |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,83 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Shared_Escher_DgContainer |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Shared_Escher_DgContainer |
||||
|
{ |
||||
|
/** |
||||
|
* Drawing index, 1-based. |
||||
|
* |
||||
|
* @var int |
||||
|
*/ |
||||
|
private $_dgId; |
||||
|
|
||||
|
/** |
||||
|
* Last shape index in this drawing |
||||
|
* |
||||
|
* @var int |
||||
|
*/ |
||||
|
private $_lastSpId; |
||||
|
|
||||
|
private $_spgrContainer = null; |
||||
|
|
||||
|
public function getDgId() |
||||
|
{ |
||||
|
return $this->_dgId; |
||||
|
} |
||||
|
|
||||
|
public function setDgId($value) |
||||
|
{ |
||||
|
$this->_dgId = $value; |
||||
|
} |
||||
|
|
||||
|
public function getLastSpId() |
||||
|
{ |
||||
|
return $this->_lastSpId; |
||||
|
} |
||||
|
|
||||
|
public function setLastSpId($value) |
||||
|
{ |
||||
|
$this->_lastSpId = $value; |
||||
|
} |
||||
|
|
||||
|
public function getSpgrContainer() |
||||
|
{ |
||||
|
return $this->_spgrContainer; |
||||
|
} |
||||
|
|
||||
|
public function setSpgrContainer($spgrContainer) |
||||
|
{ |
||||
|
return $this->_spgrContainer = $spgrContainer; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,109 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Shared_Escher_DgContainer_SpgrContainer |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Shared_Escher_DgContainer_SpgrContainer |
||||
|
{ |
||||
|
/** |
||||
|
* Parent Shape Group Container |
||||
|
* |
||||
|
* @var PHPExcel_Shared_Escher_DgContainer_SpgrContainer |
||||
|
*/ |
||||
|
private $_parent; |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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(); |
||||
|
|
||||
|
foreach ($this->_children as $child) { |
||||
|
if ($child instanceof PHPExcel_Shared_Escher_DgContainer_SpgrContainer) { |
||||
|
$allSpContainers = array_merge($allSpContainers, $child->getAllSpContainers()); |
||||
|
} else { |
||||
|
$allSpContainers[] = $child; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $allSpContainers; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,395 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 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; |
||||
|
|
||||
|
/** |
||||
|
* Is this a group shape? |
||||
|
* |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $_spgr = false; |
||||
|
|
||||
|
/** |
||||
|
* Shape type |
||||
|
* |
||||
|
* @var int |
||||
|
*/ |
||||
|
private $_spType; |
||||
|
|
||||
|
/** |
||||
|
* Shape flag |
||||
|
* |
||||
|
* @var int |
||||
|
*/ |
||||
|
private $_spFlag; |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
|
||||
|
$parent = $this->getParent(); |
||||
|
while ($parent instanceof PHPExcel_Shared_Escher_DgContainer_SpgrContainer) { |
||||
|
++$nestingLevel; |
||||
|
$parent = $parent->getParent(); |
||||
|
} |
||||
|
|
||||
|
return $nestingLevel; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,203 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Shared_Escher_DggContainer |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 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; |
||||
|
|
||||
|
/** |
||||
|
* Total number of drawings saved |
||||
|
* |
||||
|
* @var int |
||||
|
*/ |
||||
|
private $_cDgSaved; |
||||
|
|
||||
|
/** |
||||
|
* Total number of shapes saved (including group shapes) |
||||
|
* |
||||
|
* @var int |
||||
|
*/ |
||||
|
private $_cSpSaved; |
||||
|
|
||||
|
/** |
||||
|
* 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 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set identifier clusters. array(<drawingId> => <max shape id>, ...) |
||||
|
* |
||||
|
* @param array $pValue |
||||
|
*/ |
||||
|
public function setIDCLs($pValue) |
||||
|
{ |
||||
|
$this->_IDCLs = $pValue; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,65 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Shared_Escher_DggContainer_BstoreContainer |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 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(); |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,120 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 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; |
||||
|
|
||||
|
/** |
||||
|
* 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 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,91 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared_Escher |
||||
|
* @copyright Copyright (c) 2006 - 2013 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; |
||||
|
|
||||
|
/** |
||||
|
* Raw image data |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private $_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 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; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,317 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Shared_Excel5 |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared |
||||
|
* @copyright Copyright (c) 2006 - 2013 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(); |
||||
|
|
||||
|
$columnDimensions = $sheet->getColumnDimensions(); |
||||
|
|
||||
|
// 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); |
||||
|
|
||||
|
} else if ($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); |
||||
|
} |
||||
|
|
||||
|
// now find the effective column width in pixels |
||||
|
if (isset($columnDimensions[$col]) and !$columnDimensions[$col]->getVisible()) { |
||||
|
$effectivePixelWidth = 0; |
||||
|
} else { |
||||
|
$effectivePixelWidth = $pixelWidth; |
||||
|
} |
||||
|
|
||||
|
return $effectivePixelWidth; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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(); |
||||
|
|
||||
|
$rowDimensions = $sheet->getRowDimensions(); |
||||
|
|
||||
|
// 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 |
||||
|
|
||||
|
} else if ($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 row height in pixels |
||||
|
if ( isset($rowDimensions[$row]) and !$rowDimensions[$row]->getVisible() ) { |
||||
|
$effectivePixelRowHeight = 0; |
||||
|
} else { |
||||
|
$effectivePixelRowHeight = $pixelRowHeight; |
||||
|
} |
||||
|
|
||||
|
return $effectivePixelRowHeight; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
|
||||
|
// 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)); |
||||
|
} |
||||
|
|
||||
|
// correct for offsetX in startcell |
||||
|
$distanceX -= (int) floor(self::sizeCol($sheet, $startColumn) * $startOffsetX / 1024); |
||||
|
|
||||
|
// correct for offsetX in endcell |
||||
|
$distanceX -= (int) floor(self::sizeCol($sheet, $endColumn) * (1 - $endOffsetX / 1024)); |
||||
|
|
||||
|
return $distanceX; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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; |
||||
|
|
||||
|
// add the widths of the spanning rows |
||||
|
for ($row = $startRow; $row <= $endRow; ++$row) { |
||||
|
$distanceY += self::sizeRow($sheet, $row); |
||||
|
} |
||||
|
|
||||
|
// 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)); |
||||
|
|
||||
|
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; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,178 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Shared_File |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared |
||||
|
* @copyright Copyright (c) 2006 - 2013 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; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 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() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 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() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 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); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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); |
||||
|
} |
||||
|
|
||||
|
// 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; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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); } |
||||
|
} |
||||
|
|
||||
|
// 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()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,775 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* PHPExcel |
||||
|
* |
||||
|
* Copyright (c) 2006 - 2013 PHPExcel |
||||
|
* |
||||
|
* This library is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU Lesser General Public |
||||
|
* License as published by the Free Software Foundation; either |
||||
|
* version 2.1 of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This library is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
|
* Lesser General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU Lesser General Public |
||||
|
* License along with this library; if not, write to the Free Software |
||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
||||
|
* @version 1.7.9, 2013-06-02 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* PHPExcel_Shared_Font |
||||
|
* |
||||
|
* @category PHPExcel |
||||
|
* @package PHPExcel_Shared |
||||
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) |
||||
|
*/ |
||||
|
class PHPExcel_Shared_Font |
||||
|
{ |
||||
|
/* Methods for resolving autosize value */ |
||||
|
const AUTOSIZE_METHOD_APPROX = 'approx'; |
||||
|
const AUTOSIZE_METHOD_EXACT = 'exact'; |
||||
|
|
||||
|
private static $_autoSizeMethods = array( |
||||
|
self::AUTOSIZE_METHOD_APPROX, |
||||
|
self::AUTOSIZE_METHOD_EXACT, |
||||
|
); |
||||
|
|
||||
|
/** Character set codes used by BIFF5-8 in Font records */ |
||||
|
const CHARSET_ANSI_LATIN = 0x00; |
||||
|
const CHARSET_SYSTEM_DEFAULT = 0x01; |
||||
|
const CHARSET_SYMBOL = 0x02; |
||||
|
const CHARSET_APPLE_ROMAN = 0x4D; |
||||
|
const CHARSET_ANSI_JAPANESE_SHIFTJIS = 0x80; |
||||
|
const CHARSET_ANSI_KOREAN_HANGUL = 0x81; |
||||
|
const CHARSET_ANSI_KOREAN_JOHAB = 0x82; |
||||
|
const CHARSET_ANSI_CHINESE_SIMIPLIFIED = 0x86; // gb2312 |
||||
|
const CHARSET_ANSI_CHINESE_TRADITIONAL = 0x88; // big5 |
||||
|
const CHARSET_ANSI_GREEK = 0xA1; |
||||
|
const CHARSET_ANSI_TURKISH = 0xA2; |
||||
|
const CHARSET_ANSI_VIETNAMESE = 0xA3; |
||||
|
const CHARSET_ANSI_HEBREW = 0xB1; |
||||
|
const CHARSET_ANSI_ARABIC = 0xB2; |
||||
|
const CHARSET_ANSI_BALTIC = 0xBA; |
||||
|
const CHARSET_ANSI_CYRILLIC = 0xCC; |
||||
|
const CHARSET_ANSI_THAI = 0xDD; |
||||
|
const CHARSET_ANSI_LATIN_II = 0xEE; |
||||
|
const CHARSET_OEM_LATIN_I = 0xFF; |
||||
|
|
||||
|
// XXX: Constants created! |
||||
|
/** Font filenames */ |
||||
|
const ARIAL = 'arial.ttf'; |
||||
|
const ARIAL_BOLD = 'arialbd.ttf'; |
||||
|
const ARIAL_ITALIC = 'ariali.ttf'; |
||||
|
const ARIAL_BOLD_ITALIC = 'arialbi.ttf'; |
||||
|
|
||||
|
const CALIBRI = 'CALIBRI.TTF'; |
||||
|
const CALIBRI_BOLD = 'CALIBRIB.TTF'; |
||||
|
const CALIBRI_ITALIC = 'CALIBRII.TTF'; |
||||
|
const CALIBRI_BOLD_ITALIC = 'CALIBRIZ.TTF'; |
||||
|
|
||||
|
const COMIC_SANS_MS = 'comic.ttf'; |
||||
|
const COMIC_SANS_MS_BOLD = 'comicbd.ttf'; |
||||
|
|
||||
|
const COURIER_NEW = 'cour.ttf'; |
||||
|
const COURIER_NEW_BOLD = 'courbd.ttf'; |
||||
|
const COURIER_NEW_ITALIC = 'couri.ttf'; |
||||
|
const COURIER_NEW_BOLD_ITALIC = 'courbi.ttf'; |
||||
|
|
||||
|
const GEORGIA = 'georgia.ttf'; |
||||
|
const GEORGIA_BOLD = 'georgiab.ttf'; |
||||
|
const GEORGIA_ITALIC = 'georgiai.ttf'; |
||||
|
const GEORGIA_BOLD_ITALIC = 'georgiaz.ttf'; |
||||
|
|
||||
|
const IMPACT = 'impact.ttf'; |
||||
|
|
||||
|
const LIBERATION_SANS = 'LiberationSans-Regular.ttf'; |
||||
|
const LIBERATION_SANS_BOLD = 'LiberationSans-Bold.ttf'; |
||||
|
const LIBERATION_SANS_ITALIC = 'LiberationSans-Italic.ttf'; |
||||
|
const LIBERATION_SANS_BOLD_ITALIC = 'LiberationSans-BoldItalic.ttf'; |
||||
|
|
||||
|
const LUCIDA_CONSOLE = 'lucon.ttf'; |
||||
|
const LUCIDA_SANS_UNICODE = 'l_10646.ttf'; |
||||
|
|
||||
|
const MICROSOFT_SANS_SERIF = 'micross.ttf'; |
||||
|
|
||||
|
const PALATINO_LINOTYPE = 'pala.ttf'; |
||||
|
const PALATINO_LINOTYPE_BOLD = 'palab.ttf'; |
||||
|
const PALATINO_LINOTYPE_ITALIC = 'palai.ttf'; |
||||
|
const PALATINO_LINOTYPE_BOLD_ITALIC = 'palabi.ttf'; |
||||
|
|
||||
|
const SYMBOL = 'symbol.ttf'; |
||||
|
|
||||
|
const TAHOMA = 'tahoma.ttf'; |
||||
|
const TAHOMA_BOLD = 'tahomabd.ttf'; |
||||
|
|
||||
|
const TIMES_NEW_ROMAN = 'times.ttf'; |
||||
|
const TIMES_NEW_ROMAN_BOLD = 'timesbd.ttf'; |
||||
|
const TIMES_NEW_ROMAN_ITALIC = 'timesi.ttf'; |
||||
|
const TIMES_NEW_ROMAN_BOLD_ITALIC = 'timesbi.ttf'; |
||||
|
|
||||
|
const TREBUCHET_MS = 'trebuc.ttf'; |
||||
|
const TREBUCHET_MS_BOLD = 'trebucbd.ttf'; |
||||
|
const TREBUCHET_MS_ITALIC = 'trebucit.ttf'; |
||||
|
const TREBUCHET_MS_BOLD_ITALIC = 'trebucbi.ttf'; |
||||
|
|
||||
|
const VERDANA = 'verdana.ttf'; |
||||
|
const VERDANA_BOLD = 'verdanab.ttf'; |
||||
|
const VERDANA_ITALIC = 'verdanai.ttf'; |
||||
|
const VERDANA_BOLD_ITALIC = 'verdanaz.ttf'; |
||||
|
|
||||
|
/** |
||||
|
* AutoSize method |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private static $autoSizeMethod = self::AUTOSIZE_METHOD_APPROX; |
||||
|
|
||||
|
/** |
||||
|
* Path to folder containing TrueType font .ttf files |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
private static $trueTypeFontPath = null; |
||||
|
|
||||
|
/** |
||||
|
* How wide is a default column for a given default font and size? |
||||
|
* Empirical data found by inspecting real Excel files and reading off the pixel width |
||||
|
* in Microsoft Office Excel 2007. |
||||
|
* |
||||
|
* @var array |
||||
|
*/ |
||||
|
public static $defaultColumnWidths = array( |
||||
|
'Arial' => array( |
||||
|
1 => array('px' => 24, 'width' => 12.00000000), |
||||
|
2 => array('px' => 24, 'width' => 12.00000000), |
||||
|
3 => array('px' => 32, 'width' => 10.66406250), |
||||
|
4 => array('px' => 32, 'width' => 10.66406250), |
||||
|
5 => array('px' => 40, 'width' => 10.00000000), |
||||
|
6 => array('px' => 48, 'width' => 9.59765625), |
||||
|
7 => array('px' => 48, 'width' => 9.59765625), |
||||
|
8 => array('px' => 56, 'width' => 9.33203125), |
||||
|
9 => array('px' => 64, 'width' => 9.14062500), |
||||
|
10 => array('px' => 64, 'width' => 9.14062500), |
||||
|
), |
||||
|
'Calibri' => array( |
||||
|
1 => array('px' => 24, 'width' => 12.00000000), |
||||
|
2 => array('px' => 24, 'width' => 12.00000000), |
||||
|
3 => array('px' => 32, 'width' => 10.66406250), |
||||
|
4 => array('px' => 32, 'width' => 10.66406250), |
||||
|
5 => array('px' => 40, 'width' => 10.00000000), |
||||
|
6 => array('px' => 48, 'width' => 9.59765625), |
||||
|
7 => array('px' => 48, 'width' => 9.59765625), |
||||
|
8 => array('px' => 56, 'width' => 9.33203125), |
||||
|
9 => array('px' => 56, 'width' => 9.33203125), |
||||
|
10 => array('px' => 64, 'width' => 9.14062500), |
||||
|
11 => array('px' => 64, 'width' => 9.14062500), |
||||
|
), |
||||
|
'Verdana' => array( |
||||
|
1 => array('px' => 24, 'width' => 12.00000000), |
||||
|
2 => array('px' => 24, 'width' => 12.00000000), |
||||
|
3 => array('px' => 32, 'width' => 10.66406250), |
||||
|
4 => array('px' => 32, 'width' => 10.66406250), |
||||
|
5 => array('px' => 40, 'width' => 10.00000000), |
||||
|
6 => array('px' => 48, 'width' => 9.59765625), |
||||
|
7 => array('px' => 48, 'width' => 9.59765625), |
||||
|
8 => array('px' => 64, 'width' => 9.14062500), |
||||
|
9 => array('px' => 72, 'width' => 9.00000000), |
||||
|
10 => array('px' => 72, 'width' => 9.00000000), |
||||
|
), |
||||
|
); |
||||
|
|
||||
|
/** |
||||
|
* Set autoSize method |
||||
|
* |
||||
|
* @param string $pValue |
||||
|
* @return boolean Success or failure |
||||
|
*/ |
||||
|
public static function setAutoSizeMethod($pValue = self::AUTOSIZE_METHOD_APPROX) |
||||
|
{ |
||||
|
if (!in_array($pValue,self::$_autoSizeMethods)) { |
||||
|
return FALSE; |
||||
|
} |
||||
|
|
||||
|
self::$autoSizeMethod = $pValue; |
||||
|
|
||||
|
return TRUE; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get autoSize method |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function getAutoSizeMethod() |
||||
|
{ |
||||
|
return self::$autoSizeMethod; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set the path to the folder containing .ttf files. There should be a trailing slash. |
||||
|
* Typical locations on variout some platforms: |
||||
|
* <ul> |
||||
|
* <li>C:/Windows/Fonts/</li> |
||||
|
* <li>/usr/share/font/truetype/</li> |
||||
|
* <li>~/.font/</li> |
||||
|
* </ul> |
||||
|
* |
||||
|
* @param string $pValue |
||||
|
*/ |
||||
|
public static function setTrueTypeFontPath($pValue = '') |
||||
|
{ |
||||
|
self::$trueTypeFontPath = $pValue; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the path to the folder containing .ttf files. |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function getTrueTypeFontPath() |
||||
|
{ |
||||
|
return self::$trueTypeFontPath; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Calculate an (approximate) OpenXML column width, based on font size and text contained |
||||
|
* |
||||
|
* @param PHPExcel_Style_Font $font Font object |
||||
|
* @param PHPExcel_RichText|string $cellText Text to calculate width |
||||
|
* @param integer $rotation Rotation angle |
||||
|
* @param PHPExcel_Style_Font|NULL $defaultFont Font object |
||||
|
* @return integer Column width |
||||
|
*/ |
||||
|
public static function calculateColumnWidth(PHPExcel_Style_Font $font, $cellText = '', $rotation = 0, PHPExcel_Style_Font $defaultFont = null) { |
||||
|
|
||||
|
// If it is rich text, use plain text |
||||
|
if ($cellText instanceof PHPExcel_RichText) { |
||||
|
$cellText = $cellText->getPlainText(); |
||||
|
} |
||||
|
|
||||
|
// Special case if there are one or more newline characters ("\n") |
||||
|
if (strpos($cellText, "\n") !== false) { |
||||
|
$lineTexts = explode("\n", $cellText); |
||||
|
$lineWitdhs = array(); |
||||
|
foreach ($lineTexts as $lineText) { |
||||
|
$lineWidths[] = self::calculateColumnWidth($font, $lineText, $rotation = 0, $defaultFont); |
||||
|
} |
||||
|
return max($lineWidths); // width of longest line in cell |
||||
|
} |
||||
|
|
||||
|
// Try to get the exact text width in pixels |
||||
|
try { |
||||
|
// If autosize method is set to 'approx', use approximation |
||||
|
if (self::$autoSizeMethod == self::AUTOSIZE_METHOD_APPROX) { |
||||
|
throw new PHPExcel_Exception('AutoSize method is set to approx'); |
||||
|
} |
||||
|
|
||||
|
// Width of text in pixels excl. padding |
||||
|
$columnWidth = self::getTextWidthPixelsExact($cellText, $font, $rotation); |
||||
|
|
||||
|
// Excel adds some padding, use 1.07 of the width of an 'n' glyph |
||||
|
$columnWidth += ceil(self::getTextWidthPixelsExact('0', $font, 0) * 1.07); // pixels incl. padding |
||||
|
|
||||
|
} catch (PHPExcel_Exception $e) { |
||||
|
// Width of text in pixels excl. padding, approximation |
||||
|
$columnWidth = self::getTextWidthPixelsApprox($cellText, $font, $rotation); |
||||
|
|
||||
|
// Excel adds some padding, just use approx width of 'n' glyph |
||||
|
$columnWidth += self::getTextWidthPixelsApprox('n', $font, 0); |
||||
|
} |
||||
|
|
||||
|
// Convert from pixel width to column width |
||||
|
$columnWidth = PHPExcel_Shared_Drawing::pixelsToCellDimension($columnWidth, $defaultFont); |
||||
|
|
||||
|
// Return |
||||
|
return round($columnWidth, 6); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get GD text width in pixels for a string of text in a certain font at a certain rotation angle |
||||
|
* |
||||
|
* @param string $text |
||||
|
* @param PHPExcel_Style_Font |
||||
|
* @param int $rotation |
||||
|
* @return int |
||||
|
* @throws PHPExcel_Exception |
||||
|
*/ |
||||
|
public static function getTextWidthPixelsExact($text, PHPExcel_Style_Font $font, $rotation = 0) { |
||||
|
if (!function_exists('imagettfbbox')) { |
||||
|
throw new PHPExcel_Exception('GD library needs to be enabled'); |
||||
|
} |
||||
|
|
||||
|
// font size should really be supplied in pixels in GD2, |
||||
|
// but since GD2 seems to assume 72dpi, pixels and points are the same |
||||
|
$fontFile = self::getTrueTypeFontFileFromFont($font); |
||||
|
$textBox = imagettfbbox($font->getSize(), $rotation, $fontFile, $text); |
||||
|
|
||||
|
// Get corners positions |
||||
|
$lowerLeftCornerX = $textBox[0]; |
||||
|
$lowerLeftCornerY = $textBox[1]; |
||||
|
$lowerRightCornerX = $textBox[2]; |
||||
|
$lowerRightCornerY = $textBox[3]; |
||||
|
$upperRightCornerX = $textBox[4]; |
||||
|
$upperRightCornerY = $textBox[5]; |
||||
|
$upperLeftCornerX = $textBox[6]; |
||||
|
$upperLeftCornerY = $textBox[7]; |
||||
|
|
||||
|
// Consider the rotation when calculating the width |
||||
|
$textWidth = max($lowerRightCornerX - $upperLeftCornerX, $upperRightCornerX - $lowerLeftCornerX); |
||||
|
|
||||
|
return $textWidth; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get approximate width in pixels for a string of text in a certain font at a certain rotation angle |
||||
|
* |
||||
|
* @param string $columnText |
||||
|
* @param PHPExcel_Style_Font $font |
||||
|
* @param int $rotation |
||||
|
* @return int Text width in pixels (no padding added) |
||||
|
*/ |
||||
|
public static function getTextWidthPixelsApprox($columnText, PHPExcel_Style_Font $font = null, $rotation = 0) |
||||
|
{ |
||||
|
$fontName = $font->getName(); |
||||
|
$fontSize = $font->getSize(); |
||||
|
|
||||
|
// Calculate column width in pixels. We assume fixed glyph width. Result varies with font name and size. |
||||
|
switch ($fontName) { |
||||
|
case 'Calibri': |
||||
|
// value 8.26 was found via interpolation by inspecting real Excel files with Calibri 11 font. |
||||
|
$columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText)); |
||||
|
$columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size |
||||
|
break; |
||||
|
|
||||
|
case 'Arial': |
||||
|
// value 7 was found via interpolation by inspecting real Excel files with Arial 10 font. |
||||
|
$columnWidth = (int) (7 * PHPExcel_Shared_String::CountCharacters($columnText)); |
||||
|
$columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size |
||||
|
break; |
||||
|
|
||||
|
case 'Verdana': |
||||
|
// value 8 was found via interpolation by inspecting real Excel files with Verdana 10 font. |
||||
|
$columnWidth = (int) (8 * PHPExcel_Shared_String::CountCharacters($columnText)); |
||||
|
$columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size |
||||
|
break; |
||||
|
|
||||
|
default: |
||||
|
// just assume Calibri |
||||
|
$columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText)); |
||||
|
$columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
// Calculate approximate rotated column width |
||||
|
if ($rotation !== 0) { |
||||
|
if ($rotation == -165) { |
||||
|
// stacked text |
||||
|
$columnWidth = 4; // approximation |
||||
|
} else { |
||||
|
// rotated text |
||||
|
$columnWidth = $columnWidth * cos(deg2rad($rotation)) |
||||
|
+ $fontSize * abs(sin(deg2rad($rotation))) / 5; // approximation |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// pixel width is an integer |
||||
|
$columnWidth = (int) $columnWidth; |
||||
|
return $columnWidth; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Calculate an (approximate) pixel size, based on a font points size |
||||
|
* |
||||
|
* @param int $fontSizeInPoints Font size (in points) |
||||
|
* @return int Font size (in pixels) |
||||
|
*/ |
||||
|
public static function fontSizeToPixels($fontSizeInPoints = 11) { |
||||
|
return (int) ((4 / 3) * $fontSizeInPoints); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Calculate an (approximate) pixel size, based on inch size |
||||
|
* |
||||
|
* @param int $sizeInInch Font size (in inch) |
||||
|
* @return int Size (in pixels) |
||||
|
*/ |
||||
|
public static function inchSizeToPixels($sizeInInch = 1) { |
||||
|
return ($sizeInInch * 96); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Calculate an (approximate) pixel size, based on centimeter size |
||||
|
* |
||||
|
* @param int $sizeInCm Font size (in centimeters) |
||||
|
* @return int Size (in pixels) |
||||
|
*/ |
||||
|
public static function centimeterSizeToPixels($sizeInCm = 1) { |
||||
|
return ($sizeInCm * 37.795275591); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Returns the font path given the font |
||||
|
* |
||||
|
* @param PHPExcel_Style_Font |
||||
|
* @return string Path to TrueType font file |
||||
|
*/ |
||||
|
public static function getTrueTypeFontFileFromFont($font) { |
||||
|
if (!file_exists(self::$trueTypeFontPath) || !is_dir(self::$trueTypeFontPath)) { |
||||
|
throw new PHPExcel_Exception('Valid directory to TrueType Font files not specified'); |
||||
|
} |
||||
|
|
||||
|
$name = $font->getName(); |
||||
|
$bold = $font->getBold(); |
||||
|
$italic = $font->getItalic(); |
||||
|
|
||||
|
// Check if we can map font to true type font file |
||||
|
switch ($name) { |
||||
|
case 'Arial': |
||||
|
$fontFile = ( |
||||
|
$bold ? ($italic ? self::ARIAL_BOLD_ITALIC : self::ARIAL_BOLD) |
||||
|
: ($italic ? self::ARIAL_ITALIC : self::ARIAL) |
||||
|
); |
||||
|
break; |
||||
|
|
||||
|
case 'Calibri': |
||||
|
$fontFile = ( |
||||
|
$bold ? ($italic ? self::CALIBRI_BOLD_ITALIC : self::CALIBRI_BOLD) |
||||
|
: ($italic ? self::CALIBRI_ITALIC : self::CALIBRI) |
||||
|
); |
||||
|
break; |
||||
|
|
||||
|
case 'Courier New': |
||||
|
$fontFile = ( |
||||
|
$bold ? ($italic ? self::COURIER_NEW_BOLD_ITALIC : self::COURIER_NEW_BOLD) |
||||
|
: ($italic ? self::COURIER_NEW_ITALIC : self::COURIER_NEW) |
||||
|
); |
||||
|
break; |
||||
|
|
||||
|
case 'Comic Sans MS': |
||||
|
$fontFile = ( |
||||
|
$bold ? self::COMIC_SANS_MS_BOLD : self::COMIC_SANS_MS |
||||
|
); |
||||
|
break; |
||||
|
|
||||
|
case 'Georgia': |
||||
|
$fontFile = ( |
||||
|
$bold ? ($italic ? self::GEORGIA_BOLD_ITALIC : self::GEORGIA_BOLD) |
||||
|
: ($italic ? self::GEORGIA_ITALIC : self::GEORGIA) |
||||
|
); |
||||
|
break; |
||||
|
|
||||
|
case 'Impact': |
||||
|
$fontFile = self::IMPACT; |
||||
|
break; |
||||
|
|
||||
|
case 'Liberation Sans': |
||||
|
$fontFile = ( |
||||
|
$bold ? ($italic ? self::LIBERATION_SANS_BOLD_ITALIC : self::LIBERATION_SANS_BOLD) |
||||
|
: ($italic ? self::LIBERATION_SANS_ITALIC : self::LIBERATION_SANS) |
||||
|
); |
||||
|
break; |
||||
|
|
||||
|
case 'Lucida Console': |
||||
|
$fontFile = self::LUCIDA_CONSOLE; |
||||
|
break; |
||||
|
|
||||
|
case 'Lucida Sans Unicode': |
||||
|
$fontFile = self::LUCIDA_SANS_UNICODE; |
||||
|
break; |
||||
|
|
||||
|
case 'Microsoft Sans Serif': |
||||
|
$fontFile = self::MICROSOFT_SANS_SERIF; |
||||
|
break; |
||||
|
|
||||
|
case 'Palatino Linotype': |
||||
|
$fontFile = ( |
||||
|
$bold ? ($italic ? self::PALATINO_LINOTYPE_BOLD_ITALIC : self::PALATINO_LINOTYPE_BOLD) |
||||
|
: ($italic ? self::PALATINO_LINOTYPE_ITALIC : self::PALATINO_LINOTYPE) |
||||
|
); |
||||
|
break; |
||||
|
|
||||
|
case 'Symbol': |
||||
|
$fontFile = self::SYMBOL; |
||||
|
break; |
||||
|
|
||||
|
case 'Tahoma': |
||||
|
$fontFile = ( |
||||
|
$bold ? self::TAHOMA_BOLD : self::TAHOMA |
||||
|
); |
||||
|
break; |
||||
|
|
||||
|
case 'Times New Roman': |
||||
|
$fontFile = ( |
||||
|
$bold ? ($italic ? self::TIMES_NEW_ROMAN_BOLD_ITALIC : self::TIMES_NEW_ROMAN_BOLD) |
||||
|
: ($italic ? self::TIMES_NEW_ROMAN_ITALIC : self::TIMES_NEW_ROMAN) |
||||
|
); |
||||
|
break; |
||||
|
|
||||
|
case 'Trebuchet MS': |
||||
|
$fontFile = ( |
||||
|
$bold ? ($italic ? self::TREBUCHET_MS_BOLD_ITALIC : self::TREBUCHET_MS_BOLD) |
||||
|
: ($italic ? self::TREBUCHET_MS_ITALIC : self::TREBUCHET_MS) |
||||
|
); |
||||
|
break; |
||||
|
|
||||
|
case 'Verdana': |
||||
|
$fontFile = ( |
||||
|
$bold ? ($italic ? self::VERDANA_BOLD_ITALIC : self::VERDANA_BOLD) |
||||
|
: ($italic ? self::VERDANA_ITALIC : self::VERDANA) |
||||
|
); |
||||
|
break; |
||||
|
|
||||
|
default: |
||||
|
throw new PHPExcel_Exception('Unknown font name "'. $name .'". Cannot map to TrueType font file'); |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
$fontFile = self::$trueTypeFontPath . $fontFile; |
||||
|
|
||||
|
// Check if file actually exists |
||||
|
if (!file_exists($fontFile)) { |
||||
|
throw New PHPExcel_Exception('TrueType Font file not found'); |
||||
|
} |
||||
|
|
||||
|
return $fontFile; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Returns the associated charset for the font name. |
||||
|
* |
||||
|
* @param string $name Font name |
||||
|
* @return int Character set code |
||||
|
*/ |
||||
|
public static function getCharsetFromFontName($name) |
||||
|
{ |
||||
|
switch ($name) { |
||||
|
// Add more cases. Check FONT records in real Excel files. |
||||
|
case 'EucrosiaUPC': return self::CHARSET_ANSI_THAI; |
||||
|
case 'Wingdings': return self::CHARSET_SYMBOL; |
||||
|
case 'Wingdings 2': return self::CHARSET_SYMBOL; |
||||
|
case 'Wingdings 3': return self::CHARSET_SYMBOL; |
||||
|
default: return self::CHARSET_ANSI_LATIN; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the effective column width for columns without a column dimension or column with width -1 |
||||
|
* For example, for Calibri 11 this is 9.140625 (64 px) |
||||
|
* |
||||
|
* @param PHPExcel_Style_Font $font The workbooks default font |
||||
|
* @param boolean $pPixels true = return column width in pixels, false = return in OOXML units |
||||
|
* @return mixed Column width |
||||
|
*/ |
||||
|
public static function getDefaultColumnWidthByFont(PHPExcel_Style_Font $font, $pPixels = false) |
||||
|
{ |
||||
|
if (isset(self::$defaultColumnWidths[$font->getName()][$font->getSize()])) { |
||||
|
// Exact width can be determined |
||||
|
$columnWidth = $pPixels ? |
||||
|
self::$defaultColumnWidths[$font->getName()][$font->getSize()]['px'] |
||||
|
: self::$defaultColumnWidths[$font->getName()][$font->getSize()]['width']; |
||||
|
|
||||
|
} else { |
||||
|
// We don't have data for this particular font and size, use approximation by |
||||
|
// extrapolating from Calibri 11 |
||||
|
$columnWidth = $pPixels ? |
||||
|
self::$defaultColumnWidths['Calibri'][11]['px'] |
||||
|
: self::$defaultColumnWidths['Calibri'][11]['width']; |
||||
|
$columnWidth = $columnWidth * $font->getSize() / 11; |
||||
|
|
||||
|
// Round pixels to closest integer |
||||
|
if ($pPixels) { |
||||
|
$columnWidth = (int) round($columnWidth); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $columnWidth; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the effective row height for rows without a row dimension or rows with height -1 |
||||
|
* For example, for Calibri 11 this is 15 points |
||||
|
* |
||||
|
* @param PHPExcel_Style_Font $font The workbooks default font |
||||
|
* @return float Row height in points |
||||
|
*/ |
||||
|
public static function getDefaultRowHeightByFont(PHPExcel_Style_Font $font) |
||||
|
{ |
||||
|
switch ($font->getName()) { |
||||
|
case 'Arial': |
||||
|
switch ($font->getSize()) { |
||||
|
case 10: |
||||
|
// inspection of Arial 10 workbook says 12.75pt ~17px |
||||
|
$rowHeight = 12.75; |
||||
|
break; |
||||
|
|
||||
|
case 9: |
||||
|
// inspection of Arial 9 workbook says 12.00pt ~16px |
||||
|
$rowHeight = 12; |
||||
|
break; |
||||
|
|
||||
|
case 8: |
||||
|
// inspection of Arial 8 workbook says 11.25pt ~15px |
||||
|
$rowHeight = 11.25; |
||||
|
break; |
||||
|
|
||||
|
case 7: |
||||
|
// inspection of Arial 7 workbook says 9.00pt ~12px |
||||
|
$rowHeight = 9; |
||||
|
break; |
||||
|
|
||||
|
case 6: |
||||
|
case 5: |
||||
|
// inspection of Arial 5,6 workbook says 8.25pt ~11px |
||||
|
$rowHeight = 8.25; |
||||
|
break; |
||||
|
|
||||
|
case 4: |
||||
|
// inspection of Arial 4 workbook says 6.75pt ~9px |
||||
|
$rowHeight = 6.75; |
||||
|
break; |
||||
|
|
||||
|
case 3: |
||||
|
// inspection of Arial 3 workbook says 6.00pt ~8px |
||||
|
$rowHeight = 6; |
||||
|
break; |
||||
|
|
||||
|
case 2: |
||||
|
case 1: |
||||
|
// inspection of Arial 1,2 workbook says 5.25pt ~7px |
||||
|
$rowHeight = 5.25; |
||||
|
break; |
||||
|
|
||||
|
default: |
||||
|
// use Arial 10 workbook as an approximation, extrapolation |
||||
|
$rowHeight = 12.75 * $font->getSize() / 10; |
||||
|
break; |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
case 'Calibri': |
||||
|
switch ($font->getSize()) { |
||||
|
case 11: |
||||
|
// inspection of Calibri 11 workbook says 15.00pt ~20px |
||||
|
$rowHeight = 15; |
||||
|
break; |
||||
|
|
||||
|
case 10: |
||||
|
// inspection of Calibri 10 workbook says 12.75pt ~17px |
||||
|
$rowHeight = 12.75; |
||||
|
break; |
||||
|
|
||||
|
case 9: |
||||
|
// inspection of Calibri 9 workbook says 12.00pt ~16px |
||||
|
$rowHeight = 12; |
||||
|
break; |
||||
|
|
||||
|
case 8: |
||||
|
// inspection of Calibri 8 workbook says 11.25pt ~15px |
||||
|
$rowHeight = 11.25; |
||||
|
break; |
||||
|
|
||||
|
case 7: |
||||
|
// inspection of Calibri 7 workbook says 9.00pt ~12px |
||||
|
$rowHeight = 9; |
||||
|
break; |
||||
|
|
||||
|
case 6: |
||||
|
case 5: |
||||
|
// inspection of Calibri 5,6 workbook says 8.25pt ~11px |
||||
|
$rowHeight = 8.25; |
||||
|
break; |
||||
|
|
||||
|
case 4: |
||||
|
// inspection of Calibri 4 workbook says 6.75pt ~9px |
||||
|
$rowHeight = 6.75; |
||||
|
break; |
||||
|
|
||||
|
case 3: |
||||
|
// inspection of Calibri 3 workbook says 6.00pt ~8px |
||||
|
$rowHeight = 6.00; |
||||
|
break; |
||||
|
|
||||
|
case 2: |
||||
|
case 1: |
||||
|
// inspection of Calibri 1,2 workbook says 5.25pt ~7px |
||||
|
$rowHeight = 5.25; |
||||
|
break; |
||||
|
|
||||
|
default: |
||||
|
// use Calibri 11 workbook as an approximation, extrapolation |
||||
|
$rowHeight = 15 * $font->getSize() / 11; |
||||
|
break; |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
case 'Verdana': |
||||
|
switch ($font->getSize()) { |
||||
|
case 10: |
||||
|
// inspection of Verdana 10 workbook says 12.75pt ~17px |
||||
|
$rowHeight = 12.75; |
||||
|
break; |
||||
|
|
||||
|
case 9: |
||||
|
// inspection of Verdana 9 workbook says 11.25pt ~15px |
||||
|
$rowHeight = 11.25; |
||||
|
break; |
||||
|
|
||||
|
case 8: |
||||
|
// inspection of Verdana 8 workbook says 10.50pt ~14px |
||||
|
$rowHeight = 10.50; |
||||
|
break; |
||||
|
|
||||
|
case 7: |
||||
|
// inspection of Verdana 7 workbook says 9.00pt ~12px |
||||
|
$rowHeight = 9.00; |
||||
|
break; |
||||
|
|
||||
|
case 6: |
||||
|
case 5: |
||||
|
// inspection of Verdana 5,6 workbook says 8.25pt ~11px |
||||
|
$rowHeight = 8.25; |
||||
|
break; |
||||
|
|
||||
|
case 4: |
||||
|
// inspection of Verdana 4 workbook says 6.75pt ~9px |
||||
|
$rowHeight = 6.75; |
||||
|
break; |
||||
|
|
||||
|
case 3: |
||||
|
// inspection of Verdana 3 workbook says 6.00pt ~8px |
||||
|
$rowHeight = 6; |
||||
|
break; |
||||
|
|
||||
|
case 2: |
||||
|
case 1: |
||||
|
// inspection of Verdana 1,2 workbook says 5.25pt ~7px |
||||
|
$rowHeight = 5.25; |
||||
|
break; |
||||
|
|
||||
|
default: |
||||
|
// use Verdana 10 workbook as an approximation, extrapolation |
||||
|
$rowHeight = 12.75 * $font->getSize() / 10; |
||||
|
break; |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
default: |
||||
|
// just use Calibri as an approximation |
||||
|
$rowHeight = 15 * $font->getSize() / 11; |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
return $rowHeight; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
Mar 1, 2005 11:15 AST by PM |
||||
|
|
||||
|
+ For consistency, renamed Math.php to Maths.java, utils to util, |
||||
|
tests to test, docs to doc - |
||||
|
|
||||
|
+ Removed conditional logic from top of Matrix class. |
||||
|
|
||||
|
+ Switched to using hypo function in Maths.php for all php-hypot calls. |
||||
|
NOTE TO SELF: Need to make sure that all decompositions have been |
||||
|
switched over to using the bundled hypo. |
||||
|
|
||||
|
Feb 25, 2005 at 10:00 AST by PM |
||||
|
|
||||
|
+ Recommend using simpler Error.php instead of JAMA_Error.php but |
||||
|
can be persuaded otherwise. |
||||
|
|
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue