diff --git a/Writer.php b/Writer.php index eda6120..aca86d0 100644 --- a/Writer.php +++ b/Writer.php @@ -31,8 +31,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -require_once('PEAR.php'); -require_once('Spreadsheet/Excel/Writer/Workbook.php'); +require_once 'PEAR.php'; +require_once 'Spreadsheet/Excel/Writer/Workbook.php'; /** * Class for writing Excel Spreadsheets. This class should change COMPLETELY. diff --git a/Writer/BIFFwriter.php b/Writer/BIFFwriter.php index 1f700df..cd9c94b 100644 --- a/Writer/BIFFwriter.php +++ b/Writer/BIFFwriter.php @@ -32,7 +32,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -require_once('PEAR.php'); +require_once 'PEAR.php'; /** * Class for writing Excel BIFF records. @@ -112,11 +112,9 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR $number = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F); if ($number == $teststr) { $byte_order = 0; // Little Endian - } - elseif ($number == strrev($teststr)){ + } elseif ($number == strrev($teststr)){ $byte_order = 1; // Big Endian - } - else { + } else { // Give up. I'll fix this in a later version. return $this->raiseError("Required floating point format ". "not supported on this platform."); @@ -173,8 +171,7 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR $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; @@ -224,8 +221,7 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR $header = pack("vv", $record, $limit); // Headers for continue records // Retrieve chunks of 2080/8224 bytes +4 for the header. - for($i = $limit; $i < strlen($data) - $limit; $i += $limit) - { + for ($i = $limit; $i < strlen($data) - $limit; $i += $limit) { $tmp .= $header; $tmp .= substr($data, $i, $limit); } @@ -233,7 +229,7 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR // Retrieve the last chunk of data $header = pack("vv", $record, strlen($data) - $i); $tmp .= $header; - $tmp .= substr($data,$i,strlen($data) - $i); + $tmp .= substr($data, $i, strlen($data) - $i); return $tmp; } diff --git a/Writer/Format.php b/Writer/Format.php index 788d25b..8f6abda 100644 --- a/Writer/Format.php +++ b/Writer/Format.php @@ -32,7 +32,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -require_once('PEAR.php'); +require_once 'PEAR.php'; /** * Class for generating Excel XF records (formats) @@ -296,10 +296,9 @@ class Spreadsheet_Excel_Writer_Format extends PEAR $this->_diag_color = 0x40; // Set properties passed to Spreadsheet_Excel_Writer_Workbook::addFormat() - foreach($properties as $property => $value) + foreach ($properties as $property => $value) { - if(method_exists($this,'set'.ucwords($property))) - { + if (method_exists($this, 'set'.ucwords($property))) { $method_name = 'set'.ucwords($property); $this->$method_name($value); } @@ -318,8 +317,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR // Set the type of the XF record and some of the attributes. if ($style == "style") { $style = 0xFFF5; - } - else { + } else { $style = $this->_locked; $style |= $this->_hidden << 1; } @@ -364,8 +362,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR $ifnt = $this->font_index; // Index to FONT record $ifmt = $this->_num_format; // Index to FORMAT record - if ($this->_BIFF_version == 0x0500) - { + if ($this->_BIFF_version == 0x0500) { $align = $this->_text_h_align; // Alignment $align |= $this->_text_wrap << 3; $align |= $this->_text_v_align << 4; @@ -397,9 +394,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR $data = pack("vvvvvvvv", $ifnt, $ifmt, $style, $align, $icv, $fill, $border1, $border2); - } - elseif ($this->_BIFF_version == 0x0600) - { + } elseif ($this->_BIFF_version == 0x0600) { $align = $this->_text_h_align; // Alignment $align |= $this->_text_wrap << 3; $align |= $this->_text_v_align << 4; @@ -464,8 +459,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR $record = 0x31; // Record identifier if ($this->_BIFF_version == 0x0500) { $length = 0x0F + $cch; // Record length - } - elseif ($this->_BIFF_version == 0x0600) { + } elseif ($this->_BIFF_version == 0x0600) { $length = 0x10 + $cch; } $reserved = 0x00; // Reserved @@ -488,8 +482,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR $data = pack("vvvvvCCCCC", $dyHeight, $grbit, $icv, $bls, $sss, $uls, $bFamily, $bCharSet, $reserved, $cch); - } - elseif ($this->_BIFF_version == 0x0600) { + } elseif ($this->_BIFF_version == 0x0600) { $data = pack("vvvvvCCCCCC", $dyHeight, $grbit, $icv, $bls, $sss, $uls, $bFamily, $bCharSet, $reserved, $cch, $encoding); @@ -561,27 +554,27 @@ class Spreadsheet_Excel_Writer_Format extends PEAR ); // Return the default color, 0x7FFF, if undef, - if($name_color == '') { + if ($name_color == '') { return(0x7FFF); } // or the color string converted to an integer, - if(isset($colors[$name_color])) { + if (isset($colors[$name_color])) { return($colors[$name_color]); } // or the default color if string is unrecognised, - if(preg_match("/\D/",$name_color)) { + if (preg_match("/\D/",$name_color)) { return(0x7FFF); } // or an index < 8 mapped into the correct range, - if($name_color < 8) { + if ($name_color < 8) { return($name_color + 8); } // or the default color if arg is outside range, - if($name_color > 63) { + if ($name_color > 63) { return(0x7FFF); } @@ -669,16 +662,16 @@ class Spreadsheet_Excel_Writer_Format extends PEAR */ function setBold($weight = 1) { - if($weight == 1) { + if ($weight == 1) { $weight = 0x2BC; // Bold text } - if($weight == 0) { + if ($weight == 0) { $weight = 0x190; // Normal text } - if($weight < 0x064) { + if ($weight < 0x064) { $weight = 0x190; // Lower bound } - if($weight > 0x3E8) { + if ($weight > 0x3E8) { $weight = 0x190; // Upper bound } $this->_bold = $weight; diff --git a/Writer/OLEwriter.php b/Writer/OLEwriter.php index e169cd2..2ca39e4 100644 --- a/Writer/OLEwriter.php +++ b/Writer/OLEwriter.php @@ -32,7 +32,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -require_once('PEAR.php'); +require_once 'PEAR.php'; /** * Class for creating OLE streams for Excel Spreadsheets @@ -131,18 +131,15 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR { $OLEfile = $this->_OLEfilename; - if(($OLEfile == '-') or ($OLEfile == '')) - { + if (($OLEfile == '-') or ($OLEfile == '')) { $this->_tmp_filename = tempnam("/tmp", "OLEwriter"); - $fh = fopen($this->_tmp_filename,"wb"); + $fh = fopen($this->_tmp_filename, "wb"); if ($fh == false) { $this->raiseError("Can't create temporary file."); } - } - else - { + } else { // Create a new file, open for writing (in binmode) - $fh = fopen($OLEfile,"wb"); + $fh = fopen($OLEfile, "wb"); if ($fh == false) { $this->raiseError("Can't open $OLEfile. It may be in use or protected."); } @@ -177,8 +174,7 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR // Set the min file size to 4k to avoid having to use small blocks if ($biffsize > 4096) { $this->_booksize = $biffsize; - } - else { + } else { $this->_booksize = 4096; } //$this->_size_allowed = 1; @@ -196,8 +192,7 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR $datasize = $this->_booksize; if ($datasize % 512 == 0) { $this->_big_blocks = $datasize/512; - } - else { + } else { $this->_big_blocks = floor($datasize/512) + 1; } // There are 127 list blocks and 1 marker blocks for each big block @@ -222,8 +217,7 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR $this->_writeBigBlockDepot(); // Close the filehandle fclose($this->_filehandle); - if(($this->_OLEfilename == '-') or ($this->_OLEfilename == '')) - { + if (($this->_OLEfilename == '-') or ($this->_OLEfilename == '')) { $fh = fopen($this->_tmp_filename, "rb"); if ($fh == false) { $this->raiseError("Can't read temporary file."); @@ -242,7 +236,7 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR */ function write($data) { - fwrite($this->_filehandle,$data,strlen($data)); + fwrite($this->_filehandle, $data, strlen($data)); } @@ -267,26 +261,24 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR $unknown7 = pack("VVV", 0x00, -2 ,0x00); $unused = pack("V", -1); - fwrite($this->_filehandle,$id); - fwrite($this->_filehandle,$unknown1); - fwrite($this->_filehandle,$unknown2); - fwrite($this->_filehandle,$unknown3); - fwrite($this->_filehandle,$unknown4); - fwrite($this->_filehandle,$unknown5); - fwrite($this->_filehandle,$num_bbd_blocks); - fwrite($this->_filehandle,$root_startblock); - fwrite($this->_filehandle,$unknown6); - fwrite($this->_filehandle,$sbd_startblock); - fwrite($this->_filehandle,$unknown7); + fwrite($this->_filehandle, $id); + fwrite($this->_filehandle, $unknown1); + fwrite($this->_filehandle, $unknown2); + fwrite($this->_filehandle, $unknown3); + fwrite($this->_filehandle, $unknown4); + fwrite($this->_filehandle, $unknown5); + fwrite($this->_filehandle, $num_bbd_blocks); + fwrite($this->_filehandle, $root_startblock); + fwrite($this->_filehandle, $unknown6); + fwrite($this->_filehandle, $sbd_startblock); + fwrite($this->_filehandle, $unknown7); - for($i=1; $i <= $num_lists; $i++) - { + for ($i=1; $i <= $num_lists; $i++) { $root_start++; - fwrite($this->_filehandle,pack("V",$root_start)); + fwrite($this->_filehandle, pack("V",$root_start)); } - for($i = $num_lists; $i <=108; $i++) - { - fwrite($this->_filehandle,$unused); + for ($i = $num_lists; $i <=108; $i++) { + fwrite($this->_filehandle, $unused); } } @@ -307,19 +299,16 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR $end_of_chain = pack("V", -2); $unused = pack("V", -1); - for($i=1; $i < $num_blocks; $i++) - { - fwrite($this->_filehandle,pack("V",$i)); + for ($i=1; $i < $num_blocks; $i++) { + fwrite($this->_filehandle, pack("V",$i)); } - fwrite($this->_filehandle,$end_of_chain); - fwrite($this->_filehandle,$end_of_chain); - for($i=0; $i < $num_lists; $i++) - { - fwrite($this->_filehandle,$marker); + fwrite($this->_filehandle, $end_of_chain); + fwrite($this->_filehandle, $end_of_chain); + for ($i=0; $i < $num_lists; $i++) { + fwrite($this->_filehandle, $marker); } - for($i=$used_blocks; $i <= $total_blocks; $i++) - { - fwrite($this->_filehandle,$unused); + for ($i=$used_blocks; $i <= $total_blocks; $i++) { + fwrite($this->_filehandle, $unused); } } @@ -348,16 +337,14 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR * @param integer $size size of the property storage. * @access private */ - function _writePps($name,$type,$dir,$start,$size) + function _writePps($name, $type, $dir, $start, $size) { $length = 0; $rawname = ''; - if ($name != '') - { + if ($name != '') { $name = $name . "\0"; - for($i=0;$i_filehandle,$rawname); - for($i=0; $i < (64 -$length); $i++) { - fwrite($this->_filehandle,$zero); + fwrite($this->_filehandle, $rawname); + for ($i = 0; $i < (64 -$length); $i++) { + fwrite($this->_filehandle, $zero); } - fwrite($this->_filehandle,$pps_sizeofname); - fwrite($this->_filehandle,$pps_type); - fwrite($this->_filehandle,$pps_prev); - fwrite($this->_filehandle,$pps_next); - fwrite($this->_filehandle,$pps_dir); - for($i=0; $i < 5; $i++) { - fwrite($this->_filehandle,$unknown1); + fwrite($this->_filehandle, $pps_sizeofname); + fwrite($this->_filehandle, $pps_type); + fwrite($this->_filehandle, $pps_prev); + fwrite($this->_filehandle, $pps_next); + fwrite($this->_filehandle, $pps_dir); + for ($i = 0; $i < 5; $i++) { + fwrite($this->_filehandle, $unknown1); } - fwrite($this->_filehandle,$pps_ts1s); - fwrite($this->_filehandle,$pps_ts1d); - fwrite($this->_filehandle,$pps_ts2d); - fwrite($this->_filehandle,$pps_ts2d); - fwrite($this->_filehandle,$pps_sb); - fwrite($this->_filehandle,$pps_size); - fwrite($this->_filehandle,$unknown1); + fwrite($this->_filehandle, $pps_ts1s); + fwrite($this->_filehandle, $pps_ts1d); + fwrite($this->_filehandle, $pps_ts2d); + fwrite($this->_filehandle, $pps_ts2d); + fwrite($this->_filehandle, $pps_sb); + fwrite($this->_filehandle, $pps_size); + fwrite($this->_filehandle, $unknown1); } /** @@ -411,16 +398,14 @@ class Spreadsheet_Excel_Writer_OLEwriter extends PEAR { $biffsize = $this->_biffsize; if ($biffsize < 4096) { - $min_size = 4096; - } - else { + $min_size = 4096; + } else { $min_size = 512; } - if ($biffsize % $min_size != 0) - { + if ($biffsize % $min_size != 0) { $padding = $min_size - ($biffsize % $min_size); - for($i=0; $i < $padding; $i++) { - fwrite($this->_filehandle,"\0"); + for ($i = 0; $i < $padding; $i++) { + fwrite($this->_filehandle, "\0"); } } } diff --git a/Writer/Parser.php b/Writer/Parser.php index 9e5866c..0d2f3ec 100644 --- a/Writer/Parser.php +++ b/Writer/Parser.php @@ -25,75 +25,75 @@ /** * @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', "<>"); -require_once('PEAR.php'); +require_once 'PEAR.php'; /** * Class for parsing Excel formulas @@ -538,61 +538,39 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR */ function _convert($token) { - if (preg_match("/^\"[^\"]{0,255}\"$/", $token)) - { + if (preg_match("/^\"[^\"]{0,255}\"$/", $token)) { return $this->_convertString($token); - } - elseif (is_numeric($token)) - { + } elseif (is_numeric($token)) { return $this->_convertNumber($token); - } - // match references like A1 or $A$1 - elseif (preg_match('/^\$?([A-Ia-i]?[A-Za-z])\$?(\d+)$/',$token)) - { + } elseif (preg_match('/^\$?([A-Ia-i]?[A-Za-z])\$?(\d+)$/',$token)) { + // match references like A1 or $A$1 return $this->_convertRef2d($token); - } - // match external references like Sheet1!A1 or Sheet1:Sheet2!A1 - elseif (preg_match("/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z](\d+)$/",$token)) - { + } elseif (preg_match("/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z](\d+)$/",$token)) { + // match external references like Sheet1!A1 or Sheet1:Sheet2!A1 return $this->_convertRef3d($token); - } - // match external references like Sheet1!A1 or Sheet1:Sheet2!A1 - elseif (preg_match("/^'\w+(\:\w+)?'\![A-Ia-i]?[A-Za-z](\d+)$/",$token)) - { + } elseif (preg_match("/^'\w+(\:\w+)?'\![A-Ia-i]?[A-Za-z](\d+)$/",$token)) { + // match external references like Sheet1!A1 or Sheet1:Sheet2!A1 return $this->_convertRef3d($token); - } - // match ranges like A1:B2 - elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)\:(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/",$token)) - { + } elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)\:(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/",$token)) { + // match ranges like A1:B2 return $this->_convertRange2d($token); - } - // match ranges like A1..B2 - elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/",$token)) - { + } elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/",$token)) { + // match ranges like A1..B2 return $this->_convertRange2d($token); - } - // match external ranges like Sheet1!A1 or Sheet1:Sheet2!A1:B2 - elseif (preg_match("/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?(\d+)\:([A-Ia-i]?[A-Za-z])?(\d+)$/",$token)) - { + } elseif (preg_match("/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?(\d+)\:([A-Ia-i]?[A-Za-z])?(\d+)$/",$token)) { + // match external ranges like Sheet1!A1 or Sheet1:Sheet2!A1:B2 return $this->_convertRange3d($token); - } - // match external ranges like 'Sheet1'!A1 or 'Sheet1:Sheet2'!A1:B2 - elseif (preg_match("/^'\w+(\:\w+)?'\!([A-Ia-i]?[A-Za-z])?(\d+)\:([A-Ia-i]?[A-Za-z])?(\d+)$/",$token)) - { + } elseif (preg_match("/^'\w+(\:\w+)?'\!([A-Ia-i]?[A-Za-z])?(\d+)\:([A-Ia-i]?[A-Za-z])?(\d+)$/",$token)) { + // match external ranges like 'Sheet1'!A1 or 'Sheet1:Sheet2'!A1:B2 return $this->_convertRange3d($token); - } - elseif (isset($this->ptg[$token])) // operators (including parentheses) - { + } elseif (isset($this->ptg[$token])) { + // operators (including parentheses) return pack("C", $this->ptg[$token]); - } - // commented so argument number can be processed correctly. See toReversePolish(). - /*elseif (preg_match("/[A-Z0-9\xc0-\xdc\.]+/",$token)) - { - return($this->_convertFunction($token,$this->_func_args)); - }*/ - // if it's an argument, ignore the token (the argument remains) - elseif ($token == 'arg') - { + /*} elseif (preg_match("/[A-Z0-9\xc0-\xdc\.]+/",$token)) { + // commented so argument number can be processed correctly. See toReversePolish(). + return($this->_convertFunction($token,$this->_func_args));*/ + } elseif ($token == 'arg') { + // if it's an argument, ignore the token (the argument remains) return ''; } // TODO: use real error codes @@ -610,9 +588,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR // Integer in the range 0..2**16-1 if ((preg_match("/^\d+$/",$num)) and ($num <= 65535)) { return pack("Cv", $this->ptg['ptgInt'], $num); - } - else // A float - { + } else { // A float if ($this->_byte_order) { // if it's Big Endian $num = strrev($num); } @@ -637,8 +613,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR } if ($this->_BIFF_version == 0x0500) { return pack("CC", $this->ptg['ptgStr'], strlen($string)).$string; - } - elseif ($this->_BIFF_version == 0x0600) { + } elseif ($this->_BIFF_version == 0x0600) { $encoding = 0; // TODO: Unicode support return pack("CCC", $this->ptg['ptgStr'], strlen($string), $encoding).$string; } @@ -681,12 +656,10 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR // Split the range into 2 cell refs if (preg_match("/^([A-Ia-i]?[A-Za-z])(\d+)\:([A-Ia-i]?[A-Za-z])(\d+)$/",$range)) { list($cell1, $cell2) = split(':', $range); - } - elseif (preg_match("/^([A-Ia-i]?[A-Za-z])(\d+)\.\.([A-Ia-i]?[A-Za-z])(\d+)$/",$range)) { + } elseif (preg_match("/^([A-Ia-i]?[A-Za-z])(\d+)\.\.([A-Ia-i]?[A-Za-z])(\d+)$/",$range)) { list($cell1, $cell2) = split('\.\.', $range); - } - else { + } else { // TODO: use real error codes return $this->raiseError("Unknown range separator", 0, PEAR_ERROR_DIE); } @@ -706,14 +679,11 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR // The ptg value depends on the class of the ptg. if ($class == 0) { $ptgArea = pack("C", $this->ptg['ptgArea']); - } - elseif ($class == 1) { + } elseif ($class == 1) { $ptgArea = pack("C", $this->ptg['ptgAreaV']); - } - elseif ($class == 2) { + } elseif ($class == 2) { $ptgArea = pack("C", $this->ptg['ptgAreaA']); - } - else { + } else { // TODO: use real error codes return $this->raiseError("Unknown class $class", 0, PEAR_ERROR_DIE); } @@ -741,8 +711,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR if (PEAR::isError($ext_ref)) { return $ext_ref; } - } - elseif ($this->_BIFF_version == 0x0600) { + } elseif ($this->_BIFF_version == 0x0600) { $ext_ref = $this->_getRefIndex($ext_ref); if (PEAR::isError($ext_ref)) { return $ext_ref; @@ -753,8 +722,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR list($cell1, $cell2) = split(':', $range); // Convert the cell references - if (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/", $cell1)) - { + if (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/", $cell1)) { $cell_array1 = $this->_cellToPackedRowcol($cell1); if (PEAR::isError($cell_array1)) { return $cell_array1; @@ -765,8 +733,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR return $cell_array2; } list($row2, $col2) = $cell_array2; - } - else { // It's a rows range (like 26:27) + } else { // It's a rows range (like 26:27) $cells_array = $this->_rangeToPackedRange($cell1.':'.$cell2); if (PEAR::isError($cells_array)) { return $cells_array; @@ -777,14 +744,11 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR // The ptg value depends on the class of the ptg. if ($class == 0) { $ptgArea = pack("C", $this->ptg['ptgArea3d']); - } - elseif ($class == 1) { + } elseif ($class == 1) { $ptgArea = pack("C", $this->ptg['ptgArea3dV']); - } - elseif ($class == 2) { + } elseif ($class == 2) { $ptgArea = pack("C", $this->ptg['ptgArea3dA']); - } - else { + } else { return $this->raiseError("Unknown class $class", 0, PEAR_ERROR_DIE); } @@ -812,14 +776,11 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR // The ptg value depends on the class of the ptg. if ($class == 0) { $ptgRef = pack("C", $this->ptg['ptgRef']); - } - elseif ($class == 1) { + } elseif ($class == 1) { $ptgRef = pack("C", $this->ptg['ptgRefV']); - } - elseif ($class == 2) { + } elseif ($class == 2) { $ptgRef = pack("C", $this->ptg['ptgRefA']); - } - else { + } else { // TODO: use real error codes return $this->raiseError("Unknown class $class"); } @@ -847,8 +808,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR if (PEAR::isError($ext_ref)) { return $ext_ref; } - } - elseif ($this->_BIFF_version == 0x0600) { + } elseif ($this->_BIFF_version == 0x0600) { $ext_ref = $this->_getRefIndex($ext_ref); if (PEAR::isError($ext_ref)) { return $ext_ref; @@ -861,14 +821,11 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR // The ptg value depends on the class of the ptg. if ($class == 0) { $ptgRef = pack("C", $this->ptg['ptgRef3d']); - } - elseif ($class == 1) { + } elseif ($class == 1) { $ptgRef = pack("C", $this->ptg['ptgRef3dV']); - } - elseif ($class == 2) { + } elseif ($class == 2) { $ptgRef = pack("C", $this->ptg['ptgRef3dA']); - } - else { + } else { return $this->raiseError("Unknown class $class", 0, PEAR_ERROR_DIE); } @@ -889,8 +846,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR $ext_ref = preg_replace("/'$/", '', $ext_ref); // Remove trailing ' if any. // Check if there is a sheet range eg., Sheet1:Sheet2. - if (preg_match("/:/", $ext_ref)) - { + if (preg_match("/:/", $ext_ref)) { list($sheet_name1, $sheet_name2) = split(':', $ext_ref); $sheet1 = $this->_getSheetIndex($sheet_name1); @@ -906,9 +862,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR if ($sheet1 > $sheet2) { list($sheet1, $sheet2) = array($sheet2, $sheet1); } - } - else // Single sheet name only. - { + } else { // Single sheet name only. $sheet1 = $this->_getSheetIndex($ext_ref); if ($sheet1 == -1) { return $this->raiseError("Unknown sheet name $ext_ref in formula"); @@ -938,8 +892,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR $ext_ref = preg_replace("/'$/", '', $ext_ref); // Remove trailing ' if any. // Check if there is a sheet range eg., Sheet1:Sheet2. - if (preg_match("/:/", $ext_ref)) - { + if (preg_match("/:/", $ext_ref)) { list($sheet_name1, $sheet_name2) = split(':', $ext_ref); $sheet1 = $this->_getSheetIndex($sheet_name1); @@ -955,9 +908,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR if ($sheet1 > $sheet2) { list($sheet1, $sheet2) = array($sheet2, $sheet1); } - } - else // Single sheet name only. - { + } else { // Single sheet name only. $sheet1 = $this->_getSheetIndex($ext_ref); if ($sheet1 == -1) { return $this->raiseError("Unknown sheet name $ext_ref in formula"); @@ -970,16 +921,14 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR $ref = pack('vvv', $supbook_index, $sheet1, $sheet2); $total_references = count($this->_references); $index = -1; - for ($i = 0; $i < $total_references; $i++) - { + for ($i = 0; $i < $total_references; $i++) { if ($ref == $this->_references[$i]) { $index = $i; break; } } // if REF was not found add it to references array - if ($index == -1) - { + if ($index == -1) { $this->_references[$total_references] = $ref; $index = $total_references; } @@ -999,8 +948,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR { if (!isset($this->_ext_sheets[$sheet_name])) { return -1; - } - else { + } else { return $this->_ext_sheets[$sheet_name]; } } @@ -1044,8 +992,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR $row |= $col_rel << 14; $row |= $row_rel << 15; $col = pack('C', $col); - } - elseif ($this->_BIFF_version == 0x0600) { + } elseif ($this->_BIFF_version == 0x0600) { $col |= $col_rel << 14; $col |= $row_rel << 15; $col = pack('v', $col); @@ -1089,8 +1036,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR $row2 |= $row2_rel << 15; $col1 = pack('C', $col1); $col2 = pack('C', $col2); - } - elseif ($this->_BIFF_version == 0x0600) { + } elseif ($this->_BIFF_version == 0x0600) { $col1 |= $row1_rel << 15; $col2 |= $row2_rel << 15; $col1 = pack('v', $col1); @@ -1123,8 +1069,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR // Convert base26 column string to a number. $expn = strlen($col_ref) - 1; $col = 0; - for ($i=0; $i < strlen($col_ref); $i++) - { + for ($i = 0; $i < strlen($col_ref); $i++) { $col += (ord($col_ref{$i}) - ord('A') + 1) * pow(26, $expn); $expn--; } @@ -1145,8 +1090,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR { $i = $this->_current_char; // eat up white spaces - if ($i < strlen($this->_formula)) - { + if ($i < strlen($this->_formula)) { while ($this->_formula{$i} == " ") { $i++; } @@ -1155,17 +1099,14 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR } $token = ""; } - while ($i < strlen($this->_formula)) - { + while ($i < strlen($this->_formula)) { $token .= $this->_formula{$i}; if ($i < strlen($this->_formula) - 1) { $this->_lookahead = $this->_formula{$i+1}; - } - else { + } else { $this->_lookahead = ''; } - if ($this->_match($token) != '') - { + if ($this->_match($token) != '') { //if ($i < strlen($this->_formula) - 1) { // $this->_lookahead = $this->_formula{$i+1}; //} @@ -1175,9 +1116,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR } if ($i < strlen($this->_formula) - 2) { $this->_lookahead = $this->_formula{$i+2}; - } - // if we run out of characters _lookahead becomes empty - else { + } else { // if we run out of characters _lookahead becomes empty $this->_lookahead = ''; } $i++; @@ -1194,8 +1133,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR */ function _match($token) { - switch($token) - { + switch($token) { case SPREADSHEET_EXCEL_WRITER_ADD: return $token; break; @@ -1247,66 +1185,56 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR break; default: // if it's a reference - if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/',$token) and - !ereg("[0-9]",$this->_lookahead) and - ($this->_lookahead != ':') and ($this->_lookahead != '.') and + if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/', $token) && + !ereg("[0-9]", $this->_lookahead) && + ($this->_lookahead != ':') && ($this->_lookahead != '.') && ($this->_lookahead != '!')) { return $token; - } - // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1) - elseif (preg_match("/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z][0-9]+$/",$token) and - !ereg("[0-9]",$this->_lookahead) and - ($this->_lookahead != ':') and ($this->_lookahead != '.')) + } elseif (preg_match("/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z][0-9]+$/", $token) && + !ereg("[0-9]", $this->_lookahead) && + ($this->_lookahead != ':') && ($this->_lookahead != '.')) { + // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1) return $token; - } - // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1) - elseif (preg_match("/^'\w+(\:\w+)?'\![A-Ia-i]?[A-Za-z][0-9]+$/",$token) and - !ereg("[0-9]",$this->_lookahead) and - ($this->_lookahead != ':') and ($this->_lookahead != '.')) + } elseif (preg_match("/^'\w+(\:\w+)?'\![A-Ia-i]?[A-Za-z][0-9]+$/", $token) && + !ereg("[0-9]", $this->_lookahead) && + ($this->_lookahead != ':') && ($this->_lookahead != '.')) { + // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1) 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 - !ereg("[0-9]",$this->_lookahead)) + } elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/", $token) && + !ereg("[0-9]", $this->_lookahead)) { + // if it's a range (A1:A2) 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 - !ereg("[0-9]",$this->_lookahead)) + } elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/", $token) && + !ereg("[0-9]", $this->_lookahead)) { + // if it's a range (A1..A2) return $token; - } - // If it's an external range like Sheet1!A1 or Sheet1:Sheet2!A1:B2 - elseif (preg_match("/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/",$token) and - !ereg("[0-9]",$this->_lookahead)) + } elseif (preg_match("/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/", $token) && + !ereg("[0-9]", $this->_lookahead)) { + // If it's an external range like Sheet1!A1 or Sheet1:Sheet2!A1:B2 return $token; - } - // If it's an external range like 'Sheet1'!A1 or 'Sheet1:Sheet2'!A1:B2 - elseif (preg_match("/^'\w+(\:\w+)?'\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/",$token) and - !ereg("[0-9]",$this->_lookahead)) + } elseif (preg_match("/^'\w+(\:\w+)?'\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/", $token) && + !ereg("[0-9]", $this->_lookahead)) { + // If it's an external range like 'Sheet1'!A1 or 'Sheet1:Sheet2'!A1:B2 return $token; - } - // If it's a number (check that it's not a sheet name or range) - elseif (is_numeric($token) and - (!is_numeric($token.$this->_lookahead) or ($this->_lookahead == '')) and - ($this->_lookahead != '!') and ($this->_lookahead != ':')) + } elseif (is_numeric($token) && + (!is_numeric($token.$this->_lookahead) || ($this->_lookahead == '')) && + ($this->_lookahead != '!') && ($this->_lookahead != ':')) { + // If it's a number (check that it's not a sheet name or range) return $token; - } - // If it's a string (of maximum 255 characters) - elseif (ereg("^\"[^\"]{0,255}\"$",$token)) - { + } elseif (ereg("^\"[^\"]{0,255}\"$", $token)) { + // If it's a string (of maximum 255 characters) return $token; - } - // if it's a function call - elseif (eregi("^[A-Z0-9\xc0-\xdc\.]+$",$token) and ($this->_lookahead == "(")) + } elseif (eregi("^[A-Z0-9\xc0-\xdc\.]+$", $token) && ($this->_lookahead == "(")) { + // if it's a function call return $token; } return ''; @@ -1347,53 +1275,42 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR if (PEAR::isError($result)) { return $result; } - if ($this->_current_token == SPREADSHEET_EXCEL_WRITER_LT) - { + if ($this->_current_token == SPREADSHEET_EXCEL_WRITER_LT) { $this->_advance(); $result2 = $this->_expression(); if (PEAR::isError($result2)) { return $result2; } $result = $this->_createTree('ptgLT', $result, $result2); - } - elseif ($this->_current_token == SPREADSHEET_EXCEL_WRITER_GT) - { + } elseif ($this->_current_token == SPREADSHEET_EXCEL_WRITER_GT) { $this->_advance(); $result2 = $this->_expression(); if (PEAR::isError($result2)) { return $result2; } $result = $this->_createTree('ptgGT', $result, $result2); - } - elseif ($this->_current_token == SPREADSHEET_EXCEL_WRITER_LE) - { + } elseif ($this->_current_token == SPREADSHEET_EXCEL_WRITER_LE) { $this->_advance(); $result2 = $this->_expression(); if (PEAR::isError($result2)) { return $result2; } $result = $this->_createTree('ptgLE', $result, $result2); - } - elseif ($this->_current_token == SPREADSHEET_EXCEL_WRITER_GE) - { + } elseif ($this->_current_token == SPREADSHEET_EXCEL_WRITER_GE) { $this->_advance(); $result2 = $this->_expression(); if (PEAR::isError($result2)) { return $result2; } $result = $this->_createTree('ptgGE', $result, $result2); - } - elseif ($this->_current_token == SPREADSHEET_EXCEL_WRITER_EQ) - { + } elseif ($this->_current_token == SPREADSHEET_EXCEL_WRITER_EQ) { $this->_advance(); $result2 = $this->_expression(); if (PEAR::isError($result2)) { return $result2; } $result = $this->_createTree('ptgEQ', $result, $result2); - } - elseif ($this->_current_token == SPREADSHEET_EXCEL_WRITER_NE) - { + } elseif ($this->_current_token == SPREADSHEET_EXCEL_WRITER_NE) { $this->_advance(); $result2 = $this->_expression(); if (PEAR::isError($result2)) { @@ -1420,9 +1337,8 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR $result = $this->_createTree($this->_current_token, '', ''); $this->_advance(); return $result; - } - // catch "-" Term - elseif ($this->_current_token == SPREADSHEET_EXCEL_WRITER_SUB) { + } elseif ($this->_current_token == SPREADSHEET_EXCEL_WRITER_SUB) { + // catch "-" Term $this->_advance(); $result2 = $this->_expression(); $result = $this->_createTree('ptgUminus', $result2, ''); @@ -1432,20 +1348,17 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR if (PEAR::isError($result)) { return $result; } - while (($this->_current_token == SPREADSHEET_EXCEL_WRITER_ADD) or + while (($this->_current_token == SPREADSHEET_EXCEL_WRITER_ADD) || ($this->_current_token == SPREADSHEET_EXCEL_WRITER_SUB)) { - if ($this->_current_token == SPREADSHEET_EXCEL_WRITER_ADD) - { + if ($this->_current_token == SPREADSHEET_EXCEL_WRITER_ADD) { $this->_advance(); $result2 = $this->_term(); if (PEAR::isError($result2)) { return $result2; } $result = $this->_createTree('ptgAdd', $result, $result2); - } - else - { + } else { $this->_advance(); $result2 = $this->_term(); if (PEAR::isError($result2)) { @@ -1484,7 +1397,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR if (PEAR::isError($result)) { return $result; } - while (($this->_current_token == SPREADSHEET_EXCEL_WRITER_MUL) or + while (($this->_current_token == SPREADSHEET_EXCEL_WRITER_MUL) || ($this->_current_token == SPREADSHEET_EXCEL_WRITER_DIV)) { if ($this->_current_token == SPREADSHEET_EXCEL_WRITER_MUL) @@ -1495,9 +1408,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR return $result2; } $result = $this->_createTree('ptgMul', $result, $result2); - } - else - { + } else { $this->_advance(); $result2 = $this->_fact(); if (PEAR::isError($result2)) { @@ -1522,8 +1433,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR */ function _fact() { - if ($this->_current_token == SPREADSHEET_EXCEL_WRITER_OPEN) - { + if ($this->_current_token == SPREADSHEET_EXCEL_WRITER_OPEN) { $this->_advance(); // eat the "(" $result = $this->_parenthesizedExpression(); if ($this->_current_token != SPREADSHEET_EXCEL_WRITER_CLOSE) { @@ -1533,57 +1443,43 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR return $result; } // if it's a reference - if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/',$this->_current_token)) - { + if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/', $this->_current_token)) { $result = $this->_createTree($this->_current_token, '', ''); $this->_advance(); return $result; - } - // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1) - elseif (preg_match("/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z][0-9]+$/",$this->_current_token)) - { + } elseif (preg_match("/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z][0-9]+$/", $this->_current_token)) { + // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1) $result = $this->_createTree($this->_current_token, '', ''); $this->_advance(); return $result; - } - // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1) - elseif (preg_match("/^'\w+(\:\w+)?'\![A-Ia-i]?[A-Za-z][0-9]+$/",$this->_current_token)) - { + } elseif (preg_match("/^'\w+(\:\w+)?'\![A-Ia-i]?[A-Za-z][0-9]+$/", $this->_current_token)) { + // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1) $result = $this->_createTree($this->_current_token, '', ''); $this->_advance(); 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 - preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$this->_current_token)) + } elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/", $this->_current_token) || + preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/", $this->_current_token)) { + // if it's a range $result = $this->_current_token; $this->_advance(); return $result; - } - // If it's an external range (Sheet1!A1 or Sheet1!A1:B2) - elseif (preg_match("/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/",$this->_current_token)) - { + } elseif (preg_match("/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/", $this->_current_token)) { + // If it's an external range (Sheet1!A1 or Sheet1!A1:B2) $result = $this->_current_token; $this->_advance(); return $result; - } - // If it's an external range ('Sheet1'!A1 or 'Sheet1'!A1:B2) - elseif (preg_match("/^'\w+(\:\w+)?'\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/",$this->_current_token)) - { + } elseif (preg_match("/^'\w+(\:\w+)?'\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/",$this->_current_token)) { + // If it's an external range ('Sheet1'!A1 or 'Sheet1'!A1:B2) $result = $this->_current_token; $this->_advance(); return $result; - } - elseif (is_numeric($this->_current_token)) - { + } elseif (is_numeric($this->_current_token)) { $result = $this->_createTree($this->_current_token, '', ''); $this->_advance(); return $result; - } - // if it's a function call - elseif (eregi("^[A-Z0-9\xc0-\xdc\.]+$",$this->_current_token)) - { + } elseif (eregi("^[A-Z0-9\xc0-\xdc\.]+$",$this->_current_token)) { + // if it's a function call $result = $this->_func(); return $result; } @@ -1605,16 +1501,13 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR $function = $this->_current_token; $this->_advance(); $this->_advance(); // eat the "(" - while ($this->_current_token != ')') - { - if ($num_args > 0) - { + while ($this->_current_token != ')') { + if ($num_args > 0) { if ($this->_current_token == SPREADSHEET_EXCEL_WRITER_COMA || $this->_current_token == SPREADSHEET_EXCEL_WRITER_SEMICOLON) { $this->_advance(); // eat the "," or ";" - } - else { + } else { return $this->raiseError("Syntax error: comma expected in ". "function $function, arg #{$num_args}"); } @@ -1623,9 +1516,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR return $result2; } $result = $this->_createTree('arg', $result, $result2); - } - else // first argument - { + } else { // first argument $result2 = $this->_condition(); if (PEAR::isError($result2)) { return $result2; @@ -1690,36 +1581,29 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR function toReversePolish($tree = array()) { $polish = ""; // the string we are going to return - if (empty($tree)) // If it's the first call use _parse_tree - { + if (empty($tree)) { // If it's the first call use _parse_tree $tree = $this->_parse_tree; } - if (is_array($tree['left'])) - { + if (is_array($tree['left'])) { $converted_tree = $this->toReversePolish($tree['left']); if (PEAR::isError($converted_tree)) { return $converted_tree; } $polish .= $converted_tree; - } - elseif ($tree['left'] != '') // It's a final node - { + } elseif ($tree['left'] != '') { // It's a final node $converted_tree = $this->_convert($tree['left']); if (PEAR::isError($converted_tree)) { return $converted_tree; } $polish .= $converted_tree; } - if (is_array($tree['right'])) - { + if (is_array($tree['right'])) { $converted_tree = $this->toReversePolish($tree['right']); if (PEAR::isError($converted_tree)) { return $converted_tree; } $polish .= $converted_tree; - } - elseif ($tree['right'] != '') // It's a final node - { + } elseif ($tree['right'] != '') { // It's a final node $converted_tree = $this->_convert($tree['right']); if (PEAR::isError($converted_tree)) { return $converted_tree; @@ -1727,17 +1611,16 @@ 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 (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 + if (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/",$tree['value']) && + !preg_match('/^([A-Ia-i]?[A-Za-z])(\d+)$/',$tree['value']) && + !preg_match("/^[A-Ia-i]?[A-Za-z](\d+)\.\.[A-Ia-i]?[A-Za-z](\d+)$/",$tree['value']) && + !is_numeric($tree['value']) && !isset($this->ptg[$tree['value']])) { // left subtree for a function is always an array. if ($tree['left'] != '') { $left_tree = $this->toReversePolish($tree['left']); - } - else { + } else { $left_tree = ''; } if (PEAR::isError($left_tree)) { @@ -1745,9 +1628,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR } // add it's left subtree and return. return $left_tree.$this->_convertFunction($tree['value'], $tree['right']); - } - else - { + } else { $converted_tree = $this->_convert($tree['value']); if (PEAR::isError($converted_tree)) { return $converted_tree; diff --git a/Writer/Validator.php b/Writer/Validator.php index 6d99afe..241951e 100644 --- a/Writer/Validator.php +++ b/Writer/Validator.php @@ -150,20 +150,25 @@ class Spreadsheet_Excel_Writer_Validator return true; } - function _getOptions() - { - $options = $this->_type; - $options |= $this->_style << 3; - if($this->_fixedList) - $options |= 0x80; - if($this->_blank) - $options |= 0x100; - if(!$this->_incell) - $options |= 0x200; - if($this->_showprompt) - $options |= 0x40000; - if($this->_showerror) - $options |= 0x80000; + function _getOptions() + { + $options = $this->_type; + $options |= $this->_style << 3; + if ($this->_fixedList) { + $options |= 0x80; + } + if ($this->_blank) { + $options |= 0x100; + } + if (!$this->_incell) { + $options |= 0x200; + } + if ($this->_showprompt) { + $options |= 0x40000; + } + if ($this->_showerror) { + $options |= 0x80000; + } $options |= $this->_operator << 20; return $options; diff --git a/Writer/Workbook.php b/Writer/Workbook.php index 5962089..8bd0095 100644 --- a/Writer/Workbook.php +++ b/Writer/Workbook.php @@ -32,12 +32,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -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'); -require_once('OLE/PPS/Root.php'); -require_once('OLE/PPS/File.php'); +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'; +require_once 'OLE/PPS/Root.php'; +require_once 'OLE/PPS/File.php'; /** * Class for generating Excel Spreadsheets @@ -327,8 +327,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // Check that the worksheet name doesn't already exist: a fatal Excel error. $total_worksheets = count($this->_worksheets); - for ($i=0; $i < $total_worksheets; $i++) - { + for ($i = 0; $i < $total_worksheets; $i++) { if ($name == $this->_worksheets[$i]->getName()) { return $this->raiseError("Worksheet '$name' already exists"); } @@ -357,7 +356,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri */ function &addFormat($properties = array()) { - $format = new Spreadsheet_Excel_Writer_Format($this->_BIFF_version, $this->_xf_index,$properties); + $format = new Spreadsheet_Excel_Writer_Format($this->_BIFF_version, $this->_xf_index, $properties); $this->_xf_index += 1; $this->_formats[] = &$format; return $format; @@ -371,7 +370,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri */ function &addValidator() { - include_once('Spreadsheet/Excel/Writer/Validator.php'); + include_once 'Spreadsheet/Excel/Writer/Validator.php'; /* FIXME: check for successful inclusion*/ $valid = new Spreadsheet_Excel_Writer_Validator($this->_parser); return $valid; @@ -387,7 +386,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri * @param integer $blue blue RGB value [0-255] * @return integer The palette index for the custom color */ - function setCustomColor($index,$red,$green,$blue) + function setCustomColor($index, $red, $green, $blue) { // Match a HTML #xxyyzz style parameter /*if (defined $_[1] and $_[1] =~ /^#(\w\w)(\w\w)(\w\w)/ ) { @@ -401,9 +400,9 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri } // Check that the colour components are in the right range - if ( ($red < 0 or $red > 255) or - ($green < 0 or $green > 255) or - ($blue < 0 or $blue > 255) ) + if (($red < 0 or $red > 255) || + ($green < 0 or $green > 255) || + ($blue < 0 or $blue > 255)) { return $this->raiseError("Color component outside range: 0 <= color <= 255"); } @@ -499,7 +498,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // Calculate the number of selected worksheet tabs and call the finalization // methods for each worksheet $total_worksheets = count($this->_worksheets); - for ($i=0; $i < $total_worksheets; $i++) { + for ($i = 0; $i < $total_worksheets; $i++) { if ($this->_worksheets[$i]->selected) { $this->_selected++; } @@ -528,7 +527,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $this->_calcSheetOffsets(); // Add BOUNDSHEET records - for ($i=0; $i < $total_worksheets; $i++) { + for ($i = 0; $i < $total_worksheets; $i++) { $this->_storeBoundsheet($this->_worksheets[$i]->name,$this->_worksheets[$i]->offset); } @@ -589,8 +588,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri } $OLE->append($this->_data); $total_worksheets = count($this->_worksheets); - for ($i = 0; $i < $total_worksheets; $i++) - { + for ($i = 0; $i < $total_worksheets; $i++) { while ($tmp = $this->_worksheets[$i]->getData()) { $OLE->append($tmp); } @@ -615,8 +613,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri { if ($this->_BIFF_version == 0x0600) { $boundsheet_length = 12; // fixed length for a BOUNDSHEET record - } - else { + } else { $boundsheet_length = 11; } $EOF = 4; @@ -634,12 +631,12 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri } $total_worksheets = count($this->_worksheets); // add the length of the BOUNDSHEET records - for ($i=0; $i < $total_worksheets; $i++) { + for ($i = 0; $i < $total_worksheets; $i++) { $offset += $boundsheet_length + strlen($this->_worksheets[$i]->name); } $offset += $EOF; - for ($i=0; $i < $total_worksheets; $i++) { + for ($i = 0; $i < $total_worksheets; $i++) { $this->_worksheets[$i]->offset = $offset; $offset += $this->_worksheets[$i]->_datasize; } @@ -660,7 +657,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // 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++){ + for ($i = 1; $i <= 5; $i++){ $this->_append($font); } @@ -674,14 +671,12 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $fonts[$key] = 0; // Index of the default font $total_formats = count($this->_formats); - for ($i=0; $i < $total_formats; $i++) - { + 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]; - } - else { + } else { // Add a new FONT record $fonts[$key] = $index; $this->_formats[$i]->font_index = $index; @@ -707,17 +702,15 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // 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++) - { + 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. // - if (!preg_match("/^0+\d/",$num_format)) - { - if (preg_match("/^\d+$/",$num_format)) { // built-in format + if (!preg_match("/^0+\d/", $num_format)) { + if (preg_match("/^\d+$/", $num_format)) { // built-in format continue; } } @@ -725,8 +718,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri if (isset($hash_num_formats[$num_format])) { // FORMAT has already been used $this->_formats[$i]->_num_format = $hash_num_formats[$num_format]; - } - else{ + } else{ // Add a new FORMAT $hash_num_formats[$num_format] = $index; $this->_formats[$i]->_num_format = $index; @@ -754,7 +746,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // The default font index is 0 // $format = $this->_tmp_format; - for ($i=0; $i <= 14; $i++) { + for ($i = 0; $i <= 14; $i++) { $xf = $format->getXf('style'); // Style XF $this->_append($xf); } @@ -764,7 +756,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // User defined XFs $total_formats = count($this->_formats); - for ($i=0; $i < $total_formats; $i++) { + for ($i = 0; $i < $total_formats; $i++) { $xf = $this->_formats[$i]->getXf('cell'); $this->_append($xf); } @@ -808,8 +800,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $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->_worksheets[$i]->print_rowmin)) - { + if (isset($this->_worksheets[$i]->print_rowmin)) { $this->_storeNameShort( $this->_worksheets[$i]->index, 0x06, // NAME type @@ -832,7 +823,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // Determine if row + col, row, col or nothing has been defined // and write the appropriate record // - if (isset($rowmin) and isset($colmin)) { + if (isset($rowmin) && isset($colmin)) { // Row and column titles have been defined. // Row title has been defined. $this->_storeNameLong( @@ -843,8 +834,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $colmin, $colmax ); - } - elseif (isset($rowmin)) { + } elseif (isset($rowmin)) { // Row title has been defined. $this->_storeNameShort( $this->_worksheets[$i]->index, @@ -854,8 +844,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri 0x00, 0xff ); - } - elseif (isset($colmin)) { + } elseif (isset($colmin)) { // Column title has been defined. $this->_storeNameShort( $this->_worksheets[$i]->index, @@ -865,8 +854,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $colmin, $colmax ); - } - else { + } else { // Print title hasn't been defined. } } @@ -941,8 +929,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $record = 0x0085; // Record identifier if ($this->_BIFF_version == 0x0600) { $length = 0x08 + strlen($sheetname); // Number of bytes to follow - } - else { + } else { $length = 0x07 + strlen($sheetname); // Number of bytes to follow } @@ -952,8 +939,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $header = pack("vv", $record, $length); if ($this->_BIFF_version == 0x0600) { $data = pack("Vvv", $offset, $grbit, $cch); - } - else { + } else { $data = pack("VvC", $offset, $grbit, $cch); } $this->_append($header.$data.$sheetname); @@ -1030,8 +1016,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri 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 } @@ -1040,8 +1025,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $header = pack("vv", $record, $length); if ($this->_BIFF_version == 0x0600) { $data = pack("vvC", $ifmt, $cch, $encoding); - } - elseif ($this->_BIFF_version == 0x0500) { + } elseif ($this->_BIFF_version == 0x0500) { $data = pack("vC", $ifmt, $cch); } $this->_append($header.$data.$format); @@ -1292,8 +1276,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri $data = ''; // The RGB data // Pack the RGB data - foreach($aref as $color) - { + foreach($aref as $color) { foreach($color as $byte) { $data .= pack("C",$byte); } @@ -1372,13 +1355,10 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // split string fits exactly into the remaining space. if ($block_length > 0) { $continue = 1; - } - else { + } else { $continue = 0; } - - } - else { + } else { // Store the max size for this block $this->_block_sizes[] = $written + $continue; @@ -1393,8 +1373,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // one or more CONTINUE blocks if ($block_length < $continue_limit) { $written = $block_length; - } - else { + } else { $written = 0; } } @@ -1504,12 +1483,10 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri // if ($block_length > 0) { $continue = 1; - } - else { + } else { $continue = 0; } - } - else { + } else { // Not enough space to start the string in the current block $block_length -= $continue_limit - $space_remaining - $continue; $continue = 0; @@ -1533,8 +1510,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri if ($block_length < $continue_limit) { $this->_append($string); $written = $block_length; - } - else { + } else { $written = 0; } } diff --git a/Writer/Worksheet.php b/Writer/Worksheet.php index 65a8258..cb3bf08 100644 --- a/Writer/Worksheet.php +++ b/Writer/Worksheet.php @@ -32,8 +32,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -require_once('Spreadsheet/Excel/Writer/Parser.php'); -require_once('Spreadsheet/Excel/Writer/BIFFwriter.php'); +require_once 'Spreadsheet/Excel/Writer/Parser.php'; +require_once 'Spreadsheet/Excel/Writer/BIFFwriter.php'; /** * Class for generating Excel Spreadsheets @@ -470,8 +470,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr if ( $fh) { // Store filehandle $this->_filehandle = $fh; - } - else { + } else { // If tmpfile() fails store data in memory $this->_using_tmpfile = false; } @@ -568,9 +567,8 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr } // Prepend the COLINFO records if they exist - if (!empty($this->_colinfo)) - { - for ($i=0; $i < count($this->_colinfo); $i++) { + if (!empty($this->_colinfo)) { + for ($i = 0; $i < count($this->_colinfo); $i++) { $this->_storeColinfo($this->_colinfo[$i]); } $this->_storeDefcol(); @@ -621,8 +619,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $buffer = 4096; // Return data stored in memory - if (isset($this->_data)) - { + if (isset($this->_data)) { $tmp = $this->_data; unset($this->_data); $fh = $this->_filehandle; @@ -632,8 +629,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr return $tmp; } // Return data stored on disk - if ($this->_using_tmpfile) - { + if ($this->_using_tmpfile) { if ($tmp = fread($this->_filehandle, $buffer)) { return $tmp; } @@ -654,7 +650,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr */ function setMerge($first_row, $first_col, $last_row, $last_col) { - if (($last_row < $first_row) or ($last_col < $first_col)) { + if (($last_row < $first_row) || ($last_col < $first_col)) { return; } // don't check rowmin, rowmax, etc... because we don't know when this @@ -965,8 +961,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $this->title_rowmin = $first_row; if (isset($last_row)) { //Second row is optional $this->title_rowmax = $last_row; - } - else { + } else { $this->title_rowmax = $first_row; } } @@ -983,8 +978,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $this->title_colmin = $first_col; if (isset($last_col)) { // Second col is optional $this->title_colmax = $last_col; - } - else { + } else { $this->title_colmax = $first_col; } } @@ -1092,8 +1086,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr function setZoom($scale = 100) { // Confine the scale to Excel's range - if ($scale < 10 or $scale > 400) - { + if ($scale < 10 || $scale > 400) { $this->raiseError("Zoom factor $scale outside range: 10 <= zoom <= 400"); $scale = 100; } @@ -1111,8 +1104,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr function setPrintScale($scale = 100) { // Confine the scale to Excel's range - if ($scale < 10 or $scale > 400) - { + if ($scale < 10 || $scale > 400) { $this->raiseError("Print scale $scale outside range: 10 <= zoom <= 400"); $scale = 100; } @@ -1139,37 +1131,29 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr @_ = $this->_substituteCellref(@_); }*/ - - // Match number if (preg_match("/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/",$token)) { + // Match number return $this->writeNumber($row,$col,$token,$format); - } - // Match http or ftp URL - elseif (preg_match("/^[fh]tt?p:\/\//",$token)) { + } elseif (preg_match("/^[fh]tt?p:\/\//",$token)) { + // Match http or ftp URL return $this->writeUrl($row, $col, $token, '', $format); - } - // Match mailto: - elseif (preg_match("/^mailto:/",$token)) { + } elseif (preg_match("/^mailto:/",$token)) { + // Match mailto: return $this->writeUrl($row, $col, $token, '', $format); - } - // Match internal or external sheet link - elseif (preg_match("/^(?:in|ex)ternal:/",$token)) { + } elseif (preg_match("/^(?:in|ex)ternal:/",$token)) { + // Match internal or external sheet link return $this->writeUrl($row, $col, $token, '', $format); - } - // Match formula - elseif (preg_match("/^=/",$token)) { + } elseif (preg_match("/^=/",$token)) { + // Match formula return $this->writeFormula($row, $col, $token, $format); - } - // Match formula - elseif (preg_match("/^@/",$token)) { + } elseif (preg_match("/^@/",$token)) { + // Match formula return $this->writeFormula($row, $col, $token, $format); - } - // Match blank - elseif ($token == '') { + } elseif ($token == '') { + // Match blank return $this->writeBlank($row,$col,$format); - } - // Default: match string - else { + } else { + // Default: match string return $this->writeString($row,$col,$token,$format); } } @@ -1239,8 +1223,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr { if ($format != 0) { return($format->getXfIndex()); - } - else { + } else { return(0x0F); } } @@ -1262,16 +1245,14 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr */ function _append($data) { - if ($this->_using_tmpfile) - { + if ($this->_using_tmpfile) { // Add CONTINUE records if necessary if (strlen($data) > $this->_limit) { $data = $this->_addContinue($data); } - fwrite($this->_filehandle,$data); + fwrite($this->_filehandle, $data); $this->_datasize += strlen($data); - } - else { + } else { parent::_append($data); } } @@ -1291,21 +1272,21 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $cell = strtoupper($cell); // Convert a column range: 'A:A' or 'B:G' - if (preg_match("/([A-I]?[A-Z]):([A-I]?[A-Z])/",$cell,$match)) { + if (preg_match("/([A-I]?[A-Z]):([A-I]?[A-Z])/", $cell, $match)) { list($no_use, $col1) = $this->_cellToRowcol($match[1] .'1'); // Add a dummy row list($no_use, $col2) = $this->_cellToRowcol($match[2] .'1'); // Add a dummy row return(array($col1, $col2)); } // Convert a cell range: 'A1:B7' - if (preg_match("/\$?([A-I]?[A-Z]\$?\d+):\$?([A-I]?[A-Z]\$?\d+)/",$cell,$match)) { + if (preg_match("/\$?([A-I]?[A-Z]\$?\d+):\$?([A-I]?[A-Z]\$?\d+)/", $cell, $match)) { list($row1, $col1) = $this->_cellToRowcol($match[1]); list($row2, $col2) = $this->_cellToRowcol($match[2]); return(array($row1, $col1, $row2, $col2)); } // Convert a cell reference: 'A1' or 'AD2000' - if (preg_match("/\$?([A-I]?[A-Z]\$?\d+)/",$cell)) { + if (preg_match("/\$?([A-I]?[A-Z]\$?\d+)/", $cell)) { list($row1, $col1) = $this->_cellToRowcol($match[1]); return(array($row1, $col1)); } @@ -1360,8 +1341,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr // split the plain text password in its component characters $chars = preg_split('//', $plaintext, -1, PREG_SPLIT_NO_EMPTY); - foreach($chars as $char) - { + foreach($chars as $char) { $value = ord($char) << $i; // shifted ASCII value $rotated_bits = $value >> 15; // rotated bits beyond bit 15 $value &= 0x7fff; // first 15 bits @@ -1427,36 +1407,29 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $xf = $this->_XF($format); // The cell format // Check that row and col are valid and store max and min values - if ($row >= $this->_xls_rowmax) - { + if ($row >= $this->_xls_rowmax) { return(-2); } - if ($col >= $this->_xls_colmax) - { + if ($col >= $this->_xls_colmax) { return(-2); } - if ($row < $this->_dim_rowmin) - { + if ($row < $this->_dim_rowmin) { $this->_dim_rowmin = $row; } - if ($row > $this->_dim_rowmax) - { + if ($row > $this->_dim_rowmax) { $this->_dim_rowmax = $row; } - if ($col < $this->_dim_colmin) - { + if ($col < $this->_dim_colmin) { $this->_dim_colmin = $col; } - if ($col > $this->_dim_colmax) - { + if ($col > $this->_dim_colmax) { $this->_dim_colmax = $col; } $header = pack("vv", $record, $length); $data = pack("vvv", $row, $col, $xf); $xl_double = pack("d", $num); - if ($this->_byte_order) // if it's Big Endian - { + if ($this->_byte_order) { // if it's Big Endian $xl_double = strrev($xl_double); } @@ -1492,33 +1465,26 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $str_error = 0; // Check that row and col are valid and store max and min values - if ($row >= $this->_xls_rowmax) - { + if ($row >= $this->_xls_rowmax) { return(-2); } - if ($col >= $this->_xls_colmax) - { + if ($col >= $this->_xls_colmax) { return(-2); } - if ($row < $this->_dim_rowmin) - { + if ($row < $this->_dim_rowmin) { $this->_dim_rowmin = $row; } - if ($row > $this->_dim_rowmax) - { + if ($row > $this->_dim_rowmax) { $this->_dim_rowmax = $row; } - if ($col < $this->_dim_colmin) - { + if ($col < $this->_dim_colmin) { $this->_dim_colmin = $col; } - if ($col > $this->_dim_colmax) - { + if ($col > $this->_dim_colmax) { $this->_dim_colmax = $col; } - if ($strlen > $this->_xls_strmax) // LABEL must be < 255 chars - { + if ($strlen > $this->_xls_strmax) { // LABEL must be < 255 chars $str = substr($str, 0, $this->_xls_strmax); $length = 0x0008 + $this->_xls_strmax; $strlen = $this->_xls_strmax; @@ -1610,28 +1576,22 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr //$length = 0x0006 + $note_length; // Bytes to follow // Check that row and col are valid and store max and min values - if ($row >= $this->_xls_rowmax) - { + if ($row >= $this->_xls_rowmax) { return(-2); } - if ($col >= $this->_xls_colmax) - { + if ($col >= $this->_xls_colmax) { return(-2); } - if ($row < $this->_dim_rowmin) - { + if ($row < $this->_dim_rowmin) { $this->_dim_rowmin = $row; } - if ($row > $this->_dim_rowmax) - { + if ($row > $this->_dim_rowmax) { $this->_dim_rowmax = $row; } - if ($col < $this->_dim_colmin) - { + if ($col < $this->_dim_colmin) { $this->_dim_colmin = $col; } - if ($col > $this->_dim_colmax) - { + if ($col > $this->_dim_colmax) { $this->_dim_colmax = $col; } @@ -1641,8 +1601,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $data = pack("vvv", $row, $col, $note_length); $this->_append($header.$data.substr($note, 0, 2048)); - for($i = $max_length; $i < $note_length; $i += $max_length) - { + for($i = $max_length; $i < $note_length; $i += $max_length) { $chunk = substr($note, $i, $max_length); $length = 0x0006 + strlen($chunk); $header = pack("vv", $record, $length); @@ -1672,8 +1631,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr function writeBlank($row, $col, $format) { // Don't write a blank cell unless it has a format - if ($format == 0) - { + if ($format == 0) { return(0); } @@ -1682,28 +1640,22 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $xf = $this->_XF($format); // The cell format // Check that row and col are valid and store max and min values - if ($row >= $this->_xls_rowmax) - { + if ($row >= $this->_xls_rowmax) { return(-2); } - if ($col >= $this->_xls_colmax) - { + if ($col >= $this->_xls_colmax) { return(-2); } - if ($row < $this->_dim_rowmin) - { + if ($row < $this->_dim_rowmin) { $this->_dim_rowmin = $row; } - if ($row > $this->_dim_rowmax) - { + if ($row > $this->_dim_rowmax) { $this->_dim_rowmax = $row; } - if ($col < $this->_dim_colmin) - { + if ($col < $this->_dim_colmin) { $this->_dim_colmin = $col; } - if ($col > $this->_dim_colmax) - { + if ($col > $this->_dim_colmax) { $this->_dim_colmax = $col; } @@ -1752,12 +1704,9 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr // Strip the '=' or '@' sign at the beginning of the formula string if (preg_match("/^=/",$formula)) { $formula = preg_replace("/(^=)/","",$formula); - } - elseif (preg_match("/^@/",$formula)) { + } elseif (preg_match("/^@/",$formula)) { $formula = preg_replace("/(^@)/","",$formula); - } - else - { + } else { // Error handling $this->writeString($row, $col, 'Unrecognised character for formula'); return -1; @@ -1765,15 +1714,13 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr // Parse the formula using the parser in Parser.php $error = $this->_parser->parse($formula); - if ($this->isError($error)) - { + if ($this->isError($error)) { $this->writeString($row, $col, $error->getMessage()); return -1; } $formula = $this->_parser->toReversePolish(); - if ($this->isError($formula)) - { + if ($this->isError($formula)) { $this->writeString($row, $col, $formula->getMessage()); return -1; } @@ -1880,7 +1827,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $str = $url; } $str_error = $this->writeString($row1, $col1, $str, $format); - if (($str_error == -2) or ($str_error == -3)) { + if (($str_error == -2) || ($str_error == -3)) { return $str_error; } @@ -1943,7 +1890,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $str = $url; } $str_error = $this->writeString($row1, $col1, $str, $format); - if (($str_error == -2) or ($str_error == -3)) { + if (($str_error == -2) || ($str_error == -3)) { return $str_error; } @@ -2017,7 +1964,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $str = preg_replace('[\#]', ' - ', $url); } $str_error = $this->writeString($row1, $col1, $str, $format); - if (($str_error == -2) or ($str_error == -3)) { + if (($str_error == -2) || ($str_error == -3)) { return $str_error; } @@ -2131,8 +2078,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr // Use setRow($row, NULL, $XF) to set XF format without setting height if ($height != NULL) { $miyRw = $height * 20; // row height - } - else { + } else { $miyRw = 0xff; // default row height is 256 } @@ -2180,8 +2126,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $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); @@ -2200,8 +2145,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $record = 0x023E; // Record identifier if ($this->_BIFF_version == 0x0500) { $length = 0x000A; // Number of bytes to follow - } - elseif ($this->_BIFF_version == 0x0600) { + } elseif ($this->_BIFF_version == 0x0600) { $length = 0x0012; } @@ -2241,8 +2185,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr 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; @@ -2292,26 +2235,22 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr } if (isset($col_array[2])) { $coldx = $col_array[2]; - } - else { + } else { $coldx = 8.43; } if (isset($col_array[3])) { $format = $col_array[3]; - } - else { + } else { $format = 0; } if (isset($col_array[4])) { $grbit = $col_array[4]; - } - else { + } else { $grbit = 0; } if (isset($col_array[5])) { $level = $col_array[5]; - } - else { + } else { $level = 0; } $record = 0x007D; // Record identifier @@ -2359,13 +2298,11 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr } // Swap last row/col for first row/col as necessary - if ($rwFirst > $rwLast) - { + if ($rwFirst > $rwLast) { list($rwFirst, $rwLast) = array($rwLast, $rwFirst); } - if ($colFirst > $colLast) - { + if ($colFirst > $colLast) { list($colFirst, $colLast) = array($colLast, $colFirst); } @@ -2443,8 +2380,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $length = 0x02; // The following 2 bytes $cch = 1; // The following byte $rgch = 0x02; // Self reference - } - else { + } else { $length = 0x02 + strlen($sheetname); $cch = strlen($sheetname); $rgch = 0x03; // Reference to a sheet in the current workbook @@ -2477,16 +2413,14 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $colLeft = $panes[3]; if (count($panes) > 4) { // if Active pane was received $pnnAct = $panes[4]; - } - else { + } else { $pnnAct = NULL; } $record = 0x0041; // Record identifier $length = 0x000A; // Number of bytes to follow // Code specific to frozen or thawed panes. - if ($this->_frozen) - { + if ($this->_frozen) { // Set default values for $rwTop and $colLeft if (!isset($rwTop)) { $rwTop = $y; @@ -2494,9 +2428,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr if (!isset($colLeft)) { $colLeft = $x; } - } - else - { + } else { // Set default values for $rwTop and $colLeft if (!isset($rwTop)) { $rwTop = 0; @@ -2518,16 +2450,19 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr // Determine which pane should be active. There is also the undocumented // option to override this should it be necessary: may be removed later. // - if (!isset($pnnAct)) - { - if ($x != 0 and $y != 0) + if (!isset($pnnAct)) { + if ($x != 0 && $y != 0) { $pnnAct = 0; // Bottom right - if ($x != 0 and $y == 0) + } + if ($x != 0 && $y == 0) { $pnnAct = 1; // Top right - if ($x == 0 and $y != 0) + } + if ($x == 0 && $y != 0) { $pnnAct = 2; // Bottom left - if ($x == 0 and $y == 0) + } + if ($x == 0 && $y == 0) { $pnnAct = 3; // Top left + } } $this->_active_pane = $pnnAct; // Used in _storeSelection @@ -2579,8 +2514,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $numHdr = pack("d", $numHdr); $numFtr = pack("d", $numFtr); - if ($this->_byte_order) // if it's Big Endian - { + if ($this->_byte_order) { // if it's Big Endian $numHdr = strrev($numHdr); $numFtr = strrev($numFtr); } @@ -2613,15 +2547,13 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr if ($this->_BIFF_version == 0x0600) { $encoding = 0x0; // TODO: Unicode support $length = 3 + $cch; // Bytes to follow - } - else { + } else { $length = 1 + $cch; // Bytes to follow } $header = pack("vv", $record, $length); if ($this->_BIFF_version == 0x0600) { $data = pack("vC", $cch, $encoding); - } - else { + } else { $data = pack("C", $cch); } @@ -2642,15 +2574,13 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr if ($this->_BIFF_version == 0x0600) { $encoding = 0x0; // TODO: Unicode support $length = 3 + $cch; // Bytes to follow - } - else { + } else { $length = 1 + $cch; } $header = pack("vv", $record, $length); if ($this->_BIFF_version == 0x0600) { $data = pack("vC", $cch, $encoding); - } - else { + } else { $data = pack("C", $cch); } @@ -2706,8 +2636,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("d", $margin); - if ($this->_byte_order) // if it's Big Endian - { + if ($this->_byte_order) { // if it's Big Endian $data = strrev($data); } @@ -2728,8 +2657,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("d", $margin); - if ($this->_byte_order) // if it's Big Endian - { + if ($this->_byte_order) { // if it's Big Endian $data = strrev($data); } @@ -2750,8 +2678,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("d", $margin); - if ($this->_byte_order) // if it's Big Endian - { + if ($this->_byte_order) { // if it's Big Endian $data = strrev($data); } @@ -2772,8 +2699,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $header = pack("vv", $record, $length); $data = pack("d", $margin); - if ($this->_byte_order) // if it's Big Endian - { + if ($this->_byte_order) { // if it's Big Endian $data = strrev($data); } @@ -2887,8 +2813,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr // Calculate the maximum column outline level. The equivalent calculation // for the row outline level is carried out in setRow(). - for ($i=0; $i < count($this->_colinfo); $i++) - { + for ($i = 0; $i < count($this->_colinfo); $i++) { // Skip cols without outline level info. if (count($col_level) >= 6) { $col_level = max($this->_colinfo[$i][5], $col_level); @@ -2930,8 +2855,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr // /*if ($this->_fit_page) { $grbit = 0x05c1; - } - else { + } else { $grbit = 0x04c1; }*/ // Set the option flags @@ -2980,8 +2904,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $cbrk = count($breaks); // Number of page breaks if ($this->_BIFF_version == 0x0600) { $length = 2 + 6*$cbrk; // Bytes to follow - } - else { + } else { $length = 2 + 2*$cbrk; // Bytes to follow } @@ -2992,8 +2915,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr foreach($breaks as $break) { if ($this->_BIFF_version == 0x0600) { $data .= pack("vvv", $break, 0x0000, 0x00ff); - } - else { + } else { $data .= pack("v", $break); } } @@ -3026,9 +2948,9 @@ 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 { + } else { $length = 2 + 2*$cbrk; // Bytes to follow } @@ -3039,8 +2961,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr foreach ($breaks as $break) { if ($this->_BIFF_version == 0x0600) { $data .= pack("vvv", $break, 0x0000, 0xffff); - } - else { + } else { $data .= pack("v", $break); } } @@ -3079,7 +3000,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr function _storePassword() { // Exit unless sheet protection and password have been specified - if (($this->_protect == 0) or (!isset($this->_password))) { + if (($this->_protect == 0) || (!isset($this->_password))) { return; } @@ -3110,8 +3031,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr function insertBitmap($row, $col, $bitmap, $x = 0, $y = 0, $scale_x = 1, $scale_y = 1) { $bitmap_array = $this->_processBitmap($bitmap); - if ($this->isError($bitmap_array)) - { + if ($this->isError($bitmap_array)) { $this->writeString($row, $col, $bitmap_array->getMessage()); return; } @@ -3193,12 +3113,10 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $row_end = $row_start; // Row containing bottom right corner of object // Zero the specified offset if greater than the cell dimensions - if ($x1 >= $this->_sizeCol($col_start)) - { + if ($x1 >= $this->_sizeCol($col_start)) { $x1 = 0; } - if ($y1 >= $this->_sizeRow($row_start)) - { + if ($y1 >= $this->_sizeRow($row_start)) { $y1 = 0; } @@ -3220,15 +3138,19 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr // Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell // with zero eight or width. // - if ($this->_sizeCol($col_start) == 0) + if ($this->_sizeCol($col_start) == 0) { return; - if ($this->_sizeCol($col_end) == 0) + } + if ($this->_sizeCol($col_end) == 0) { return; - if ($this->_sizeRow($row_start) == 0) + } + if ($this->_sizeRow($row_start) == 0) { return; - if ($this->_sizeRow($row_end) == 0) + } + if ($this->_sizeRow($row_end) == 0) { return; - + } + // Convert the pixel values to the percentage value expected by Excel $x1 = $x1 / $this->_sizeCol($col_start) * 1024; $y1 = $y1 / $this->_sizeRow($row_start) * 256; @@ -3257,12 +3179,10 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr if (isset($this->col_sizes[$col])) { if ($this->col_sizes[$col] == 0) { return(0); - } - else { + } else { return(floor(7 * $this->col_sizes[$col] + 5)); } - } - else { + } else { return(64); } } @@ -3283,12 +3203,10 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr if (isset($this->_row_sizes[$row])) { if ($this->_row_sizes[$row] == 0) { return(0); - } - else { + } else { return(floor(4/3 * $this->_row_sizes[$row])); } - } - else { + } else { return(17); } } @@ -3511,8 +3429,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr $this->_append($header.$data); $record = 0x01be; // Record identifier - foreach($this->_dv as $dv) - { + foreach($this->_dv as $dv) { $length = strlen($dv); // Bytes to follow $header = pack("vv", $record, $length); $this->_append($header.$dv);