diff --git a/.gitignore b/.gitignore index 9768287..869f498 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -# ide related -.idea # composer related composer.lock composer.phar diff --git a/Spreadsheet/Excel/Writer.php b/Spreadsheet/Excel/Writer.php index 291b7c4..8bb710c 100644 --- a/Spreadsheet/Excel/Writer.php +++ b/Spreadsheet/Excel/Writer.php @@ -31,7 +31,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -require_once __DIR__ . '/Writer/Workbook.php'; +if (!class_exists('Spreadsheet_Excel_Writer_Workbook')) { + require_once 'Spreadsheet/Excel/Writer/Workbook.php'; +} /** * Class for writing Excel Spreadsheets. This class should change COMPLETELY. @@ -46,12 +48,13 @@ class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook /** * The constructor. It just creates a Workbook * - * @param string $fileName The optional filename for the Workbook. + * @param string $filename The optional filename for the Workbook. + * @return Spreadsheet_Excel_Writer_Workbook The Workbook created */ - public function __construct($fileName = '') + public function __construct($filename = '') { - $this->fileName = $fileName; - parent::__construct($fileName); + $this->_filename = $filename; + parent::__construct($filename); } /** @@ -62,11 +65,12 @@ class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook */ public function send($filename) { - header('Content-type: application/vnd.ms-excel'); - header('Content-Disposition: attachment; filename="' . $filename .'"'); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0,pre-check=0'); - header('Pragma: public'); + $filename = addslashes($filename); + header("Content-type: application/vnd.ms-excel"); + header("Content-Disposition: attachment; filename=\"$filename\""); + header("Expires: 0"); + header("Cache-Control: must-revalidate, post-check=0,pre-check=0"); + header("Pragma: public"); } /** @@ -76,26 +80,26 @@ class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook * @access public * @static * @param integer $row Row for the cell to convert (0-indexed). - * @param integer $column Column for the cell to convert (0-indexed). + * @param integer $col Column for the cell to convert (0-indexed). * @return string The cell identifier in A1 format */ - public function rowcolToCell($row, $column) + function rowcolToCell($row, $col) { - if ($column > 255) { //maximum column value exceeded - return new PEAR_Error('Maximum column value exceeded: ' . $column); + if ($col > 255) { //maximum column value exceeded + return new PEAR_Error("Maximum column value exceeded: $col"); } - $int = (int)($column / 26); - $frac = $column % 26; - $chr1 = ''; + $int = (int)($col / 26); + $frac = $col % 26; + $chr1 = ''; if ($int > 0) { $chr1 = chr(ord('A') + $int - 1); } $chr2 = chr(ord('A') + $frac); - ++$row; + $row++; return $chr1 . $chr2 . $row; } -} +} \ No newline at end of file diff --git a/Spreadsheet/Excel/Writer/BIFFwriter.php b/Spreadsheet/Excel/Writer/BIFFwriter.php index bf89344..cb08407 100644 --- a/Spreadsheet/Excel/Writer/BIFFwriter.php +++ b/Spreadsheet/Excel/Writer/BIFFwriter.php @@ -32,6 +32,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +if (!class_exists('PEAR')) { + require_once 'PEAR.php'; +} + /** * Class for writing Excel BIFF records. * @@ -55,44 +59,44 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR * The BIFF/Excel version (5). * @var integer */ - public $BIFF_version = 0x0500; + public $_BIFF_version = 0x0500; /** * The byte order of this architecture. 0 => little endian, 1 => big endian * @var integer */ - public $byteOrder; + public $_byte_order; /** * The string containing the data of the BIFF stream * @var string */ - public $data; + public $_data; /** - * The size of the data in bytes. Should be the same as strlen($this->data) + * The size of the data in bytes. Should be the same as strlen($this->_data) * @var integer */ - public $dataSize; + public $_datasize; /** - * The maximun length for a BIFF record. See addContinue() + * The maximun length for a BIFF record. See _addContinue() * @var integer - * @see addContinue() + * @see _addContinue() */ - public $limit; + public $_limit; /** * The temporary dir for storing the OLE file * @var string */ - public $temporaryDirectory; + public $_tmp_dir; /** * The temporary file for storing the OLE file * @var string */ - public $temporaryFile; + public $_tmp_file; /** * Constructor @@ -101,13 +105,13 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR */ public function __construct() { - $this->byteOrder = ''; - $this->data = ''; - $this->dataSize = 0; - $this->limit = 2080; - $this->temporaryDirectory = ''; + $this->_byte_order = ''; + $this->_data = ''; + $this->_datasize = 0; + $this->_limit = 2080; + $this->_tmp_dir = ''; // Set the byte order - $this->setByteOrder(); + $this->_setByteOrder(); } /** @@ -116,55 +120,51 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR * * @access private */ - protected function setByteOrder() + protected function _setByteOrder() { // Check if "pack" gives the required IEEE 64bit float - $testString = pack('d', 1.2345); - $number = pack('C8', 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F); - - if ($number == $testString) { + $teststr = pack("d", 1.2345); + $number = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F); + if ($number == $teststr) { $byte_order = 0; // Little Endian - } elseif ($number == strrev($testString)){ + } elseif ($number == strrev($teststr)){ $byte_order = 1; // Big Endian } else { // Give up. I'll fix this in a later version. - return $this->raiseError('Required floating point format ' . - 'not supported on this platform.'); + return $this->raiseError("Required floating point format ". + "not supported on this platform."); } - - $this->byteOrder = $byte_order; + $this->_byte_order = $byte_order; } /** - * General storage function + * General storage public function * * @param string $data binary data to prepend * @access private */ - protected function prepend($data) + protected function _prepend($data) { - if (strlen($data) > $this->limit) { - $data = $this->addContinue($data); + if (strlen($data) > $this->_limit) { + $data = $this->_addContinue($data); } - - $this->data = $data . $this->data; - $this->dataSize += strlen($data); + $this->_data = $data.$this->_data; + $this->_datasize += strlen($data); } /** - * General storage function + * General storage public function * * @param string $data binary data to append * @access private */ - protected function append($data) + protected function _append($data) { - if (strlen($data) > $this->limit) { - $data = $this->addContinue($data); + if (strlen($data) > $this->_limit) { + $data = $this->_addContinue($data); } - - $this->data = $this->data . $data; - $this->dataSize += strlen($data); + $this->_data = $this->_data.$data; + $this->_datasize += strlen($data); } /** @@ -175,28 +175,28 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR * 0x0010 Worksheet. * @access private */ - protected function storeBof($type) + protected function _storeBof($type) { $record = 0x0809; // Record identifier // According to the SDK $build and $year should be set to zero. // However, this throws a warning in Excel 5. So, use magic numbers. - if ($this->BIFF_version == 0x0500) { + if ($this->_BIFF_version == 0x0500) { $length = 0x0008; $unknown = ''; $build = 0x096C; $year = 0x07C9; - } elseif ($this->BIFF_version == 0x0600) { + } elseif ($this->_BIFF_version == 0x0600) { $length = 0x0010; $unknown = pack("VV", 0x00000041, 0x00000006); //unknown last 8 bytes for BIFF8 $build = 0x0DBB; $year = 0x07CC; } - $version = $this->BIFF_version; + $version = $this->_BIFF_version; - $header = pack('vv', $record, $length); - $data = pack('vvvv', $version, $type, $build, $year); - $this->prepend($header . $data . $unknown); + $header = pack("vv", $record, $length); + $data = pack("vvvv", $version, $type, $build, $year); + $this->_prepend($header . $data . $unknown); } /** @@ -204,12 +204,12 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR * * @access private */ - protected function storeEof() + protected function _storeEof() { $record = 0x000A; // Record identifier $length = 0x0000; // Number of bytes to follow - $header = pack('vv', $record, $length); - $this->append($header); + $header = pack("vv", $record, $length); + $this->_append($header); } /** @@ -217,23 +217,23 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR * Excel 97 the limit is 8228 bytes. Records that are longer than these limits * must be split up into CONTINUE blocks. * - * This function takes a long BIFF record and inserts CONTINUE records as + * This public function takes a long BIFF record and inserts CONTINUE records as * necessary. * * @param string $data The original binary data to be written * @return string A very convenient string of continue blocks * @access private */ - protected function addContinue($data) + protected function _addContinue($data) { - $limit = $this->limit; + $limit = $this->_limit; $record = 0x003C; // Record identifier // The first 2080/8224 bytes remain intact. However, we have to change // the length field of the record. - $tmp = substr($data, 0, 2).pack('v', $limit-4) . substr($data, 4, $limit - 4); + $tmp = substr($data, 0, 2).pack("v", $limit-4).substr($data, 4, $limit - 4); - $header = pack('vv', $record, $limit); // Headers for continue records + $header = pack("vv", $record, $limit); // Headers for continue records // Retrieve chunks of 2080/8224 bytes +4 for the header. $data_length = strlen($data); @@ -243,7 +243,7 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR } // Retrieve the last chunk of data - $header = pack('vv', $record, strlen($data) - $i); + $header = pack("vv", $record, strlen($data) - $i); $tmp .= $header; $tmp .= substr($data, $i, strlen($data) - $i); @@ -257,13 +257,12 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR * @param string $dir The dir to be used as temp dir * @return true if given dir is valid, false otherwise */ - protected function setTempDir($dir) + public function setTempDir($dir) { if (is_dir($dir)) { - $this->temporaryDirectory = $dir; + $this->_tmp_dir = $dir; return true; } - return false; } -} +} \ No newline at end of file diff --git a/Spreadsheet/Excel/Writer/Format.php b/Spreadsheet/Excel/Writer/Format.php index 7841471..c19d4e5 100644 --- a/Spreadsheet/Excel/Writer/Format.php +++ b/Spreadsheet/Excel/Writer/Format.php @@ -32,6 +32,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +if (!class_exists('PEAR')) { + require_once 'PEAR.php'; +} + /** * Class for generating Excel XF records (formats) * @@ -42,24 +46,18 @@ class Spreadsheet_Excel_Writer_Format extends PEAR { - /** - * The BIFF version for the workbook - * @var integer - */ - public $_BIFF_version; - - /** - * Index to the FONT record. - * @var integer - */ - public $font_index; - /** * The index given by the workbook when creating a new format. * @var integer */ public $_xf_index; + /** + * Index to the FONT record. + * @var integer + */ + public $font_index; + /** * The font name (ASCII). * @var string @@ -250,7 +248,6 @@ class Spreadsheet_Excel_Writer_Format extends PEAR * Constructor * * @access private - * @param integer $BIFF_version * @param integer $index the XF index for the format. * @param array $properties array with properties to be set on initialization. */ @@ -497,7 +494,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR /** * Returns a unique hash key for a font. - * Used by Spreadsheet_Excel_Writer_Workbook::storeAllFonts() + * Used by Spreadsheet_Excel_Writer_Workbook::_storeAllFonts() * * The elements that form the key are arranged to increase the probability of * generating a unique key. Elements that hold a large range of numbers @@ -651,9 +648,9 @@ class Spreadsheet_Excel_Writer_Format extends PEAR if (preg_match("/\d/",$location)) { return; // Ignore numbers } - + $location = strtolower($location); - + if ($location == 'left') { $this->_text_h_align = 1; } @@ -691,9 +688,9 @@ class Spreadsheet_Excel_Writer_Format extends PEAR if (preg_match("/\d/",$location)) { return; // Ignore numbers } - + $location = strtolower($location); - + if ($location == 'top') { $this->_text_v_align = 0; } @@ -1103,12 +1100,11 @@ class Spreadsheet_Excel_Writer_Format extends PEAR * Sets the font family name. * * @access public - * @param string $font_family The font family name. Possible values are: + * @param string $fontfamily The font family name. Possible values are: * 'Times New Roman', 'Arial', 'Courier'. */ public function setFontFamily($font_family) { $this->_font_name = $font_family; } -} -?> +} \ No newline at end of file diff --git a/Spreadsheet/Excel/Writer/Parser.php b/Spreadsheet/Excel/Writer/Parser.php index 3b1eda1..9182f9b 100644 --- a/Spreadsheet/Excel/Writer/Parser.php +++ b/Spreadsheet/Excel/Writer/Parser.php @@ -25,77 +25,81 @@ /** * @const SPREADSHEET_EXCEL_WRITER_ADD token identifier for character "+" */ -define('SPREADSHEET_EXCEL_WRITER_ADD', '+'); +define('SPREADSHEET_EXCEL_WRITER_ADD', "+"); /** * @const SPREADSHEET_EXCEL_WRITER_SUB token identifier for character "-" */ -define('SPREADSHEET_EXCEL_WRITER_SUB', '-'); +define('SPREADSHEET_EXCEL_WRITER_SUB', "-"); /** * @const SPREADSHEET_EXCEL_WRITER_MUL token identifier for character "*" */ -define('SPREADSHEET_EXCEL_WRITER_MUL', '*'); +define('SPREADSHEET_EXCEL_WRITER_MUL', "*"); /** * @const SPREADSHEET_EXCEL_WRITER_DIV token identifier for character "/" */ -define('SPREADSHEET_EXCEL_WRITER_DIV', '/'); +define('SPREADSHEET_EXCEL_WRITER_DIV', "/"); /** * @const SPREADSHEET_EXCEL_WRITER_OPEN token identifier for character "(" */ -define('SPREADSHEET_EXCEL_WRITER_OPEN', '('); +define('SPREADSHEET_EXCEL_WRITER_OPEN', "("); /** * @const SPREADSHEET_EXCEL_WRITER_CLOSE token identifier for character ")" */ -define('SPREADSHEET_EXCEL_WRITER_CLOSE', ')'); +define('SPREADSHEET_EXCEL_WRITER_CLOSE', ")"); /** * @const SPREADSHEET_EXCEL_WRITER_COMA token identifier for character "," */ -define('SPREADSHEET_EXCEL_WRITER_COMA', ','); +define('SPREADSHEET_EXCEL_WRITER_COMA', ","); /** * @const SPREADSHEET_EXCEL_WRITER_SEMICOLON token identifier for character ";" */ -define('SPREADSHEET_EXCEL_WRITER_SEMICOLON', ';'); +define('SPREADSHEET_EXCEL_WRITER_SEMICOLON', ";"); /** * @const SPREADSHEET_EXCEL_WRITER_GT token identifier for character ">" */ -define('SPREADSHEET_EXCEL_WRITER_GT', '>'); +define('SPREADSHEET_EXCEL_WRITER_GT', ">"); /** * @const SPREADSHEET_EXCEL_WRITER_LT token identifier for character "<" */ -define('SPREADSHEET_EXCEL_WRITER_LT', '<'); +define('SPREADSHEET_EXCEL_WRITER_LT', "<"); /** * @const SPREADSHEET_EXCEL_WRITER_LE token identifier for character "<=" */ -define('SPREADSHEET_EXCEL_WRITER_LE', '<='); +define('SPREADSHEET_EXCEL_WRITER_LE', "<="); /** * @const SPREADSHEET_EXCEL_WRITER_GE token identifier for character ">=" */ -define('SPREADSHEET_EXCEL_WRITER_GE', '>='); +define('SPREADSHEET_EXCEL_WRITER_GE', ">="); /** * @const SPREADSHEET_EXCEL_WRITER_EQ token identifier for character "=" */ -define('SPREADSHEET_EXCEL_WRITER_EQ', '='); +define('SPREADSHEET_EXCEL_WRITER_EQ', "="); /** * @const SPREADSHEET_EXCEL_WRITER_NE token identifier for character "<>" */ -define('SPREADSHEET_EXCEL_WRITER_NE', '<>'); +define('SPREADSHEET_EXCEL_WRITER_NE', "<>"); /** * * @const SPREADSHEET_EXCEL_WRITER_CONCAT token identifier for character "&" */ -define('SPREADSHEET_EXCEL_WRITER_CONCAT', '&'); +define('SPREADSHEET_EXCEL_WRITER_CONCAT', "&"); + +if (!class_exists('PEAR')) { + require_once 'PEAR.php'; +} /** * Class for parsing Excel formulas @@ -107,12 +111,6 @@ define('SPREADSHEET_EXCEL_WRITER_CONCAT', '&'); class Spreadsheet_Excel_Writer_Parser extends PEAR { - /** - * The BIFF version for the workbook - * @var integer - */ - public $_BIFF_version; - /** * The index of the character we are currently looking at * @var integer @@ -131,11 +129,6 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR */ public $_formula; - /** - * @var array - */ - public $_functions; - /** * The character ahead of the current char * @var string @@ -166,12 +159,17 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR */ public $_references; + /** + * The BIFF version for the workbook + * @var integer + */ + public $_BIFF_version; + /** * The class constructor * * @param integer $byte_order The byte order (Little endian or Big endian) of the architecture - * (optional). 1 => big endian, 0 (default) little endian. - * @param integer $biff_version + (optional). 1 => big endian, 0 (default) little endian. */ public function __construct($byte_order, $biff_version) { @@ -181,14 +179,14 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR $this->_formula = ''; // The formula to parse. $this->_lookahead = ''; // The character ahead of the current char. $this->_parse_tree = ''; // The parse tree to be generated. - $this->_initializeHashes(); // Initialize the hashes: ptg's and function's ptg's + $this->_initializeHashes(); // Initialize the hashes: ptg's and public function's ptg's $this->_byte_order = $byte_order; // Little Endian or Big Endian $this->_ext_sheets = array(); $this->_references = array(); } /** - * Initialize the ptg and function hashes. + * Initialize the ptg and public function hashes. * * @access private */ @@ -296,18 +294,18 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR // Thanks to Michael Meeks and Gnumeric for the initial arg values. // // The following hash was generated by "function_locale.pl" in the distro. - // Refer to function_locale.pl for non-English function names. + // Refer to function_locale.pl for non-English public function names. // // The array elements are as follow: - // ptg: The Excel function ptg code. - // args: The number of arguments that the function takes: + // ptg: The Excel public function ptg code. + // args: The number of arguments that the public function takes: // >=0 is a fixed number of arguments. // -1 is a variable number of arguments. - // class: The reference, value or array class of the function args. - // vol: The function is volatile. + // class: The reference, value or array class of the public function args. + // vol: The public function is volatile. // $this->_functions = array( - // function ptg args class vol + // public function ptg args class vol 'COUNT' => array( 0, -1, 0, 0 ), 'IF' => array( 1, -1, 1, 0 ), 'ISNA' => array( 2, 1, 1, 0 ), @@ -603,7 +601,6 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR * * @access private * @param mixed $num an integer or double for conversion to its ptg value - * @return string */ protected function _convertNumber($num) { @@ -643,13 +640,13 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR } /** - * Convert a function to a ptgFunc or ptgFuncVarV depending on the number of + * Convert a public function to a ptgFunc or ptgFuncVarV depending on the number of * args that it takes. * * @access private - * @param string $token The name of the function for convertion to ptg value. - * @param integer $num_args The number of arguments the function receives. - * @return string The packed ptg for the function + * @param string $token The name of the public function for convertion to ptg value. + * @param integer $num_args The number of arguments the public function receives. + * @return string The packed ptg for the public function */ protected function _convertFunction($token, $num_args) { @@ -667,13 +664,11 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR } /** - * Convert an Excel range such as A1:D4 to a ptgRefV. - * - * @access private - * @param string $range An Excel range in the A1:A2 or A1..A2 format. - * @param int $class - * @return array|string - */ + * Convert an Excel range such as A1:D4 to a ptgRefV. + * + * @access private + * @param string $range An Excel range in the A1:A2 or A1..A2 format. + */ protected function _convertRange2d($range, $class=0) { @@ -1220,7 +1215,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR default: // if it's a reference if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/',$token) and - !preg_match("/[0-9]/",$this->_lookahead) and + !preg_match("/[0-9]/",$this->_lookahead) and ($this->_lookahead != ':') and ($this->_lookahead != '.') and ($this->_lookahead != '!')) { @@ -1241,13 +1236,13 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR return $token; } // if it's a range (A1:A2) - elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token) and + elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token) and !preg_match("/[0-9]/",$this->_lookahead)) { return $token; } // if it's a range (A1..A2) - elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token) and + elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token) and !preg_match("/[0-9]/",$this->_lookahead)) { return $token; @@ -1265,7 +1260,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR return $token; } // If it's a number (check that it's not a sheet name or range) - elseif (is_numeric($token) and + elseif (is_numeric($token) and (!is_numeric($token.$this->_lookahead) or ($this->_lookahead == '')) and ($this->_lookahead != '!') and ($this->_lookahead != ':')) { @@ -1276,7 +1271,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR { return $token; } - // if it's a function call + // if it's a public function call elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$token) and ($this->_lookahead == "(")) { return $token; @@ -1422,7 +1417,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR } /** - * This function just introduces a ptgParen element in the tree, so that Excel + * This public function just introduces a ptgParen element in the tree, so that Excel * doesn't get confused when working with a parenthesized formula afterwards. * * @access private @@ -1514,7 +1509,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR return $result; } // if it's a range - elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$this->_current_token) or + elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$this->_current_token) or preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$this->_current_token)) { $result = $this->_current_token; @@ -1541,7 +1536,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR $this->_advance(); return $result; } - // if it's a function call + // if it's a public function call elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$this->_current_token)) { $result = $this->_func(); @@ -1553,7 +1548,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR } /** - * It parses a function call. It assumes the following rule: + * It parses a public function call. It assumes the following rule: * Func -> ( Expr [,Expr]* ) * * @access private @@ -1575,7 +1570,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR $this->_advance(); // eat the "," or ";" } else { return $this->raiseError("Syntax error: comma expected in ". - "function $function, arg #{$num_args}"); + "public function $function, arg #{$num_args}"); } $result2 = $this->_condition(); if (PEAR::isError($result2)) { @@ -1597,7 +1592,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR $args = $this->_functions[$function][1]; // If fixed number of args eg. TIME($i,$j,$k). Check that the number of args is valid. if (($args >= 0) and ($args != $num_args)) { - return $this->raiseError("Incorrect number of arguments in function $function() "); + return $this->raiseError("Incorrect number of arguments in public function $function() "); } $result = $this->_createTree($function, $result, $num_args); @@ -1679,14 +1674,14 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR } $polish .= $converted_tree; } - // if it's a function convert it here (so we can set it's arguments) + // if it's a public function convert it here (so we can set it's arguments) if (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/",$tree['value']) and !preg_match('/^([A-Ia-i]?[A-Za-z])(\d+)$/',$tree['value']) and !preg_match("/^[A-Ia-i]?[A-Za-z](\d+)\.\.[A-Ia-i]?[A-Za-z](\d+)$/",$tree['value']) and !is_numeric($tree['value']) and !isset($this->ptg[$tree['value']])) { - // left subtree for a function is always an array. + // left subtree for a public function is always an array. if ($tree['left'] != '') { $left_tree = $this->toReversePolish($tree['left']); } else { @@ -1706,5 +1701,4 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR $polish .= $converted_tree; return $polish; } -} -?> +} \ No newline at end of file diff --git a/Spreadsheet/Excel/Writer/Validator.php b/Spreadsheet/Excel/Writer/Validator.php index 6f97368..e2bd4cf 100644 --- a/Spreadsheet/Excel/Writer/Validator.php +++ b/Spreadsheet/Excel/Writer/Validator.php @@ -22,19 +22,21 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +//require_once('PEAR.php'); + // Possible operator types /* FIXME: change prefixes */ -define('OP_BETWEEN', 0x00); -define('OP_NOTBETWEEN', 0x01); -define('OP_EQUAL', 0x02); -define('OP_NOTEQUAL', 0x03); -define('OP_GT', 0x04); -define('OP_LT', 0x05); -define('OP_GTE', 0x06); -define('OP_LTE', 0x07); +define("OP_BETWEEN", 0x00); +define("OP_NOTBETWEEN", 0x01); +define("OP_EQUAL", 0x02); +define("OP_NOTEQUAL", 0x03); +define("OP_GT", 0x04); +define("OP_LT", 0x05); +define("OP_GTE", 0x06); +define("OP_LTE", 0x07); /** * Baseclass for generating Excel DV records (validations) @@ -148,7 +150,7 @@ class Spreadsheet_Excel_Writer_Validator return true; } - public function _getOptions() + protected function _getOptions() { $options = $this->_type; $options |= $this->_style << 3; @@ -172,7 +174,7 @@ class Spreadsheet_Excel_Writer_Validator return $options; } - public function _getData() + protected function _getData() { $title_prompt_len = strlen($this->_title_prompt); $descr_prompt_len = strlen($this->_descr_prompt); @@ -223,6 +225,4 @@ class Spreadsheet_Excel_Writer_Validator $this->_incell = $incell; //$this->_formula1 = ...; } -}*/ - -?> +}*/ \ No newline at end of file diff --git a/Spreadsheet/Excel/Writer/Workbook.php b/Spreadsheet/Excel/Writer/Workbook.php index 6d1cb9c..4c9e525 100644 --- a/Spreadsheet/Excel/Writer/Workbook.php +++ b/Spreadsheet/Excel/Writer/Workbook.php @@ -32,10 +32,20 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -require_once __DIR__ . '/Format.php'; -require_once __DIR__ . '/BIFFwriter.php'; -require_once __DIR__ . '/Worksheet.php'; -require_once __DIR__ . '/Parser.php'; +if (!class_exists('Spreadsheet_Excel_Writer_BIFFwriter')) { + require_once 'Spreadsheet/Excel/Writer/Format.php'; + require_once 'Spreadsheet/Excel/Writer/BIFFwriter.php'; + require_once 'Spreadsheet/Excel/Writer/Worksheet.php'; + require_once 'Spreadsheet/Excel/Writer/Parser.php'; +} + +if (!class_exists('OLE_PPS_Root')) { + require_once 'OLE/PPS/Root.php'; +} + +if (!class_exists('OLE_PPS_File')) { + require_once 'OLE/PPS/File.php'; +} /** * Class for generating Excel Spreadsheets @@ -51,169 +61,159 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * Filename for the Workbook * @var string */ - public $fileName; + public $_filename; /** * Formula parser * @var Spreadsheet_Excel_Writer_Parser */ - public $parser; + public $_parser; /** * Flag for 1904 date system (0 => base date is 1900, 1 => base date is 1904) * @var integer */ - public $flagFor1904; + public $_1904; /** * The active worksheet of the workbook (0 indexed) * @var integer */ - public $activeSheet; + public $_activesheet; /** * 1st displayed worksheet in the workbook (0 indexed) * @var integer */ - public $firstSheet; + public $_firstsheet; /** * Number of workbook tabs selected * @var integer */ - public $selectedWorkBook; + public $_selected; /** * Index for creating adding new formats to the workbook * @var integer */ - public $xf_index; + public $_xf_index; /** * Flag for preventing close from being called twice. * @var integer * @see close() */ - public $fileIsClosed; + public $_fileclosed; /** * The BIFF file size for the workbook. * @var integer - * @see calcSheetOffsets() + * @see _calcSheetOffsets() */ - public $biffSize; + public $_biffsize; /** * The default sheetname for all sheets created. * @var string */ - public $sheetName; + public $_sheetname; /** * The default XF format. * @var Spreadsheet_Excel_Writer_Format */ - public $temporaryFormat; + public $_tmp_format; /** * Array containing references to all of this workbook's worksheets * @var array */ - public $workSheet; + public $_worksheets; /** - * Array of sheet names for creating the EXTERNSHEET records + * Array of sheetnames for creating the EXTERNSHEET records * @var array */ - public $sheetNames; + public $_sheetnames; /** * Array containing references to all of this workbook's formats - * @var array|Spreadsheet_Excel_Writer_Format[] + * @var array */ - public $formats; + public $_formats; /** * Array containing the colour palette * @var array */ - public $palette; + public $_palette; /** * The default format for URLs. * @var Spreadsheet_Excel_Writer_Format */ - public $urlFormat; + public $_url_format; /** * The codepage indicates the text encoding used for strings * @var integer */ - public $codePage; + public $_codepage; /** * The country code used for localization * @var integer */ - public $countryCode; + public $_country_code; /** - * number of bytes for size info of strings + * number of bytes for sizeinfo of strings * @var integer */ - public $stringSizeInfoSize; + public $_string_sizeinfo_size; /** @var int */ - public $totalStringLength; - - /** @var int */ - public $uniqueString; - - /** @var array */ - public $tableOfStrings; - - /** @var int */ - public $stringSizeInfo; - - /** @var array */ - public $blockSize; + public $_timestamp; /** * Class constructor * - * @param string $fileName for storing the workbook. "-" for writing to stdout. + * @param string filename for storing the workbook. "-" for writing to stdout. * @access public */ - public function __construct($fileName) + public function __construct($filename) { // It needs to call its parent's constructor explicitly parent::__construct(); - $this->fileName = $fileName; - $this->parser = new Spreadsheet_Excel_Writer_Parser($this->byteOrder, $this->BIFF_version); - $this->flagFor1904 = 0; - $this->activeSheet = 0; - $this->firstSheet = 0; - $this->selectedWorkBook = 0; - $this->xf_index = 16; // 15 style XF's and 1 cell XF. - $this->fileIsClosed = 0; - $this->biffSize = 0; - $this->sheetName = 'Sheet'; - $this->temporaryFormat = new Spreadsheet_Excel_Writer_Format($this->BIFF_version); - $this->workSheet = array(); - $this->sheetNames = array(); - $this->formats = array(); - $this->palette = array(); - $this->codePage = 0x04E4; // FIXME: should change for BIFF8 - $this->countryCode = -1; - $this->stringSizeInfo = 3; + $this->_filename = $filename; + $this->_parser = new Spreadsheet_Excel_Writer_Parser($this->_byte_order, $this->_BIFF_version); + $this->_1904 = 0; + $this->_activesheet = 0; + $this->_firstsheet = 0; + $this->_selected = 0; + $this->_xf_index = 16; // 15 style XF's and 1 cell XF. + $this->_fileclosed = 0; + $this->_biffsize = 0; + $this->_sheetname = 'Sheet'; + $this->_tmp_format = new Spreadsheet_Excel_Writer_Format($this->_BIFF_version); + $this->_worksheets = array(); + $this->_sheetnames = array(); + $this->_formats = array(); + $this->_palette = array(); + $this->_codepage = 0x04E4; // FIXME: should change for BIFF8 + $this->_country_code = -1; + $this->_string_sizeinfo = 3; // Add the default format for hyperlinks - $this->urlFormat = $this->addFormat(array('color' => 'blue', 'underline' => 1)); - $this->totalStringLength = 0; - $this->uniqueString = 0; - $this->tableOfStrings = array(); - $this->setPaletteXl97(); + $this->_url_format = $this->addFormat(array('color' => 'blue', 'underline' => 1)); + $this->_str_total = 0; + $this->_str_unique = 0; + $this->_str_table = array(); + $this->_timestamp = time(); + + $this->_setPaletteXl97(); } /** @@ -225,23 +225,19 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri */ public function close() { - if ($this->fileIsClosed) { // Prevent close() from being called twice. + if ($this->_fileclosed) { // Prevent close() from being called twice. return true; } - - $resource = $this->storeWorkbook(); - - if ($this->isError($resource)) { - return $this->raiseError($resource->getMessage()); + $res = $this->_storeWorkbook(); + if ($this->isError($res)) { + return $this->raiseError($res->getMessage()); } - - $this->fileIsClosed = 1; - + $this->_fileclosed = 1; return true; } /** - * An accessor for the workSheet[] array + * An accessor for the _worksheets[] array * Returns an array of the worksheet objects in a workbook * It actually calls to worksheets() * @@ -255,7 +251,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri } /** - * An accessor for the workSheet[] array. + * An accessor for the _worksheets[] array. * Returns an array of the worksheet objects in a workbook * * @access public @@ -263,12 +259,12 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri */ public function worksheets() { - return $this->workSheet; + return $this->_worksheets; } /** * Sets the BIFF version. - * This method exists just to access experimental functionality + * This method exists just to access experimental public functionality * from BIFF8. It will be deprecated ! * Only possible value is 8 (Excel 97/2000). * For any other value it fails silently. @@ -280,24 +276,24 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri { if ($version == 8) { // only accept version 8 $version = 0x0600; - $this->BIFF_version = $version; + $this->_BIFF_version = $version; // change BIFFwriter limit for CONTINUE records - $this->limit = 8228; - $this->temporaryFormat->_BIFF_version = $version; - $this->urlFormat->_BIFF_version = $version; - $this->parser->_BIFF_version = $version; - $this->codePage = 0x04B0; + $this->_limit = 8228; + $this->_tmp_format->_BIFF_version = $version; + $this->_url_format->_BIFF_version = $version; + $this->_parser->_BIFF_version = $version; + $this->_codepage = 0x04B0; - $total_worksheets = count($this->workSheet); + $total_worksheets = count($this->_worksheets); // change version for all worksheets too - for ($i = 0; $i < $total_worksheets; ++$i) { - $this->workSheet[$i]->_BIFF_version = $version; + for ($i = 0; $i < $total_worksheets; $i++) { + $this->_worksheets[$i]->_BIFF_version = $version; } - $total_formats = count($this->formats); + $total_formats = count($this->_formats); // change version for all formats too - for ($i = 0; $i < $total_formats; ++$i) { - $this->formats[$i]->_BIFF_version = $version; + for ($i = 0; $i < $total_formats; $i++) { + $this->_formats[$i]->_BIFF_version = $version; } } } @@ -311,7 +307,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri */ public function setCountry($code) { - $this->countryCode = $code; + $this->_country_code = $code; } /** @@ -326,73 +322,59 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri */ public function addWorksheet($name = '') { - $index = count($this->workSheet); - $sheetName = $this->sheetName; + $index = count($this->_worksheets); + $sheetname = $this->_sheetname; if ($name == '') { - $name = $sheetName . ($index+1); + $name = $sheetname.($index+1); } // Check that sheetname is <= 31 chars (Excel limit before BIFF8). - if ($this->BIFF_version != 0x0600) { + if ($this->_BIFF_version != 0x0600) + { if (strlen($name) > 31) { - return $this->raiseError('Sheetname $name must be <= 31 chars'); + return $this->raiseError("Sheetname $name must be <= 31 chars"); } } else { - if (function_exists('iconv')) { + if(function_exists('iconv')) { $name = iconv('UTF-8','UTF-16LE',$name); } } // Check that the worksheet name doesn't already exist: a fatal Excel error. - $total_worksheets = count($this->workSheet); - - for ($i = 0; $i < $total_worksheets; ++$i) { - if ($this->workSheet[$i]->getName() == $name) { + $total_worksheets = count($this->_worksheets); + for ($i = 0; $i < $total_worksheets; $i++) { + if ($this->_worksheets[$i]->getName() == $name) { return $this->raiseError("Worksheet '$name' already exists"); } } - $worksheet = new Spreadsheet_Excel_Writer_Worksheet( - $this->BIFF_version, - $name, - $index, - $this->activeSheet, - $this->firstSheet, - $this->totalStringLength, - $this->uniqueString, - $this->tableOfStrings, - $this->urlFormat, - $this->parser, - $this->temporaryDirectory - ); - - $this->workSheet[$index] = $worksheet; // Store ref for iterator - $this->sheetNames[$index] = $name; // Store EXTERNSHEET names - $this->parser->setExtSheet($name, $index); // Register worksheet name with parser + $worksheet = new Spreadsheet_Excel_Writer_Worksheet($this->_BIFF_version, + $name, $index, + $this->_activesheet, $this->_firstsheet, + $this->_str_total, $this->_str_unique, + $this->_str_table, $this->_url_format, + $this->_parser, $this->_tmp_dir); + $this->_worksheets[$index] = $worksheet; // Store ref for iterator + $this->_sheetnames[$index] = $name; // Store EXTERNSHEET names + $this->_parser->setExtSheet($name, $index); // Register worksheet name with parser return $worksheet; } /** - * Add a new format to the Excel workbook. - * Also, pass any properties to the Format constructor. - * - * @access public - * @param array $properties array with properties for initializing the format. - * @return Spreadsheet_Excel_Writer_Format Spreadsheet_Excel_Writer_Format reference to an Excel Format - */ + * Add a new format to the Excel workbook. + * Also, pass any properties to the Format constructor. + * + * @access public + * @param array $properties array with properties for initializing the format. + * @return Spreadsheet_Excel_Writer_Format + */ public function addFormat($properties = array()) { - $format = new Spreadsheet_Excel_Writer_Format( - $this->BIFF_version, - $this->xf_index, - $properties - ); - - $this->xf_index += 1; - $this->formats[] = $format; - + $format = new Spreadsheet_Excel_Writer_Format($this->_BIFF_version, $this->_xf_index, $properties); + $this->_xf_index += 1; + $this->_formats[] = $format; return $format; } @@ -400,13 +382,15 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * Create new validator. * * @access public - * @return Spreadsheet_Excel_Writer_Validator reference to a Validator + * @return Spreadsheet_Excel_Writer_Validator */ public function addValidator() { + if (!class_exists('Spreadsheet_Excel_Writer_Validator')) { + include_once 'Spreadsheet/Excel/Writer/Validator.php'; + } /* FIXME: check for successful inclusion*/ - $valid = new Spreadsheet_Excel_Writer_Validator($this->parser); - + $valid = new Spreadsheet_Excel_Writer_Validator($this->_parser); return $valid; } @@ -430,7 +414,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // Check that the colour index is the right range if ($index < 8 or $index > 64) { // TODO: assign real error codes - return $this->raiseError('Color index $index outside range: 8 <= index <= 64'); + return $this->raiseError("Color index $index outside range: 8 <= index <= 64"); } // Check that the colour components are in the right range @@ -438,15 +422,14 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri ($green < 0 or $green > 255) || ($blue < 0 or $blue > 255)) { - return $this->raiseError('Color component outside range: 0 <= color <= 255'); + return $this->raiseError("Color component outside range: 0 <= color <= 255"); } $index -= 8; // Adjust colour index (wingless dragonfly) // Set the RGB value - $this->palette[$index] = array($red, $green, $blue, 0); - - return ($index + 8); + $this->_palette[$index] = array($red, $green, $blue, 0); + return($index + 8); } /** @@ -454,66 +437,66 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function setPaletteXl97() + protected function _setPaletteXl97() { - $this->palette = array( - array(0x00, 0x00, 0x00, 0x00), // 8 - array(0xff, 0xff, 0xff, 0x00), // 9 - array(0xff, 0x00, 0x00, 0x00), // 10 - array(0x00, 0xff, 0x00, 0x00), // 11 - array(0x00, 0x00, 0xff, 0x00), // 12 - array(0xff, 0xff, 0x00, 0x00), // 13 - array(0xff, 0x00, 0xff, 0x00), // 14 - array(0x00, 0xff, 0xff, 0x00), // 15 - array(0x80, 0x00, 0x00, 0x00), // 16 - array(0x00, 0x80, 0x00, 0x00), // 17 - array(0x00, 0x00, 0x80, 0x00), // 18 - array(0x80, 0x80, 0x00, 0x00), // 19 - array(0x80, 0x00, 0x80, 0x00), // 20 - array(0x00, 0x80, 0x80, 0x00), // 21 - array(0xc0, 0xc0, 0xc0, 0x00), // 22 - array(0x80, 0x80, 0x80, 0x00), // 23 - array(0x99, 0x99, 0xff, 0x00), // 24 - array(0x99, 0x33, 0x66, 0x00), // 25 - array(0xff, 0xff, 0xcc, 0x00), // 26 - array(0xcc, 0xff, 0xff, 0x00), // 27 - array(0x66, 0x00, 0x66, 0x00), // 28 - array(0xff, 0x80, 0x80, 0x00), // 29 - array(0x00, 0x66, 0xcc, 0x00), // 30 - array(0xcc, 0xcc, 0xff, 0x00), // 31 - array(0x00, 0x00, 0x80, 0x00), // 32 - array(0xff, 0x00, 0xff, 0x00), // 33 - array(0xff, 0xff, 0x00, 0x00), // 34 - array(0x00, 0xff, 0xff, 0x00), // 35 - array(0x80, 0x00, 0x80, 0x00), // 36 - array(0x80, 0x00, 0x00, 0x00), // 37 - array(0x00, 0x80, 0x80, 0x00), // 38 - array(0x00, 0x00, 0xff, 0x00), // 39 - array(0x00, 0xcc, 0xff, 0x00), // 40 - array(0xcc, 0xff, 0xff, 0x00), // 41 - array(0xcc, 0xff, 0xcc, 0x00), // 42 - array(0xff, 0xff, 0x99, 0x00), // 43 - array(0x99, 0xcc, 0xff, 0x00), // 44 - array(0xff, 0x99, 0xcc, 0x00), // 45 - array(0xcc, 0x99, 0xff, 0x00), // 46 - array(0xff, 0xcc, 0x99, 0x00), // 47 - array(0x33, 0x66, 0xff, 0x00), // 48 - array(0x33, 0xcc, 0xcc, 0x00), // 49 - array(0x99, 0xcc, 0x00, 0x00), // 50 - array(0xff, 0xcc, 0x00, 0x00), // 51 - array(0xff, 0x99, 0x00, 0x00), // 52 - array(0xff, 0x66, 0x00, 0x00), // 53 - array(0x66, 0x66, 0x99, 0x00), // 54 - array(0x96, 0x96, 0x96, 0x00), // 55 - array(0x00, 0x33, 0x66, 0x00), // 56 - array(0x33, 0x99, 0x66, 0x00), // 57 - array(0x00, 0x33, 0x00, 0x00), // 58 - array(0x33, 0x33, 0x00, 0x00), // 59 - array(0x99, 0x33, 0x00, 0x00), // 60 - array(0x99, 0x33, 0x66, 0x00), // 61 - array(0x33, 0x33, 0x99, 0x00), // 62 - array(0x33, 0x33, 0x33, 0x00), // 63 - ); + $this->_palette = array( + array(0x00, 0x00, 0x00, 0x00), // 8 + array(0xff, 0xff, 0xff, 0x00), // 9 + array(0xff, 0x00, 0x00, 0x00), // 10 + array(0x00, 0xff, 0x00, 0x00), // 11 + array(0x00, 0x00, 0xff, 0x00), // 12 + array(0xff, 0xff, 0x00, 0x00), // 13 + array(0xff, 0x00, 0xff, 0x00), // 14 + array(0x00, 0xff, 0xff, 0x00), // 15 + array(0x80, 0x00, 0x00, 0x00), // 16 + array(0x00, 0x80, 0x00, 0x00), // 17 + array(0x00, 0x00, 0x80, 0x00), // 18 + array(0x80, 0x80, 0x00, 0x00), // 19 + array(0x80, 0x00, 0x80, 0x00), // 20 + array(0x00, 0x80, 0x80, 0x00), // 21 + array(0xc0, 0xc0, 0xc0, 0x00), // 22 + array(0x80, 0x80, 0x80, 0x00), // 23 + array(0x99, 0x99, 0xff, 0x00), // 24 + array(0x99, 0x33, 0x66, 0x00), // 25 + array(0xff, 0xff, 0xcc, 0x00), // 26 + array(0xcc, 0xff, 0xff, 0x00), // 27 + array(0x66, 0x00, 0x66, 0x00), // 28 + array(0xff, 0x80, 0x80, 0x00), // 29 + array(0x00, 0x66, 0xcc, 0x00), // 30 + array(0xcc, 0xcc, 0xff, 0x00), // 31 + array(0x00, 0x00, 0x80, 0x00), // 32 + array(0xff, 0x00, 0xff, 0x00), // 33 + array(0xff, 0xff, 0x00, 0x00), // 34 + array(0x00, 0xff, 0xff, 0x00), // 35 + array(0x80, 0x00, 0x80, 0x00), // 36 + array(0x80, 0x00, 0x00, 0x00), // 37 + array(0x00, 0x80, 0x80, 0x00), // 38 + array(0x00, 0x00, 0xff, 0x00), // 39 + array(0x00, 0xcc, 0xff, 0x00), // 40 + array(0xcc, 0xff, 0xff, 0x00), // 41 + array(0xcc, 0xff, 0xcc, 0x00), // 42 + array(0xff, 0xff, 0x99, 0x00), // 43 + array(0x99, 0xcc, 0xff, 0x00), // 44 + array(0xff, 0x99, 0xcc, 0x00), // 45 + array(0xcc, 0x99, 0xff, 0x00), // 46 + array(0xff, 0xcc, 0x99, 0x00), // 47 + array(0x33, 0x66, 0xff, 0x00), // 48 + array(0x33, 0xcc, 0xcc, 0x00), // 49 + array(0x99, 0xcc, 0x00, 0x00), // 50 + array(0xff, 0xcc, 0x00, 0x00), // 51 + array(0xff, 0x99, 0x00, 0x00), // 52 + array(0xff, 0x66, 0x00, 0x00), // 53 + array(0x66, 0x66, 0x99, 0x00), // 54 + array(0x96, 0x96, 0x96, 0x00), // 55 + array(0x00, 0x33, 0x66, 0x00), // 56 + array(0x33, 0x99, 0x66, 0x00), // 57 + array(0x00, 0x33, 0x00, 0x00), // 58 + array(0x33, 0x33, 0x00, 0x00), // 59 + array(0x99, 0x33, 0x00, 0x00), // 60 + array(0x99, 0x33, 0x66, 0x00), // 61 + array(0x33, 0x33, 0x99, 0x00), // 62 + array(0x33, 0x33, 0x33, 0x00), // 63 + ); } /** @@ -523,82 +506,73 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * @access private * @return mixed true on success. PEAR_Error on failure */ - protected function storeWorkbook() + protected function _storeWorkbook() { - if (count($this->workSheet) == 0) { + if (count($this->_worksheets) == 0) { return true; } // Ensure that at least one worksheet has been selected. - if ($this->activeSheet == 0) { - $this->workSheet[0]->selected = 1; + if ($this->_activesheet == 0) { + $this->_worksheets[0]->selected = 1; } // Calculate the number of selected worksheet tabs and call the finalization // methods for each worksheet - $totalNumberOfWorkSheets = count($this->workSheet); - - for ($i = 0; $i < $totalNumberOfWorkSheets; ++$i) { - if ($this->workSheet[$i]->selected) { - ++$this->selectedWorkBook; + $total_worksheets = count($this->_worksheets); + for ($i = 0; $i < $total_worksheets; $i++) { + if ($this->_worksheets[$i]->selected) { + $this->_selected++; } - - $this->workSheet[$i]->close($this->sheetNames); + $this->_worksheets[$i]->close($this->_sheetnames); } // Add Workbook globals - $this->storeBof(0x0005); - $this->storeCodepage(); - - if ($this->BIFF_version == 0x0600) { - $this->storeWindow1(); + $this->_storeBof(0x0005); + $this->_storeCodepage(); + if ($this->_BIFF_version == 0x0600) { + $this->_storeWindow1(); } - - if ($this->BIFF_version == 0x0500) { - $this->storeExterns(); // For print area and repeat rows + if ($this->_BIFF_version == 0x0500) { + $this->_storeExterns(); // For print area and repeat rows } - - $this->storeNames(); // For print area and repeat rows - - if ($this->BIFF_version == 0x0500) { - $this->storeWindow1(); + $this->_storeNames(); // For print area and repeat rows + if ($this->_BIFF_version == 0x0500) { + $this->_storeWindow1(); } - - $this->storeDatemode(); - $this->storeAllFonts(); - $this->storeAllNumFormats(); - $this->storeAllXfs(); - $this->storeAllStyles(); - $this->storePalette(); - $this->calcSheetOffsets(); + $this->_storeDatemode(); + $this->_storeAllFonts(); + $this->_storeAllNumFormats(); + $this->_storeAllXfs(); + $this->_storeAllStyles(); + $this->_storePalette(); + $this->_calcSheetOffsets(); // Add BOUNDSHEET records - for ($i = 0; $i < $totalNumberOfWorkSheets; ++$i) { - $this->storeBoundsheet($this->workSheet[$i]->name,$this->workSheet[$i]->offset); + for ($i = 0; $i < $total_worksheets; $i++) { + $this->_storeBoundsheet($this->_worksheets[$i]->name,$this->_worksheets[$i]->offset); } - if ($this->countryCode != -1) { - $this->storeCountry(); + if ($this->_country_code != -1) { + $this->_storeCountry(); } - if ($this->BIFF_version == 0x0600) { - //$this->storeSupbookInternal(); + if ($this->_BIFF_version == 0x0600) { + //$this->_storeSupbookInternal(); /* TODO: store external SUPBOOK records and XCT and CRN records in case of external references for BIFF8 */ - //$this->storeExternsheetBiff8(); - $this->storeSharedStringsTable(); + //$this->_storeExternsheetBiff8(); + $this->_storeSharedStringsTable(); } // End Workbook globals - $this->storeEof(); + $this->_storeEof(); // Store the workbook in an OLE container - $res = $this->storeOLEFile(); - + $res = $this->_storeOLEFile(); if ($this->isError($res)) { return $this->raiseError($res->getMessage()); } - return true; } @@ -608,46 +582,38 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * @access private * @return mixed true on success. PEAR_Error on failure */ - protected function storeOLEFile() + protected function _storeOLEFile() { - if ($this->BIFF_version == 0x0600) { + if($this->_BIFF_version == 0x0600) { $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Workbook')); } else { $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Book')); } - - if ($this->temporaryDirectory != '') { - $OLE->setTempDir($this->temporaryDirectory); + if ($this->_tmp_dir != '') { + $OLE->setTempDir($this->_tmp_dir); } - $res = $OLE->init(); - if ($this->isError($res)) { - return $this->raiseError('OLE Error: ' . $res->getMessage()); + return $this->raiseError("OLE Error: ".$res->getMessage()); } + $OLE->append($this->_data); - $OLE->append($this->data); - - $total_worksheets = count($this->workSheet); - - for ($i = 0; $i < $total_worksheets; ++$i) { - while ($tmp = $this->workSheet[$i]->getData()) { + $total_worksheets = count($this->_worksheets); + for ($i = 0; $i < $total_worksheets; $i++) { + while ($tmp = $this->_worksheets[$i]->getData()) { $OLE->append($tmp); } } - $root = new OLE_PPS_Root(time(), time(), array($OLE)); - - if ($this->temporaryDirectory != '') { - $root->setTempDir($this->temporaryDirectory); + $root = new OLE_PPS_Root($this->_timestamp, $this->_timestamp, array($OLE)); + if ($this->_tmp_dir != '') { + $root->setTempDir($this->_tmp_dir); } - $res = $root->save($this->fileName); - + $res = $root->save($this->_filename); if ($this->isError($res)) { - return $this->raiseError('OLE Error: ' . $res->getMessage()); + return $this->raiseError("OLE Error: ".$res->getMessage()); } - return true; } @@ -656,42 +622,38 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function calcSheetOffsets() + protected function _calcSheetOffsets() { - if ($this->BIFF_version == 0x0600) { - $lengthOfTheBoundSheet = 12; // fixed length for a BOUNDSHEET record + if ($this->_BIFF_version == 0x0600) { + $boundsheet_length = 12; // fixed length for a BOUNDSHEET record } else { - $lengthOfTheBoundSheet = 11; + $boundsheet_length = 11; } + $EOF = 4; + $offset = $this->_datasize; - $EOF = 4; - $offset = $this->dataSize; - - if ($this->BIFF_version == 0x0600) { + if ($this->_BIFF_version == 0x0600) { // add the length of the SST /* TODO: check this works for a lot of strings (> 8224 bytes) */ - $offset += $this->calculateSharedStringsSizes(); - - if ($this->countryCode != -1) { + $offset += $this->_calculateSharedStringsSizes(); + if ($this->_country_code != -1) { $offset += 8; // adding COUNTRY record } // add the lenght of SUPBOOK, EXTERNSHEET and NAME records //$offset += 8; // FIXME: calculate real value when storing the records } - $totalNumberOfWorkSheets = count($this->workSheet); + $total_worksheets = count($this->_worksheets); // add the length of the BOUNDSHEET records - - for ($i = 0; $i < $totalNumberOfWorkSheets; ++$i) { - $offset += $lengthOfTheBoundSheet + strlen($this->workSheet[$i]->name); + for ($i = 0; $i < $total_worksheets; $i++) { + $offset += $boundsheet_length + strlen($this->_worksheets[$i]->name); } $offset += $EOF; - for ($i = 0; $i < $totalNumberOfWorkSheets; ++$i) { - $this->workSheet[$i]->offset = $offset; - $offset += $this->workSheet[$i]->_datasize; + for ($i = 0; $i < $total_worksheets; $i++) { + $this->_worksheets[$i]->offset = $offset; + $offset += $this->_worksheets[$i]->_datasize; } - - $this->biffSize = $offset; + $this->_biffsize = $offset; } /** @@ -699,17 +661,17 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function storeAllFonts() + protected function _storeAllFonts() { // tmp_format is added by the constructor. We use this to write the default XF's - $format = $this->temporaryFormat; + $format = $this->_tmp_format; $font = $format->getFont(); // Note: Fonts are 0-indexed. According to the SDK there is no index 4, // so the following fonts are 0, 1, 2, 3, 5 // for ($i = 1; $i <= 5; $i++){ - $this->append($font); + $this->_append($font); } // Iterate through the XF objects and write a FONT record if it isn't the @@ -718,24 +680,22 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $fonts = array(); $index = 6; // The first user defined FONT - $key = $format->getFontKey(); // The default font from temporaryFormat + $key = $format->getFontKey(); // The default font from _tmp_format $fonts[$key] = 0; // Index of the default font - $totalNumberOfFormats = count($this->formats); - - for ($i = 0; $i < $totalNumberOfFormats; ++$i) { - $key = $this->formats[$i]->getFontKey(); - + $total_formats = count($this->_formats); + for ($i = 0; $i < $total_formats; $i++) { + $key = $this->_formats[$i]->getFontKey(); if (isset($fonts[$key])) { // FONT has already been used - $this->formats[$i]->font_index = $fonts[$key]; + $this->_formats[$i]->font_index = $fonts[$key]; } else { // Add a new FONT record $fonts[$key] = $index; - $this->formats[$i]->font_index = $index; - ++$index; - $font = $this->formats[$i]->getFont(); - $this->append($font); + $this->_formats[$i]->font_index = $index; + $index++; + $font = $this->_formats[$i]->getFont(); + $this->_append($font); } } } @@ -745,48 +705,46 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function storeAllNumFormats() + protected function _storeAllNumFormats() { // Leaning num_format syndrome - $index = 164; - $numberFormatHashes = array(); - $numberFormats = array(); + $hash_num_formats = array(); + $num_formats = array(); + $index = 164; // Iterate through the XF objects and write a FORMAT record if it isn't a // built-in format type and if the FORMAT string hasn't already been used. - $total_formats = count($this->formats); - - for ($i = 0; $i < $total_formats; ++$i) { - $numberFormat = $this->formats[$i]->_num_format; + $total_formats = count($this->_formats); + for ($i = 0; $i < $total_formats; $i++) { + $num_format = $this->_formats[$i]->_num_format; // Check if $num_format is an index to a built-in format. // Also check for a string of zeros, which is a valid format string // but would evaluate to zero. // - //@todo check if we can saftly replace >>"<< with >>'<< - if (!preg_match("/^0+\d/", $numberFormat)) { - if (preg_match("/^\d+$/", $numberFormat)) { // built-in format + if (!preg_match("/^0+\d/", $num_format)) { + if (preg_match("/^\d+$/", $num_format)) { // built-in format continue; } } - if (isset($numberFormatHashes[$numberFormat])) { + if (isset($hash_num_formats[$num_format])) { // FORMAT has already been used - $this->formats[$i]->_num_format = $numberFormatHashes[$numberFormat]; + $this->_formats[$i]->_num_format = $hash_num_formats[$num_format]; } else{ // Add a new FORMAT - $numberFormatHashes[$numberFormat] = $index; - $this->formats[$i]->_num_format = $index; - array_push($numberFormats,$numberFormat); - ++$index; + $hash_num_formats[$num_format] = $index; + $this->_formats[$i]->_num_format = $index; + array_push($num_formats,$num_format); + $index++; } } // Write the new FORMAT records starting from 0xA4 $index = 164; - foreach ($numberFormats as $numberFormat) { - $this->storeNumFormat($numberFormat,$index); - ++$index; + foreach ($num_formats as $num_format) { + $this->_storeNumFormat($num_format,$index); + $index++; } } @@ -795,26 +753,25 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - public function storeAllXfs() + protected function _storeAllXfs() { - // temporaryFormat is added by the constructor. We use this to write the default XF's + // _tmp_format is added by the constructor. We use this to write the default XF's // The default font index is 0 // - $format = $this->temporaryFormat; - - for ($i = 0; $i <= 14; ++$i) { + $format = $this->_tmp_format; + for ($i = 0; $i <= 14; $i++) { $xf = $format->getXf('style'); // Style XF - $this->append($xf); + $this->_append($xf); } $xf = $format->getXf('cell'); // Cell XF - $this->append($xf); + $this->_append($xf); // User defined XFs - $total_formats = count($this->formats); - for ($i = 0; $i < $total_formats; ++$i) { - $xf = $this->formats[$i]->getXf('cell'); - $this->append($xf); + $total_formats = count($this->_formats); + for ($i = 0; $i < $total_formats; $i++) { + $xf = $this->_formats[$i]->getXf('cell'); + $this->_append($xf); } } @@ -823,9 +780,9 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function storeAllStyles() + protected function _storeAllStyles() { - $this->storeStyle(); + $this->_storeStyle(); } /** @@ -834,14 +791,15 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function storeExterns() + protected function _storeExterns() + { // Create EXTERNCOUNT with number of worksheets - $this->storeExterncount(count($this->workSheet)); + $this->_storeExterncount(count($this->_worksheets)); // Create EXTERNSHEET for each worksheet - foreach ($this->sheetNames as $sheetname) { - $this->storeExternsheet($sheetname); + foreach ($this->_sheetnames as $sheetname) { + $this->_storeExternsheet($sheetname); } } @@ -850,33 +808,31 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function storeNames() + protected function _storeNames() { // Create the print area NAME records - $total_worksheets = count($this->workSheet); - - for ($i = 0; $i < $total_worksheets; ++$i) { + $total_worksheets = count($this->_worksheets); + for ($i = 0; $i < $total_worksheets; $i++) { // Write a Name record if the print area has been defined - if (isset($this->workSheet[$i]->print_rowmin)) { - $this->storeNameShort( - $this->workSheet[$i]->index, + if (isset($this->_worksheets[$i]->print_rowmin)) { + $this->_storeNameShort( + $this->_worksheets[$i]->index, 0x06, // NAME type - $this->workSheet[$i]->print_rowmin, - $this->workSheet[$i]->print_rowmax, - $this->workSheet[$i]->print_colmin, - $this->workSheet[$i]->print_colmax + $this->_worksheets[$i]->print_rowmin, + $this->_worksheets[$i]->print_rowmax, + $this->_worksheets[$i]->print_colmin, + $this->_worksheets[$i]->print_colmax ); } } // Create the print title NAME records - $total_worksheets = count($this->workSheet); - - for ($i = 0; $i < $total_worksheets; ++$i) { - $rowmin = $this->workSheet[$i]->title_rowmin; - $rowmax = $this->workSheet[$i]->title_rowmax; - $colmin = $this->workSheet[$i]->title_colmin; - $colmax = $this->workSheet[$i]->title_colmax; + $total_worksheets = count($this->_worksheets); + for ($i = 0; $i < $total_worksheets; $i++) { + $rowmin = $this->_worksheets[$i]->title_rowmin; + $rowmax = $this->_worksheets[$i]->title_rowmax; + $colmin = $this->_worksheets[$i]->title_colmin; + $colmax = $this->_worksheets[$i]->title_colmax; // Determine if row + col, row, col or nothing has been defined // and write the appropriate record @@ -884,8 +840,8 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri if (isset($rowmin) && isset($colmin)) { // Row and column titles have been defined. // Row title has been defined. - $this->storeNameLong( - $this->workSheet[$i]->index, + $this->_storeNameLong( + $this->_worksheets[$i]->index, 0x07, // NAME type $rowmin, $rowmax, @@ -894,8 +850,8 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri ); } elseif (isset($rowmin)) { // Row title has been defined. - $this->storeNameShort( - $this->workSheet[$i]->index, + $this->_storeNameShort( + $this->_worksheets[$i]->index, 0x07, // NAME type $rowmin, $rowmax, @@ -904,8 +860,8 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri ); } elseif (isset($colmin)) { // Column title has been defined. - $this->storeNameShort( - $this->workSheet[$i]->index, + $this->_storeNameShort( + $this->_worksheets[$i]->index, 0x07, // NAME type 0x0000, 0x3fff, @@ -932,16 +888,16 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function storeCodepage() + protected function _storeCodepage() { $record = 0x0042; // Record identifier $length = 0x0002; // Number of bytes to follow - $cv = $this->codePage; // The code page + $cv = $this->_codepage; // The code page $header = pack('vv', $record, $length); $data = pack('v', $cv); - $this->append($header . $data); + $this->_append($header . $data); } /** @@ -949,7 +905,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function storeWindow1() + protected function _storeWindow1() { $record = 0x003D; // Record identifier $length = 0x0012; // Number of bytes to follow @@ -960,55 +916,51 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $dyWn = 0x1572; // Height of window $grbit = 0x0038; // Option flags - $ctabsel = $this->selectedWorkBook; // Number of workbook tabs selected + $ctabsel = $this->_selected; // Number of workbook tabs selected $wTabRatio = 0x0258; // Tab to scrollbar ratio - $itabFirst = $this->firstSheet; // 1st displayed worksheet - $itabCur = $this->activeSheet; // Active worksheet + $itabFirst = $this->_firstsheet; // 1st displayed worksheet + $itabCur = $this->_activesheet; // Active worksheet - $header = pack('vv', $record, $length); - $data = pack('vvvvvvvvv', $xWn, $yWn, $dxWn, $dyWn, + $header = pack("vv", $record, $length); + $data = pack("vvvvvvvvv", $xWn, $yWn, $dxWn, $dyWn, $grbit, $itabCur, $itabFirst, $ctabsel, $wTabRatio); - $this->append($header . $data); + $this->_append($header . $data); } /** * Writes Excel BIFF BOUNDSHEET record. * FIXME: inconsistent with BIFF documentation * - * @param string $sheetName Worksheet name + * @param string $sheetname Worksheet name * @param integer $offset Location of worksheet BOF * @access private */ - protected function storeBoundsheet($sheetName, $offset) + protected function _storeBoundsheet($sheetname,$offset) { - $record = 0x0085; // Record identifier - - if ($this->BIFF_version == 0x0600) { - $length = 0x08 + strlen($sheetName); // Number of bytes to follow + $record = 0x0085; // Record identifier + if ($this->_BIFF_version == 0x0600) { + $length = 0x08 + strlen($sheetname); // Number of bytes to follow } else { - $length = 0x07 + strlen($sheetName); // Number of bytes to follow + $length = 0x07 + strlen($sheetname); // Number of bytes to follow } - $grbit = 0x0000; // Visibility and sheet type - - if ($this->BIFF_version == 0x0600) { - $cch = mb_strlen($sheetName,'UTF-16LE'); // Length of sheet name + $grbit = 0x0000; // Visibility and sheet type + if ($this->_BIFF_version == 0x0600) { + $cch = mb_strlen($sheetname,'UTF-16LE'); // Length of sheet name } else { - $cch = strlen($sheetName); // Length of sheet name + $cch = strlen($sheetname); // Length of sheet name } - $header = pack('vv', $record, $length); - - if ($this->BIFF_version == 0x0600) { - $data = pack('VvCC', $offset, $grbit, $cch, 0x1); + $header = pack("vv", $record, $length); + if ($this->_BIFF_version == 0x0600) { + $data = pack("VvCC", $offset, $grbit, $cch, 0x1); } else { - $data = pack('VvC', $offset, $grbit, $cch); + $data = pack("VvC", $offset, $grbit, $cch); } - - $this->append($header . $data . $sheetName); + $this->_append($header.$data.$sheetname); } /** @@ -1016,14 +968,14 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function storeSupbookInternal() + protected function _storeSupbookInternal() { $record = 0x01AE; // Record identifier $length = 0x0004; // Bytes to follow - $header = pack('vv', $record, $length); - $data = pack('vv', count($this->workSheet), 0x0104); - $this->append($header . $data); + $header = pack("vv", $record, $length); + $data = pack("vv", count($this->_worksheets), 0x0104); + $this->_append($header . $data); } /** @@ -1033,19 +985,19 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * @param string $sheetname Worksheet name * @access private */ - protected function storeExternsheetBiff8() + protected function _storeExternsheetBiff8() { - $total_references = count($this->parser->_references); - $record = 0x0017; // Record identifier - $length = 2 + 6 * $total_references; // Number of bytes to follow - $header = pack('vv', $record, $length); - $data = pack('v', $total_references); + $total_references = count($this->_parser->_references); + $record = 0x0017; // Record identifier + $length = 2 + 6 * $total_references; // Number of bytes to follow - for ($i = 0; $i < $total_references; ++$i) { - $data .= $this->parser->_references[$i]; + $supbook_index = 0; // FIXME: only using internal SUPBOOK record + $header = pack("vv", $record, $length); + $data = pack('v', $total_references); + for ($i = 0; $i < $total_references; $i++) { + $data .= $this->_parser->_references[$i]; } - - $this->append($header . $data); + $this->_append($header . $data); } /** @@ -1053,7 +1005,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function storeStyle() + protected function _storeStyle() { $record = 0x0293; // Record identifier $length = 0x0004; // Bytes to follow @@ -1062,9 +1014,9 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $BuiltIn = 0x00; // Built-in style $iLevel = 0xff; // Outline style level - $header = pack('vv', $record, $length); - $data = pack('vCC', $ixfe, $BuiltIn, $iLevel); - $this->append($header . $data); + $header = pack("vv", $record, $length); + $data = pack("vCC", $ixfe, $BuiltIn, $iLevel); + $this->_append($header . $data); } @@ -1075,18 +1027,18 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * @param integer $ifmt Format index code * @access private */ - protected function storeNumFormat($format, $ifmt) + protected function _storeNumFormat($format, $ifmt) { $record = 0x041E; // Record identifier - if ($this->BIFF_version == 0x0600) { + if ($this->_BIFF_version == 0x0600) { $length = 5 + strlen($format); // Number of bytes to follow $encoding = 0x0; - } elseif ($this->BIFF_version == 0x0500) { + } elseif ($this->_BIFF_version == 0x0500) { $length = 3 + strlen($format); // Number of bytes to follow } - if ( $this->BIFF_version == 0x0600 && function_exists('iconv') ) { // Encode format String + if ( $this->_BIFF_version == 0x0600 && function_exists('iconv') ) { // Encode format String if (mb_detect_encoding($format, 'auto') !== 'UTF-16LE'){ $format = iconv(mb_detect_encoding($format, 'auto'),'UTF-16LE',$format); } @@ -1098,14 +1050,14 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri } $length = strlen($format); - if ($this->BIFF_version == 0x0600) { - $header = pack('vv', $record, 5 + $length); - $data = pack('vvC', $ifmt, $cch, $encoding); - } elseif ($this->BIFF_version == 0x0500) { - $header = pack('vv', $record, 3 + $length); - $data = pack('vC', $ifmt, $cch); + if ($this->_BIFF_version == 0x0600) { + $header = pack("vv", $record, 5 + $length); + $data = pack("vvC", $ifmt, $cch, $encoding); + } elseif ($this->_BIFF_version == 0x0500) { + $header = pack("vv", $record, 3 + $length); + $data = pack("vC", $ifmt, $cch); } - $this->append($header . $data . $format); + $this->_append($header . $data . $format); } /** @@ -1113,16 +1065,16 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function storeDatemode() + protected function _storeDatemode() { $record = 0x0022; // Record identifier $length = 0x0002; // Bytes to follow - $f1904 = $this->flagFor1904; // Flag for 1904 date system + $f1904 = $this->_1904; // Flag for 1904 date system - $header = pack('vv', $record, $length); - $data = pack('v', $f1904); - $this->append($header . $data); + $header = pack("vv", $record, $length); + $data = pack("v", $f1904); + $this->_append($header . $data); } @@ -1139,14 +1091,14 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * @param integer $cxals Number of external references * @access private */ - protected function storeExterncount($cxals) + protected function _storeExterncount($cxals) { $record = 0x0016; // Record identifier $length = 0x0002; // Number of bytes to follow - $header = pack('vv', $record, $length); - $data = pack('v', $cxals); - $this->append($header . $data); + $header = pack("vv", $record, $length); + $data = pack("v", $cxals); + $this->_append($header . $data); } @@ -1157,20 +1109,20 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * A similar method is used in Worksheet.php for a slightly different purpose. * - * @param string $sheetName Worksheet name + * @param string $sheetname Worksheet name * @access private */ - protected function storeExternsheet($sheetName) + protected function _storeExternsheet($sheetname) { $record = 0x0017; // Record identifier - $length = 0x02 + strlen($sheetName); // Number of bytes to follow + $length = 0x02 + strlen($sheetname); // Number of bytes to follow - $cch = strlen($sheetName); // Length of sheet name + $cch = strlen($sheetname); // Length of sheet name $rgch = 0x03; // Filename encoding - $header = pack('vv', $record, $length); - $data = pack('CC', $cch, $rgch); - $this->append($header . $data . $sheetName); + $header = pack("vv", $record, $length); + $data = pack("CC", $cch, $rgch); + $this->_append($header . $data . $sheetname); } @@ -1186,7 +1138,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * @param integer $colmax End column * @access private */ - protected function storeNameShort($index, $type, $rowmin, $rowmax, $colmin, $colmax) + protected function _storeNameShort($index, $type, $rowmin, $rowmax, $colmin, $colmax) { $record = 0x0018; // Record identifier $length = 0x0024; // Number of bytes to follow @@ -1210,38 +1162,38 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $unknown07 = 0x1087; $unknown08 = 0x8005; - $header = pack('vv', $record, $length); - $data = pack('v', $grbit); - $data .= pack('C', $chKey); - $data .= pack('C', $cch); - $data .= pack('v', $cce); - $data .= pack('v', $ixals); - $data .= pack('v', $itab); - $data .= pack('C', $cchCustMenu); - $data .= pack('C', $cchDescription); - $data .= pack('C', $cchHelptopic); - $data .= pack('C', $cchStatustext); - $data .= pack('C', $rgch); - $data .= pack('C', $unknown03); - $data .= pack('v', $unknown04); - $data .= pack('v', $unknown05); - $data .= pack('v', $unknown06); - $data .= pack('v', $unknown07); - $data .= pack('v', $unknown08); - $data .= pack('v', $index); - $data .= pack('v', $index); - $data .= pack('v', $rowmin); - $data .= pack('v', $rowmax); - $data .= pack('C', $colmin); - $data .= pack('C', $colmax); - $this->append($header . $data); + $header = pack("vv", $record, $length); + $data = pack("v", $grbit); + $data .= pack("C", $chKey); + $data .= pack("C", $cch); + $data .= pack("v", $cce); + $data .= pack("v", $ixals); + $data .= pack("v", $itab); + $data .= pack("C", $cchCustMenu); + $data .= pack("C", $cchDescription); + $data .= pack("C", $cchHelptopic); + $data .= pack("C", $cchStatustext); + $data .= pack("C", $rgch); + $data .= pack("C", $unknown03); + $data .= pack("v", $unknown04); + $data .= pack("v", $unknown05); + $data .= pack("v", $unknown06); + $data .= pack("v", $unknown07); + $data .= pack("v", $unknown08); + $data .= pack("v", $index); + $data .= pack("v", $index); + $data .= pack("v", $rowmin); + $data .= pack("v", $rowmax); + $data .= pack("C", $colmin); + $data .= pack("C", $colmax); + $this->_append($header . $data); } /** * Store the NAME record in the long format that is used for storing the repeat * rows and columns when both are specified. This shares a lot of code with - * storeNameShort() but we use a separate method to keep the code clean. + * _storeNameShort() but we use a separate method to keep the code clean. * Code abstraction for reuse can be carried too far, and I should know. ;-) * * @param integer $index Sheet index @@ -1252,7 +1204,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * @param integer $colmax End column * @access private */ - protected function storeNameLong($index, $type, $rowmin, $rowmax, $colmin, $colmax) + protected function _storeNameLong($index, $type, $rowmin, $rowmax, $colmin, $colmax) { $record = 0x0018; // Record identifier $length = 0x003d; // Number of bytes to follow @@ -1277,49 +1229,49 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $unknown07 = 0x1087; $unknown08 = 0x8008; - $header = pack('vv', $record, $length); - $data = pack('v', $grbit); - $data .= pack('C', $chKey); - $data .= pack('C', $cch); - $data .= pack('v', $cce); - $data .= pack('v', $ixals); - $data .= pack('v', $itab); - $data .= pack('C', $cchCustMenu); - $data .= pack('C', $cchDescription); - $data .= pack('C', $cchHelptopic); - $data .= pack('C', $cchStatustext); - $data .= pack('C', $rgch); - $data .= pack('C', $unknown01); - $data .= pack('v', $unknown02); + $header = pack("vv", $record, $length); + $data = pack("v", $grbit); + $data .= pack("C", $chKey); + $data .= pack("C", $cch); + $data .= pack("v", $cce); + $data .= pack("v", $ixals); + $data .= pack("v", $itab); + $data .= pack("C", $cchCustMenu); + $data .= pack("C", $cchDescription); + $data .= pack("C", $cchHelptopic); + $data .= pack("C", $cchStatustext); + $data .= pack("C", $rgch); + $data .= pack("C", $unknown01); + $data .= pack("v", $unknown02); // Column definition - $data .= pack('C', $unknown03); - $data .= pack('v', $unknown04); - $data .= pack('v', $unknown05); - $data .= pack('v', $unknown06); - $data .= pack('v', $unknown07); - $data .= pack('v', $unknown08); - $data .= pack('v', $index); - $data .= pack('v', $index); - $data .= pack('v', 0x0000); - $data .= pack('v', 0x3fff); - $data .= pack('C', $colmin); - $data .= pack('C', $colmax); + $data .= pack("C", $unknown03); + $data .= pack("v", $unknown04); + $data .= pack("v", $unknown05); + $data .= pack("v", $unknown06); + $data .= pack("v", $unknown07); + $data .= pack("v", $unknown08); + $data .= pack("v", $index); + $data .= pack("v", $index); + $data .= pack("v", 0x0000); + $data .= pack("v", 0x3fff); + $data .= pack("C", $colmin); + $data .= pack("C", $colmax); // Row definition - $data .= pack('C', $unknown03); - $data .= pack('v', $unknown04); - $data .= pack('v', $unknown05); - $data .= pack('v', $unknown06); - $data .= pack('v', $unknown07); - $data .= pack('v', $unknown08); - $data .= pack('v', $index); - $data .= pack('v', $index); - $data .= pack('v', $rowmin); - $data .= pack('v', $rowmax); - $data .= pack('C', 0x00); - $data .= pack('C', 0xff); + $data .= pack("C", $unknown03); + $data .= pack("v", $unknown04); + $data .= pack("v", $unknown05); + $data .= pack("v", $unknown06); + $data .= pack("v", $unknown07); + $data .= pack("v", $unknown08); + $data .= pack("v", $index); + $data .= pack("v", $index); + $data .= pack("v", $rowmin); + $data .= pack("v", $rowmax); + $data .= pack("C", 0x00); + $data .= pack("C", 0xff); // End of data - $data .= pack('C', 0x10); - $this->append($header . $data); + $data .= pack("C", 0x10); + $this->_append($header . $data); } /** @@ -1327,15 +1279,15 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function storeCountry() + protected function _storeCountry() { $record = 0x008C; // Record identifier $length = 4; // Number of bytes to follow $header = pack('vv', $record, $length); /* using the same country code always for simplicity */ - $data = pack('vv', $this->countryCode, $this->countryCode); - $this->append($header . $data); + $data = pack('vv', $this->_country_code, $this->_country_code); + $this->_append($header . $data); } /** @@ -1343,9 +1295,9 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function storePalette() + protected function _storePalette() { - $aref = $this->palette; + $aref = $this->_palette; $record = 0x0092; // Record identifier $length = 2 + 4 * count($aref); // Number of bytes to follow @@ -1355,12 +1307,12 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // Pack the RGB data foreach ($aref as $color) { foreach ($color as $byte) { - $data .= pack('C', $byte); + $data .= pack("C",$byte); } } - $header = pack('vvv', $record, $length, $ccv); - $this->append($header . $data); + $header = pack("vvv", $record, $length, $ccv); + $this->_append($header . $data); } /** @@ -1373,7 +1325,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function calculateSharedStringsSizes() + protected function _calculateSharedStringsSizes() { /* Iterate through the strings to calculate the CONTINUE block sizes. For simplicity we use the same size for the SST and CONTINUE records: @@ -1385,13 +1337,13 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $continue_limit = 8208; $block_length = 0; $written = 0; - $this->blockSize = array(); + $this->_block_sizes = array(); $continue = 0; - foreach (array_keys($this->tableOfStrings) as $string) { + foreach (array_keys($this->_str_table) as $string) { $string_length = strlen($string); - $headerinfo = unpack('vlength/Cencoding', $string); - $encoding = $headerinfo['encoding']; + $headerinfo = unpack("vlength/Cencoding", $string); + $encoding = $headerinfo["encoding"]; $split_string = 0; // Block length is the total length of the strings that will be @@ -1451,7 +1403,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $block_length -= $continue_limit - $continue - $align; // Store the max size for this block - $this->blockSize[] = $continue_limit - $align; + $this->_block_sizes[] = $continue_limit - $align; // If the current string was split then the next CONTINUE block // should have the string continue flag (grbit) set unless the @@ -1463,7 +1415,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri } } else { // Store the max size for this block - $this->blockSize[] = $written + $continue; + $this->_block_sizes[] = $written + $continue; // Not enough space to start the string in the current block $block_length -= $continue_limit - $space_remaining - $continue; @@ -1484,7 +1436,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // Store the max size for the last block unless it is empty if ($written + $continue) { - $this->blockSize[] = $written + $continue; + $this->_block_sizes[] = $written + $continue; } @@ -1494,13 +1446,13 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri they must be written before the SST records */ - $tmp_block_sizes = $this->blockSize; - $length = 12; + $tmp_block_sizes = array(); + $tmp_block_sizes = $this->_block_sizes; + $length = 12; if (!empty($tmp_block_sizes)) { $length += array_shift($tmp_block_sizes); // SST } - while (!empty($tmp_block_sizes)) { $length += 4 + array_shift($tmp_block_sizes); // CONTINUEs } @@ -1519,7 +1471,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * * @access private */ - protected function storeSharedStringsTable() + protected function _storeSharedStringsTable() { $record = 0x00fc; // Record identifier $length = 0x0008; // Number of bytes to follow @@ -1532,8 +1484,8 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $continue = 0; // sizes are upside down - $tmp_block_sizes = $this->blockSize; - // $tmp_block_sizes = array_reverse($this->blockSize); + $tmp_block_sizes = $this->_block_sizes; + // $tmp_block_sizes = array_reverse($this->_block_sizes); // The SST record is required even if it contains no strings. Thus we will // always have a length @@ -1549,19 +1501,19 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // Write the SST block header information - $header = pack('vv', $record, $length); - $data = pack('VV', $this->totalStringLength, $this->uniqueString); - $this->append($header . $data); + $header = pack("vv", $record, $length); + $data = pack("VV", $this->_str_total, $this->_str_unique); + $this->_append($header . $data); /* TODO: not good for performance */ - foreach (array_keys($this->tableOfStrings) as $string) { + foreach (array_keys($this->_str_table) as $string) { $string_length = strlen($string); - $headerinfo = unpack('vlength/Cencoding', $string); - $encoding = $headerinfo['encoding']; + $headerinfo = unpack("vlength/Cencoding", $string); + $encoding = $headerinfo["encoding"]; $split_string = 0; // Block length is the total length of the strings that will be @@ -1572,7 +1524,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // We can write the string if it doesn't cross a CONTINUE boundary if ($block_length < $continue_limit) { - $this->append($string); + $this->_append($string); $written += $string_length; continue; } @@ -1620,7 +1572,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri if ($space_remaining > $header_length) { // Write as much as possible of the string in the current block $tmp = substr($string, 0, $space_remaining); - $this->append($tmp); + $this->_append($tmp); // The remainder will be written in the next block(s) $string = substr($string, $space_remaining); @@ -1644,7 +1596,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri } // Write the CONTINUE block header - if (!empty($this->blockSize)) { + if (!empty($this->_block_sizes)) { $record = 0x003C; $length = array_shift($tmp_block_sizes); @@ -1652,7 +1604,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri if ($continue) { $header .= pack('C', $encoding); } - $this->append($header); + $this->_append($header); } // If the string (or substr) is small enough we can write it in the @@ -1660,7 +1612,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // one or more CONTINUE blocks // if ($block_length < $continue_limit) { - $this->append($string); + $this->_append($string); $written = $block_length; } else { $written = 0; @@ -1668,5 +1620,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri } } } + + } diff --git a/Spreadsheet/Excel/Writer/Worksheet.php b/Spreadsheet/Excel/Writer/Worksheet.php index b38fa71..b70603b 100644 --- a/Spreadsheet/Excel/Writer/Worksheet.php +++ b/Spreadsheet/Excel/Writer/Worksheet.php @@ -32,8 +32,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -require_once __DIR__ . '/Parser.php'; -require_once __DIR__ . '/BIFFwriter.php'; +if (!class_exists('Spreadsheet_Excel_Writer_BIFFwriter')) { + require_once 'Spreadsheet/Excel/Writer/Parser.php'; + require_once 'Spreadsheet/Excel/Writer/BIFFwriter.php'; +} /** * Class for generating Excel Spreadsheets @@ -373,49 +375,43 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr */ public $_input_encoding; - public $activesheet; - - public $firstsheet; - /** * Constructor * * @param string $name The name of the new worksheet * @param integer $index The index of the new worksheet - * @param mixed $activeSheet The current activesheet of the workbook we belong to - * @param mixed $firstSheet The first worksheet in the workbook we belong to + * @param mixed $activesheet The current activesheet of the workbook we belong to + * @param mixed $firstsheet The first worksheet in the workbook we belong to + * @param int &$str_total Reference to the total number of strings in the workbook + * @param int &$str_unique Reference to the number of unique strings in the workbook + * @param array &$str_table Reference to the array containing all the unique strings in the workbook * @param mixed $url_format The default format for hyperlinks * @param mixed $parser The formula parser created for the Workbook * @param string $tmp_dir The path to the directory for temporary files * @access private */ - public function __construct( - $BIFF_version, - $name, - $index, - $activeSheet, - $firstSheet, - $str_total, - $str_unique, - $str_table, - $url_format, - $parser, - $tmp_dir - ) + public function __construct($BIFF_version, $name, + $index, $activesheet, + $firstsheet, &$str_total, + &$str_unique, &$str_table, + $url_format, $parser, + $tmp_dir) { // It needs to call its parent's constructor explicitly parent::__construct(); - $this->BIFF_version = $BIFF_version; + $this->_BIFF_version = $BIFF_version; $rowmax = 65536; // 16384 in Excel 5 $colmax = 256; $this->name = $name; $this->index = $index; - $this->activesheet = $activeSheet; - $this->firstsheet = $firstSheet; - $this->_str_total = $str_total; - $this->_str_unique = $str_unique; - $this->_str_table = $str_table; + $this->activesheet = $activesheet; + $this->firstsheet = $firstsheet; + // _str_total _str_unique _str_table - are actual references + // everything breaks if they're not + $this->_str_total = &$str_total; + $this->_str_unique = &$str_unique; + $this->_str_table = &$str_table; $this->_url_format = $url_format; $this->_parser = $parser; @@ -492,9 +488,9 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $this->_input_encoding = ''; $this->_dv = array(); - - $this->temporaryDirectory = $tmp_dir; - $this->temporaryFile = ''; + + $this->_tmp_dir = $tmp_dir; + $this->_tmp_file = ''; $this->_initialize(); } @@ -512,20 +508,20 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr return; } - if ($this->temporaryDirectory === '' && ini_get('open_basedir') === true) { + if ($this->_tmp_dir === '' && ini_get('open_basedir') === true) { // open_basedir restriction in effect - store data in memory // ToDo: Let the error actually have an effect somewhere - $this->_using_tmpfile = false; + $this->_using_tmpfile = false; return new PEAR_Error('Temp file could not be opened since open_basedir restriction in effect - please use setTmpDir() - using memory storage instead'); } // Open tmp file for storing Worksheet data - if ($this->temporaryDirectory === '') { + if ($this->_tmp_dir === '') { $fh = tmpfile(); } else { // For people with open base dir restriction - $this->temporaryFile = tempnam($this->temporaryDirectory, 'Spreadsheet_Excel_Writer'); - $fh = @fopen($this->temporaryFile, 'w+b'); + $this->_tmp_file = tempnam($this->_tmp_dir, "Spreadsheet_Excel_Writer"); + $fh = @fopen($this->_tmp_file, "w+b"); } if ($fh === false) { @@ -604,7 +600,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $this->_storeGridset(); // Prepend GUTS - if ($this->BIFF_version == 0x0500) { + if ($this->_BIFF_version == 0x0500) { $this->_storeGuts(); } @@ -615,7 +611,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $this->_storePrintHeaders(); // Prepend EXTERNSHEET references - if ($this->BIFF_version == 0x0500) { + if ($this->_BIFF_version == 0x0500) { for ($i = $num_sheets; $i > 0; $i--) { $sheetname = $sheetnames[$i-1]; $this->_storeExternsheet($sheetname); @@ -623,7 +619,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr } // Prepend the EXTERNCOUNT of external references. - if ($this->BIFF_version == 0x0500) { + if ($this->_BIFF_version == 0x0500) { $this->_storeExterncount($num_sheets); } @@ -637,7 +633,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr } // Prepend the BOF record - $this->storeBof(0x0010); + $this->_storeBof(0x0010); /* * End of prepend. Read upwards from here. @@ -652,18 +648,18 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $this->_storeSelection($this->_selection); $this->_storeMergedCells(); /* TODO: add data validity */ - /*if ($this->BIFF_version == 0x0600) { + /*if ($this->_BIFF_version == 0x0600) { $this->_storeDataValidity(); }*/ - $this->storeEof(); + $this->_storeEof(); - if ( $this->temporaryFile != '' ) { + if ( $this->_tmp_file != '' ) { if ( $this->_filehandle ) { fclose($this->_filehandle); $this->_filehandle = ''; } - @unlink($this->temporaryFile); - $this->temporaryFile = ''; + @unlink($this->_tmp_file); + $this->_tmp_file = ''; $this->_using_tmpfile = true; } } @@ -691,9 +687,9 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $buffer = 4096; // Return data stored in memory - if (isset($this->data)) { - $tmp = $this->data; - unset($this->data); + if (isset($this->_data)) { + $tmp = $this->_data; + unset($this->_data); $fh = $this->_filehandle; if ($this->_using_tmpfile) { fseek($fh, 0); @@ -726,7 +722,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr return; } - $max_record_ranges = floor(($this->limit - 6) / 8); + $max_record_ranges = floor(($this->_limit - 6) / 8); if($this->_merged_cells_counter >= $max_record_ranges) { $this->_merged_cells_record++; @@ -801,39 +797,39 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr * @param integer $level The optional outline level */ public function setColumn($firstcol, $lastcol, $width, $format = null, $hidden = 0, $level = 0) - { // added by Dan Lynn _colinfo as $key => $colinfo) + { // added by Dan Lynn _colinfo as $key => $colinfo) { - $existing_start = $colinfo[0]; $existing_end = $colinfo[1]; - // if the new range starts within another range - if ($firstcol > $existing_start && $firstcol < $existing_end) - { // trim the existing range to the beginning of the new range - $this->_colinfo[$key][1] = $firstcol - 1; - // if the new range lies WITHIN the existing range - if ($lastcol < $existing_end) - { // split the existing range by adding a range after our new range - $this->_colinfo[] = array($lastcol+1, $existing_end, $colinfo[2], &$colinfo[3], $colinfo[4], $colinfo[5]); - } - } // if the new range ends inside an existing range - elseif ($lastcol > $existing_start && $lastcol < $existing_end) - { // trim the existing range to the end of the new range - $this->_colinfo[$key][0] = $lastcol + 1; - } // if the new range completely overlaps the existing range - elseif ($firstcol <= $existing_start && $lastcol >= $existing_end) - { - unset($this->_colinfo[$key]); - } - } // added by Dan Lynn _colinfo = array_values($this->_colinfo); - $this->_colinfo[] = array($firstcol, $lastcol, $width, &$format, $hidden, $level); - // Set width to zero if column is hidden - $width = ($hidden) ? 0 : $width; - for ($col = $firstcol; $col <= $lastcol; $col++) - { - $this->col_sizes[$col] = $width; - } + $existing_start = $colinfo[0]; $existing_end = $colinfo[1]; + // if the new range starts within another range + if ($firstcol > $existing_start && $firstcol < $existing_end) + { // trim the existing range to the beginning of the new range + $this->_colinfo[$key][1] = $firstcol - 1; + // if the new range lies WITHIN the existing range + if ($lastcol < $existing_end) + { // split the existing range by adding a range after our new range + $this->_colinfo[] = array($lastcol+1, $existing_end, $colinfo[2], /* format */ $colinfo[3], $colinfo[4], $colinfo[5]); + } + } // if the new range ends inside an existing range + elseif ($lastcol > $existing_start && $lastcol < $existing_end) + { // trim the existing range to the end of the new range + $this->_colinfo[$key][0] = $lastcol + 1; + } // if the new range completely overlaps the existing range + elseif ($firstcol <= $existing_start && $lastcol >= $existing_end) + { + unset($this->_colinfo[$key]); + } + } // added by Dan Lynn _colinfo = array_values($this->_colinfo); + $this->_colinfo[] = array($firstcol, $lastcol, $width, $format, $hidden, $level); + // Set width to zero if column is hidden + $width = ($hidden) ? 0 : $width; + for ($col = $firstcol; $col <= $lastcol; $col++) + { + $this->col_sizes[$col] = $width; + } } /** @@ -1192,7 +1188,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr { // Confine the scale to Excel's range if ($scale < 10 || $scale > 400) { - $this->raiseError('Zoom factor ' . $scale . ' outside range: 10 <= zoom <= 400'); + $this->raiseError("Zoom factor $scale outside range: 10 <= zoom <= 400"); $scale = 100; } @@ -1349,13 +1345,13 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr { if ($this->_using_tmpfile) { // Add CONTINUE records if necessary - if (strlen($data) > $this->limit) { - $data = $this->addContinue($data); + if (strlen($data) > $this->_limit) { + $data = $this->_addContinue($data); } fwrite($this->_filehandle, $data); - $this->dataSize += strlen($data); + $this->_datasize += strlen($data); } else { - parent::append($data); + parent::_append($data); } } @@ -1541,7 +1537,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("vvv", $row, $col, $xf); $xl_double = pack("d", $num); - if ($this->byteOrder) { // if it's Big Endian + if ($this->_byte_order) { // if it's Big Endian $xl_double = strrev($xl_double); } @@ -1566,7 +1562,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr */ public function writeString($row, $col, $str, $format = null) { - if ($this->BIFF_version == 0x0600) { + if ($this->_BIFF_version == 0x0600) { return $this->writeStringBIFF8($row, $col, $str, $format); } $strlen = strlen($str); @@ -1927,7 +1923,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr /** * This is the more general form of writeUrl(). It allows a hyperlink to be - * written to a range of cells. This function also decides the type of hyperlink + * written to a range of cells. This public function also decides the type of hyperlink * to be written. These are either, Web (http, ftp, mailto), Internal * (Sheet1!A1) or external ('c:\temp\foo.xls#Sheet1!A1'). * @@ -2106,19 +2102,19 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr if (preg_match('[^external:\\\\]', $url)) { return; //($this->_writeUrlExternal_net($row1, $col1, $row2, $col2, $url, $str, $format)); } - + $record = 0x01B8; // Record identifier $length = 0x00000; // Bytes to follow - + if (!$format) { $format = $this->_url_format; } - + // Strip URL type and change Unix dir separator to Dos style (if needed) // $url = preg_replace('/^external:/', '', $url); $url = preg_replace('/\//', "\\", $url); - + // Write the visible label if ($str == '') { $str = preg_replace('/\#/', ' - ', $url); @@ -2127,12 +2123,12 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr if (($str_error == -2) or ($str_error == -3)) { return $str_error; } - + // Determine if the link is relative or absolute: // relative if link contains no dir separator, "somefile.xls" // relative if link starts with up-dir, "..\..\somefile.xls" // otherwise, absolute - + $absolute = 0x02; // Bit mask if (!preg_match("/\\\/", $url)) { $absolute = 0x00; @@ -2141,7 +2137,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $absolute = 0x00; } $link_type = 0x01 | $absolute; - + // Determine if the link contains a sheet reference and change some of the // parameters accordingly. // Split the dir name and sheet name (if it exists) @@ -2150,7 +2146,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr } else { $dir_long = $url; } - + if (isset($sheet)) { $link_type |= 0x08; $sheet_len = pack("V", strlen($sheet) + 0x01); @@ -2166,32 +2162,32 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr } - + // Pack the link type $link_type = pack("V", $link_type); - + // Calculate the up-level dir count e.g.. (..\..\..\ == 3) $up_count = preg_match_all("/\.\.\\\/", $dir_long, $useless); $up_count = pack("v", $up_count); - + // Store the short dos dir name (null terminated) $dir_short = preg_replace("/\.\.\\\/", '', $dir_long) . "\0"; - + // Store the long dir name as a wchar string (non-null terminated) //$dir_long = join("\0", split('', $dir_long)); $dir_long = $dir_long . "\0"; - + // Pack the lengths of the dir strings $dir_short_len = pack("V", strlen($dir_short) ); $dir_long_len = pack("V", strlen($dir_long) ); $stream_len = pack("V", 0);//strlen($dir_long) + 0x06); - + // Pack the undocumented parts of the hyperlink stream $unknown1 = pack("H*",'D0C9EA79F9BACE118C8200AA004BA90B02000000' ); $unknown2 = pack("H*",'0303000000000000C000000000000046' ); $unknown3 = pack("H*",'FFFFADDE000000000000000000000000000000000000000'); $unknown4 = pack("v", 0x03 ); - + // Pack the main data stream $data = pack("vvvv", $row1, $row2, $col1, $col2) . $unknown1 . @@ -2207,11 +2203,11 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $dir_long . $sheet_len . $sheet ;*/ - + // Pack the header data $length = strlen($data); $header = pack("vv", $record, $length); - + // Write the packed data $this->_append($header. $data); return($str_error); @@ -2291,17 +2287,17 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $col_max = $this->_dim_colmax + 1; // Last column plus 1 $reserved = 0x0000; // Reserved by Excel - if ($this->BIFF_version == 0x0500) { + if ($this->_BIFF_version == 0x0500) { $length = 0x000A; // Number of bytes to follow $data = pack("vvvvv", $row_min, $row_max, $col_min, $col_max, $reserved); - } elseif ($this->BIFF_version == 0x0600) { + } elseif ($this->_BIFF_version == 0x0600) { $length = 0x000E; $data = pack("VVvvv", $row_min, $row_max, $col_min, $col_max, $reserved); } $header = pack("vv", $record, $length); - $this->prepend($header.$data); + $this->_prepend($header.$data); } /** @@ -2312,9 +2308,9 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr protected function _storeWindow2() { $record = 0x023E; // Record identifier - if ($this->BIFF_version == 0x0500) { + if ($this->_BIFF_version == 0x0500) { $length = 0x000A; // Number of bytes to follow - } elseif ($this->BIFF_version == 0x0600) { + } elseif ($this->_BIFF_version == 0x0600) { $length = 0x0012; } @@ -2351,10 +2347,10 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("vvv", $grbit, $rwTop, $colLeft); // FIXME !!! - if ($this->BIFF_version == 0x0500) { + if ($this->_BIFF_version == 0x0500) { $rgbHdr = 0x00000000; // Row/column heading and gridline color $data .= pack("V", $rgbHdr); - } elseif ($this->BIFF_version == 0x0600) { + } elseif ($this->_BIFF_version == 0x0600) { $rgbHdr = 0x0040; // Row/column heading and gridline color index $zoom_factor_page_break = 0x0000; $zoom_factor_normal = 0x0000; @@ -2376,7 +2372,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("v", $colwidth); - $this->prepend($header . $data); + $this->_prepend($header . $data); } /** @@ -2437,7 +2433,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("vvvvvC", $colFirst, $colLast, $coldx, $ixfe, $grbit, $reserved); - $this->prepend($header.$data); + $this->_prepend($header.$data); } /** @@ -2497,10 +2493,10 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $record = 0x00E5; foreach($this->_merged_ranges as $ranges) { - $length = 2 + count($ranges) * 8; + $length = 2 + count($ranges) * 8; $header = pack('vv', $record, $length); $data = pack('v', count($ranges)); - foreach ($ranges as $range) + foreach ($ranges as $range) $data .= pack('vvvv', $range[0], $range[2], $range[1], $range[3]); $string = $header.$data; $this->_append($string, true); @@ -2527,7 +2523,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("v", $count); - $this->prepend($header . $data); + $this->_prepend($header . $data); } /** @@ -2559,7 +2555,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("CC", $cch, $rgch); - $this->prepend($header . $data . $sheetname); + $this->_prepend($header . $data . $sheetname); } /** @@ -2685,7 +2681,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $numHdr = pack("d", $numHdr); $numFtr = pack("d", $numFtr); - if ($this->byteOrder) { // if it's Big Endian + if ($this->_byte_order) { // if it's Big Endian $numHdr = strrev($numHdr); $numFtr = strrev($numFtr); } @@ -2701,7 +2697,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $iVRes); $data2 = $numHdr.$numFtr; $data3 = pack("v", $iCopies); - $this->prepend($header . $data1 . $data2 . $data3); + $this->_prepend($header . $data1 . $data2 . $data3); } /** @@ -2715,7 +2711,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $str = $this->_header; // header string $cch = strlen($str); // Length of header string - if ($this->BIFF_version == 0x0600) { + if ($this->_BIFF_version == 0x0600) { $encoding = 0x0; // TODO: Unicode support $length = 3 + $cch; // Bytes to follow } else { @@ -2723,13 +2719,13 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr } $header = pack("vv", $record, $length); - if ($this->BIFF_version == 0x0600) { + if ($this->_BIFF_version == 0x0600) { $data = pack("vC", $cch, $encoding); } else { $data = pack("C", $cch); } - $this->prepend($header.$data.$str); + $this->_prepend($header.$data.$str); } /** @@ -2743,7 +2739,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $str = $this->_footer; // Footer string $cch = strlen($str); // Length of footer string - if ($this->BIFF_version == 0x0600) { + if ($this->_BIFF_version == 0x0600) { $encoding = 0x0; // TODO: Unicode support $length = 3 + $cch; // Bytes to follow } else { @@ -2751,13 +2747,13 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr } $header = pack("vv", $record, $length); - if ($this->BIFF_version == 0x0600) { + if ($this->_BIFF_version == 0x0600) { $data = pack("vC", $cch, $encoding); } else { $data = pack("C", $cch); } - $this->prepend($header . $data . $str); + $this->_prepend($header . $data . $str); } /** @@ -2775,7 +2771,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("v", $fHCenter); - $this->prepend($header.$data); + $this->_prepend($header.$data); } /** @@ -2792,7 +2788,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("v", $fVCenter); - $this->prepend($header . $data); + $this->_prepend($header . $data); } /** @@ -2809,11 +2805,11 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("d", $margin); - if ($this->byteOrder) { // if it's Big Endian + if ($this->_byte_order) { // if it's Big Endian $data = strrev($data); } - $this->prepend($header . $data); + $this->_prepend($header . $data); } /** @@ -2830,11 +2826,11 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("d", $margin); - if ($this->byteOrder) { // if it's Big Endian + if ($this->_byte_order) { // if it's Big Endian $data = strrev($data); } - $this->prepend($header . $data); + $this->_prepend($header . $data); } /** @@ -2851,11 +2847,11 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("d", $margin); - if ($this->byteOrder) { // if it's Big Endian + if ($this->_byte_order) { // if it's Big Endian $data = strrev($data); } - $this->prepend($header . $data); + $this->_prepend($header . $data); } /** @@ -2872,11 +2868,11 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("d", $margin); - if ($this->byteOrder) { // if it's Big Endian + if ($this->_byte_order) { // if it's Big Endian $data = strrev($data); } - $this->prepend($header . $data); + $this->_prepend($header . $data); } /** @@ -2926,7 +2922,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("v", $fPrintRwCol); - $this->prepend($header . $data); + $this->_prepend($header . $data); } /** @@ -2944,7 +2940,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("v", $fPrintGrid); - $this->prepend($header . $data); + $this->_prepend($header . $data); } /** @@ -2962,7 +2958,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("v", $fGridSet); - $this->prepend($header . $data); + $this->_prepend($header . $data); } /** @@ -3008,7 +3004,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("vvvv", $dxRwGut, $dxColGut, $row_level, $col_level); - $this->prepend($header.$data); + $this->_prepend($header.$data); } @@ -3052,7 +3048,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("v", $grbit); - $this->prepend($header . $data); + $this->_prepend($header . $data); } /** @@ -3076,7 +3072,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $record = 0x001b; // Record identifier $cbrk = count($breaks); // Number of page breaks - if ($this->BIFF_version == 0x0600) { + if ($this->_BIFF_version == 0x0600) { $length = 2 + 6*$cbrk; // Bytes to follow } else { $length = 2 + 2*$cbrk; // Bytes to follow @@ -3087,14 +3083,14 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr // Append each page break foreach ($breaks as $break) { - if ($this->BIFF_version == 0x0600) { + if ($this->_BIFF_version == 0x0600) { $data .= pack("vvv", $break, 0x0000, 0x00ff); } else { $data .= pack("v", $break); } } - $this->prepend($header.$data); + $this->_prepend($header.$data); } @@ -3122,7 +3118,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $record = 0x001a; // Record identifier $cbrk = count($breaks); // Number of page breaks - if ($this->BIFF_version == 0x0600) { + if ($this->_BIFF_version == 0x0600) { $length = 2 + 6*$cbrk; // Bytes to follow } else { $length = 2 + 2*$cbrk; // Bytes to follow @@ -3133,14 +3129,14 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr // Append each page break foreach ($breaks as $break) { - if ($this->BIFF_version == 0x0600) { + if ($this->_BIFF_version == 0x0600) { $data .= pack("vvv", $break, 0x0000, 0xffff); } else { $data .= pack("v", $break); } } - $this->prepend($header . $data); + $this->_prepend($header . $data); } /** @@ -3163,7 +3159,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("v", $fLock); - $this->prepend($header.$data); + $this->_prepend($header.$data); } /** @@ -3186,7 +3182,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("v", $wPassword); - $this->prepend($header . $data); + $this->_prepend($header . $data); } @@ -3254,7 +3250,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr * 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 + * public 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 @@ -3608,5 +3604,4 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $this->_append($header . $dv); } } -} -?> +} \ No newline at end of file diff --git a/composer.json b/composer.json index 2887d5f..7d140d7 100644 --- a/composer.json +++ b/composer.json @@ -23,8 +23,12 @@ ], "autoload": { "psr-0": { - "Spreadsheet": "./", - "Test": "./test" + "Spreadsheet": "" + } + }, + "autoload-dev": { + "psr-0": { + "Test": "test" } }, "description": "More info available on: http://pear.php.net/package/Spreadsheet_Excel_Writer", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 13323cf..5c26d15 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,4 +1,4 @@ -test/ + + + + Spreadsheet/ + + + + + + + diff --git a/test/Test/Spreadsheet/Excel/Writer/Test_Spreadsheet_Excel_WriterTestCase.php b/test/Test/Spreadsheet/Excel/Writer/Test_Spreadsheet_Excel_WriterTestCase.php deleted file mode 100644 index 69d6623..0000000 --- a/test/Test/Spreadsheet/Excel/Writer/Test_Spreadsheet_Excel_WriterTestCase.php +++ /dev/null @@ -1,17 +0,0 @@ - - * @since 2016-01-17 - */ -class Test_Spreadsheet_Excel_WriterTestCase extends PHPUnit_Framework_TestCase -{ - /** - * @param string $fileName - * @return Spreadsheet_Excel_Writer_Workbook - */ - protected function getNewWorkbook($fileName = 'my_workbook') - { - return new Spreadsheet_Excel_Writer_Workbook($fileName); - } -} \ No newline at end of file diff --git a/test/Test/Spreadsheet/Excel/Writer/Test_Spreadsheet_Excel_Writer_WorkbookTest.php b/test/Test/Spreadsheet/Excel/Writer/Test_Spreadsheet_Excel_Writer_WorkbookTest.php deleted file mode 100644 index e96a5df..0000000 --- a/test/Test/Spreadsheet/Excel/Writer/Test_Spreadsheet_Excel_Writer_WorkbookTest.php +++ /dev/null @@ -1,15 +0,0 @@ - - * @since 2016-01-17 - */ -class Test_Spreadsheet_Excel_Writer_WorkbookTest extends Test_Spreadsheet_Excel_WriterTestCase -{ - public function testSetVersion() - { - $workbook = $this->getNewWorkbook(); - - $workbook->setVersion(8); - } -} \ No newline at end of file diff --git a/test/Test/Spreadsheet/Excel/Writer/WorkbookTest.php b/test/Test/Spreadsheet/Excel/Writer/WorkbookTest.php new file mode 100644 index 0000000..a7416ef --- /dev/null +++ b/test/Test/Spreadsheet/Excel/Writer/WorkbookTest.php @@ -0,0 +1,75 @@ + + * @since 2016-01-17 + */ +class Test_Spreadsheet_Excel_Writer_WorkbookTest extends Test_Spreadsheet_Excel_WriterTestCase +{ + public function testSetVersion() + { + $workbook = $this->getNewWorkbook(); + + $before = get_object_vars($workbook); + + $workbook->setVersion(1); + + $this->assertEquals($before, get_object_vars($workbook), "Version 1 should not change internal state"); + + $workbook->setVersion(8); + + $this->assertNotEquals($before, get_object_vars($workbook), "Version 8 should change internal state"); + + return $workbook; + } + + /** + * @depends testSetVersion + */ + public function testWriteSingleCell(Spreadsheet_Excel_Writer $workbook) + { + $sheet = $workbook->addWorksheet("Example"); + $sheet->write(0, 0, "Example"); + + $this->assertSameAsInFixture('example.xls', $workbook); + } + + public function testWriteWithFormat() + { + $workbook = $this->getNewWorkbook(); + $workbook->setVersion(8); + + $format = $workbook->addFormat(); + $format->setFontFamily('Helvetica'); + $format->setSize(16); + $format->setVAlign('vcenter'); + $format->setBorder(1); + + $sheet = $workbook->addWorksheet('Example report'); + $sheet->setInputEncoding('utf-8'); + + $sheet->setColumn(0, 10, 35); + + $sheet->writeString(0, 0, "Test string", $format); + $sheet->setRow(0, 40); + + $sheet->writeString(1, 0, "こんにちわ"); + + $this->assertSameAsInFixture('with_format.xls', $workbook); + } + + public function testWithDefaultVersion() + { + $workbook = $this->getNewWorkbook(); + + $sheet = $workbook->addWorksheet("Example"); + + for ($i = 0; $i < 10; $i++) { + for ($j = 0; $j < 10; $j++) { + $sheet->write($i, $j, "Row $i $j"); + } + } + + $this->assertSameAsInFixture('example2.xls', $workbook); + } +} diff --git a/test/Test/Spreadsheet/Excel/WriterTestCase.php b/test/Test/Spreadsheet/Excel/WriterTestCase.php new file mode 100644 index 0000000..7d7d2a8 --- /dev/null +++ b/test/Test/Spreadsheet/Excel/WriterTestCase.php @@ -0,0 +1,55 @@ + + * @since 2016-01-17 + */ +class Test_Spreadsheet_Excel_WriterTestCase extends PHPUnit_Framework_TestCase +{ + const FIXTURES_PATH = 'test/fixture/'; + + /** + * @param string $filename + * @return Spreadsheet_Excel_Writer + */ + protected function getNewWorkbook($filename = '') + { + // we're writing to the standard output by defaulr + return new Spreadsheet_Excel_Writer($filename); + } + + protected function assertSameAsInFixture($filename, Spreadsheet_Excel_Writer $workbook) + { + $this->assertEmpty($workbook->_filename, "Testing with fixtures works only for standard output"); + + // we have to fix timestamp for fixtures to work + $workbook->_timestamp = 1000000000; // somewhere in 2001 + + ob_start(); + $workbook->close(); + $data = ob_get_clean(); + + $fullPath = self::FIXTURES_PATH.$filename; + + if ($this->shouldUpdateFixtures()) { + file_put_contents($fullPath, $data); + } + + if (!is_file($fullPath)) { + $this->fail("Fixture $filename not found"); + } + + // TODO: should we save data for future analysis? + //file_put_contents("{$fullPath}.work", $data); + + $this->assertEquals(file_get_contents($fullPath), $data, "Output differs for $filename"); + } + + /** + * We should update golden files + */ + private function shouldUpdateFixtures() + { + return isset($_SERVER['GOLDEN']); + } +} \ No newline at end of file diff --git a/test/bootstrap.php b/test/bootstrap.php deleted file mode 100644 index 0ddc4c5..0000000 --- a/test/bootstrap.php +++ /dev/null @@ -1,4 +0,0 @@ -